Пример #1
0
        /// <summary>
        /// Directly deletes an event from the today's list.
        /// </summary>
        /// <param name="sender"></param>
        private void DirectDelete(EventDataModel sender)
        {
            dialogBox = new DialogBox(DialogBoxType.WARNING, "DELETE!", "Would you like to delete this event?");
            dialogBox.ShowDialog();

            if (dialogBox.Answer == DialogAnswer.NO)
            {
                return;
            }

            using (var context = new EventDatabaseEntities())
            {
                context.Events.Attach(sender.CurrentEvent);
                context.Events.Remove(sender.CurrentEvent);
                context.SaveChanges();

                var delete = UpcomingEventsList.Where(p => p.EventModelList.Any(x => x.CurrentEvent.ID == sender.CurrentEvent.ID));
                delete.ElementAt(0).EventModelList.Remove(sender);

                DetailsDataContext.SelectedEvent    = null;
                DetailsDataContext.ProgressbarValue = 0;
                DetailsDataContext.TodayTasksList   = new ObservableCollection <Task>();

                // Remove the empy date object.
                var item = UpcomingEventsList.FirstOrDefault(x => x.EventModelList.Count == 0);
                if (item != null)
                {
                    UpcomingEventsList.Remove(item);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Deletes the currently selected event.
        /// </summary>
        private void DeleteEvent()
        {
            if (DetailsDataContext.SelectedEvent == null)
            {
                return;
            }

            dialogBox = new DialogBox(DialogBoxType.WARNING, "DELETE!", "Would you like to delete this event?");
            dialogBox.ShowDialog();

            if (dialogBox.Answer == DialogAnswer.NO)
            {
                return;
            }

            using (var context = new EventDatabaseEntities())
            {
                context.Events.Attach(DetailsDataContext.SelectedEvent.CurrentEvent);
                context.Events.Remove(DetailsDataContext.SelectedEvent.CurrentEvent);

                context.SaveChanges();
                var delete = UpcomingEventsList.SelectMany(x => x.EventModelList.Where(r => r.CurrentEvent.ID == SelectedEvent.CurrentEvent.ID)).Single();
                UpcomingEventsList.ToList().RemoveAll(x => x.EventModelList.Remove(delete));
                DetailsDataContext.TodayTasksList   = null;
                DetailsDataContext.SelectedEvent    = null;
                DetailsDataContext.ProgressbarValue = 0;

                // Remove the empy date object.
                var item = UpcomingEventsList.FirstOrDefault(x => x.EventModelList.Count == 0);
                if (item != null)
                {
                    UpcomingEventsList.Remove(item);
                }



                dialogBox = new DialogBox("Event deleted successfully!");
                dialogBox.Show();
            }
        }