private void AddItem_Click(object sender, RoutedEventArgs e) { if (btnAdd.Content.ToString() != "Edit Item") { ToDoItem todoItem = new ToDoItem(); todoItem.Name = txtName.Text.Length > 0 ? txtName.Text : "Nameless Item"; todoItem.Deadline = dpDeadline.SelectedDate != null ? dpDeadline.SelectedDate.Value : DateTime.Now.AddDays(1); todoItem.Description = txtDescription.Text; todoItem.Status = cmbStatus.Text; todoItem.ToDoListId = _currentListId; context.ToDoItems.Add(todoItem); context.SaveChanges(); var detailPage = new ListDetailPage(_currentListId); var mainFrame = (Frame)Application.Current.MainWindow.FindName("MainFrame"); mainFrame.Content = detailPage; this.Close(); } else { var todoItem = context.ToDoItems.FirstOrDefault(x => x.ToDoItemID == _currentItemId); if (todoItem != null) { todoItem.Name = txtName.Text.Length > 0 ? txtName.Text : "Nameless Item"; todoItem.Deadline = dpDeadline.SelectedDate != null ? dpDeadline.SelectedDate.Value : DateTime.Now.AddDays(1); todoItem.Description = txtDescription.Text; todoItem.Status = cmbStatus.Text; todoItem.ToDoListId = _currentListId; context.SaveChanges(); var detailPage = new ListDetailPage(_currentListId); var mainFrame = (Frame)Application.Current.MainWindow.FindName("MainFrame"); mainFrame.Content = detailPage; this.Close(); } } }
private void ListItem_Click(object sender, RoutedEventArgs e) { var id = ((Button)sender).Tag; var detailPage = new ListDetailPage(Int32.Parse(id.ToString())); var mainFrame = (Frame)Application.Current.MainWindow.FindName("MainFrame"); mainFrame.Content = detailPage; }