From 54564be3fdbb67e7e945547169adc0b06dc20117 Mon Sep 17 00:00:00 2001 From: Ahad Chowdhury Date: Thu, 19 Sep 2024 23:52:50 +1000 Subject: [PATCH] Add DTO and conversion methods for CalendarEvent --- src/Data/CalendarEvent.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) mode change 100644 => 100755 src/Data/CalendarEvent.cs diff --git a/src/Data/CalendarEvent.cs b/src/Data/CalendarEvent.cs old mode 100644 new mode 100755 index 312ddc7..5a31191 --- a/src/Data/CalendarEvent.cs +++ b/src/Data/CalendarEvent.cs @@ -8,4 +8,37 @@ public class CalendarEvent public DateTime Date { get; set; } = DateTime.Now; public string Location { get; set; } = ""; public string Description { get; set; } = ""; + + internal void UpdateFromDto(CalendarEventDto dto) + { + Title = dto.Title; + Description = dto.Description; + Location = dto.Location; + Date = new DateTime(dto.Date, dto.Time); + } +} + +internal class CalendarEventDto +{ + internal Guid? Id { get; set; } + internal string Title { get; set; } = ""; + internal string Description { get; set; } = ""; + internal string Location { get; set; } = ""; + internal DateOnly Date { get; set; } = DateOnly.FromDateTime(DateTime.Now); + internal TimeOnly Time { get; set; } = TimeOnly.FromDateTime(DateTime.Now); + + internal CalendarEvent ToCalendarEvent(ApplicationUser user) + { + var calendarEvent = new CalendarEvent() + { + User = user + }; + + if (Id is not null && Id != Guid.Empty) calendarEvent.Id = (Guid)Id; + calendarEvent.Title = Title; + calendarEvent.Description = Description; + calendarEvent.Location = Location; + calendarEvent.Date = new DateTime(Date, Time); + return calendarEvent; + } }