private void EditOrder_Click(object sender, RoutedEventArgs e) { using (ShopBase context = new ShopBase()) { var item = (Order)this.OrderGrid.SelectedItem; var customer = context.Orders.Where(p => p.OrderId == item.OrderId).FirstOrDefault(); if (Product.Text != null && Product.Text != "") { customer.ProductName = Product.Text; } if (Description.Text != null && Description.Text != "") { customer.Description = Description.Text; } if (Quantity.Text != null && Quantity.Text != "") { customer.Quantity = Convert.ToInt32(Quantity.Text); } if (PurchaseDate.SelectedDate != null) { customer.PurchaseDate = (DateTime)(PurchaseDate.SelectedDate); } context.SaveChanges(); OrderGrid.ItemsSource = context.Orders.ToList(); } }
private void DeleteCustomer_Click(object sender, RoutedEventArgs e) { using (ShopBase context = new ShopBase()) { using (var transaction = context.Database.BeginTransaction()) { Customer customer = context.Customers.Where(p => p.Email == Email.Text).FirstOrDefault(); context.Customers.Remove(customer); context.SaveChanges(); MessageBoxResult result = MessageBox.Show("Are you sure", "Sure?", MessageBoxButton.YesNo); // Process message box results switch (result) { case MessageBoxResult.Yes: transaction.Commit(); break; case MessageBoxResult.No: transaction.Rollback(); break; } } } }
public void Save() { db.SaveChanges(); }