public void UpdateReminder() { using (var context = new ReminderContext()) { NotificationList.ItemsSource = context.Reminders .OrderByDescending(x => x.CreateTime).ToList(); } }
// Удалить private void DeleteButtonClick(object sender, RoutedEventArgs e) { if (NotificationList.SelectedIndex == -1) { return; } Reminder notificationToDelete = NotificationList.Items[NotificationList.SelectedIndex] as Reminder; using (var context = new ReminderContext()) { context.Entry(notificationToDelete).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } UpdateReminder(); }
public void UpdateTimers(Reminder reminder = null) { if (reminder == null) { using (var context = new ReminderContext()) { foreach (var ntf in context.Reminders.Where(n => n.NotifyTime > DateTime.Now)) { Timers.Add(new Timer(new TimerCallback(Notify), ntf.NotificationText, GetMilliseconds(ntf.NotifyTime), Timeout.Infinite)); } } } else { Timers.Add(new Timer(new TimerCallback(Notify), reminder.NotificationText, GetMilliseconds(reminder.NotifyTime), Timeout.Infinite)); } }