/// <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(); } } }