Skip to content

Commit

Permalink
Add DTO and conversion methods for CalendarEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
maacpiash committed Sep 19, 2024
1 parent 6854b7b commit 54564be
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Data/CalendarEvent.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 54564be

Please sign in to comment.