public static void Fill(bool update, params ReminderItemDTO[] items) { Scheduler.Remove(items.Select(x => x.GlobalId.ToString()).ToArray()); if (update) {//when we update than we should remove old instances from NotificationsReposidory foreach (var item in items) { NotificationsReposidory.Instance.Remove(item.GlobalId); } } ReminderBuilder builder = new ReminderBuilder(); var jobs = builder.Import(items); foreach (var reminderItemDto in jobs) { Scheduler.Add(reminderItemDto.Item1, reminderItemDto.Item2); } }
private void ReminderItemsReposidory_OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { ReminderBuilder.Fill(false, e.NewItems.Cast <ReminderItemDTO>().ToArray()); } else if (e.Action == NotifyCollectionChangedAction.Replace) { ReminderBuilder.Fill(true, e.NewItems.Cast <ReminderItemDTO>().ToArray()); } else if (e.Action == NotifyCollectionChangedAction.Remove) { var toRemove = e.OldItems.Cast <ReminderItemDTO>().ToArray(); Scheduler.Remove(toRemove.Select(x => x.GlobalId.ToString()).ToArray()); } else if (e.Action == NotifyCollectionChangedAction.Reset) { Scheduler.RemoveAll(); } }