예제 #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>
 /// Loads every event that occours today.
 /// </summary>
 private void LoadTodayEvents()
 {
     using (var context = new EventDatabaseEntities())
     {
         var item = context.Events.Where(x => System.Data.Entity.DbFunctions.TruncateTime(x.Date) == DateTime.Today).ToList();
         foreach (var query in item)
         {
             var completed = context.Completeds.Any(r => r.EventID == query.ID);
             TodayEventsList.Add(new EventDataModel
             {
                 CurrentEvent = query,
                 IsCompleted  = completed
             });
         }
     }
 }
예제 #4
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();
                }
            }
        }