Пример #1
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())
            {
                var deleteItem = context.Events.FirstOrDefault(x => x.ID == SelectedEvent.CurrentEvent.ID);
                context.Events.Remove(deleteItem);

                context.SaveChanges();

                // Remove the deleted event from the UI.
                var delete = TodayEventsList.FirstOrDefault(r => r.CurrentEvent.ID == SelectedEvent.CurrentEvent.ID);
                TodayEventsList.Remove(delete);
                DetailsDataContext.TodayTasksList   = null;
                DetailsDataContext.SelectedEvent    = null;
                DetailsDataContext.ProgressbarValue = 0;

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

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

            // GOT A BIG ERROR HERE AFTER EDITING...
            using (var context = new EventDatabaseEntities())
            {
                // Create a new object to avoid DbUpdateConcurrencyException.
                var deleteItem = context.Events.FirstOrDefault(x => x.ID == SelectedEvent.CurrentEvent.ID);

                context.Events.Remove(deleteItem);
                context.SaveChanges();

                // Remove deleted event from the UI.
                DetailsDataContext.TodayTasksList = new ObservableCollection <Task>();
                TodayEventsList.Remove(SelectedEvent);
                DetailsDataContext.SelectedEvent    = null;
                DetailsDataContext.ProgressbarValue = 0;
            }
        }
Пример #3
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);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Deletes the selected event.
        /// </summary>
        private void DeleteEvent(Event 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);
                context.Events.Remove(sender);
                context.SaveChanges();

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

                if (sender.ID == AutoSearchItem.ID)
                {
                    CloseEvent();
                }
            }

            foreach (var item in HistoryList)
            {
                foreach (var del in item.EventList)
                {
                    if (del.CurrentEvent.ID == sender.ID)
                    {
                        item.EventList.Remove(del);

                        if (item.EventList.Count == 0)
                        {
                            HistoryList.Remove(item);
                        }

                        return;
                    }
                }
            }
        }
Пример #5
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();
            }
        }
Пример #6
0
        /// <summary>
        /// Creates a new event.
        /// </summary>
        private void AddEvent()
        {
            if (string.IsNullOrWhiteSpace(EventModel.EventTitle) || EventModel.EventDate == null)
            {
                dialogBox = new DialogBox("ERROR!", "Invalid inputs!");
                dialogBox.Show();
                return;
            }

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

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

            if (!string.IsNullOrWhiteSpace(EventModel.EventTime))
            {
                EventModel.EventDate += " " + EventModel.EventTime;
            }

            using (var context = new EventDatabaseEntities())
            {
                try
                {
                    var item = new Event()
                    {
                        Title       = EventModel.EventTitle,
                        Priority    = EventModel.Priority.ToString(),
                        Date        = DateTime.Parse(EventModel.EventDate),
                        Description = EventModel.EventDescription,
                    };

                    context.Events.Add(item);

                    context.SaveChanges();

                    if (item.Date.Date == DateTime.Today.Date)
                    {
                        TodayEventsList.Add(new EventDataModel {
                            CurrentEvent = item, IsCompleted = false
                        });
                    }

                    if (TasksList.Count != 0)
                    {
                        foreach (var task in TasksList)
                        {
                            if (!string.IsNullOrWhiteSpace(task.Description))
                            {
                                context.Tasks.Add(new Task {
                                    EventID = item.ID, Description = task.Description
                                });
                            }
                        }
                        context.SaveChanges();
                    }

                    dialogBox = new DialogBox("Event added successfully!");
                    dialogBox.Show();
                }
                catch
                {
                    dialogBox = new DialogBox("ERROR!", "There was an error!");
                    dialogBox.Show();
                }
            }
        }