Exemplo n.º 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();
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 3
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();
                }
            }
        }