// редактирование private void Edit_Click(object sender, RoutedEventArgs e) { if (expGrid.SelectedItem == null) { return; } Expense exp = expGrid.SelectedItem as Expense; ExpenseWindow expWindow = new ExpenseWindow(new Expense { Id = exp.Id, Expense_name = exp.Expense_name, Cost = exp.Cost, ExpDate = exp.ExpDate, Category_id = exp.Category_id }); if (expWindow.ShowDialog() == true) { exp = db.Expenses.Find(expWindow._expense.Id); if (exp != null) { exp.Expense_name = expWindow._expense.Expense_name; exp.Cost = expWindow._expense.Cost; exp.ExpDate = expWindow._expense.ExpDate; exp.Category_id = expWindow._expense.Category_id; db.Entry(exp).State = EntityState.Modified; db.SaveChanges(); _itemSourceList.View.Refresh(); } } }
// добавление private void Add_Click(object sender, RoutedEventArgs e) { Expense new_Exp = new Expense(); new_Exp.ExpDate = DateTime.Today; ExpenseWindow expWindow = new ExpenseWindow(new_Exp); db.Configuration.ValidateOnSaveEnabled = false; if (expWindow.ShowDialog() == true) { Expense exp = expWindow._expense; exp.Category = db.Categories.Find(expWindow._expense.Category_id); db.Expenses.Add(exp); db.SaveChanges(); } }