Proper handling of DateTimeOffset, support for Multi-Day events and reacting to adding/removing events for the days.

This commit is contained in:
Burak Kaan Köse
2024-12-30 23:10:51 +01:00
parent 8cc7d46d7b
commit 8fd09bcad4
23 changed files with 340 additions and 234 deletions

View File

@@ -10,14 +10,15 @@ namespace Wino.Core.Domain.Models.Calendar
/// </summary>
public class CalendarDayModel
{
public TimeRange Period { get; }
public CalendarEventCollection EventsCollection { get; } = new CalendarEventCollection();
public ITimePeriod Period { get; }
public CalendarEventCollection EventsCollection { get; }
public CalendarDayModel(DateTime representingDate, CalendarRenderOptions calendarRenderOptions)
{
RepresentingDate = representingDate;
Period = new TimeRange(representingDate, representingDate.AddDays(1));
CalendarRenderOptions = calendarRenderOptions;
EventsCollection = new CalendarEventCollection(Period);
}
public DateTime RepresentingDate { get; }

View File

@@ -56,25 +56,16 @@ namespace Wino.Core.Domain.Models.Calendar
private void RegisterCalendarDayEvents(CalendarDayModel calendarDayModel)
{
calendarDayModel.EventsCollection.CalendarItemAdded += CalendarItemAdded;
calendarDayModel.EventsCollection.CalendarItemRangeRemoved += CalendarItemRangeRemoved;
calendarDayModel.EventsCollection.CalendarItemRemoved += CalendarItemRemoved;
calendarDayModel.EventsCollection.CalendarItemRangeAdded += CalendarItemRangeAdded;
}
// TODO: These handlers have incorrect senders. They should be the CalendarDayModel.
private void CalendarItemRangeAdded(object sender, List<ICalendarItem> e)
=> CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
private void CalendarItemRemoved(object sender, ICalendarItem e)
=> CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
private void CalendarItemAdded(object sender, ICalendarItem e)
=> CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
private void CalendarItemRangeRemoved(object sender, List<ICalendarItem> e)
=> CalendarDayEventCollectionUpdated?.Invoke(this, sender as CalendarDayModel);
/// <summary>
/// Unregisters all calendar item change listeners to draw the UI for calendar events.
/// </summary>
@@ -82,9 +73,7 @@ namespace Wino.Core.Domain.Models.Calendar
{
foreach (var day in CalendarDays)
{
day.EventsCollection.CalendarItemRangeRemoved -= CalendarItemRangeRemoved;
day.EventsCollection.CalendarItemRemoved -= CalendarItemRemoved;
day.EventsCollection.CalendarItemRangeAdded -= CalendarItemRangeAdded;
day.EventsCollection.CalendarItemAdded -= CalendarItemAdded;
}
}