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; } } } }
private void Find_Click(object sender, RoutedEventArgs e) { using (ShopBase context = new ShopBase()) { if (Age.Text != null && Age.Text != "" && Name.Text != null && Name.Text != "") { int age = Convert.ToInt32(Age.Text); CustomerGrid.ItemsSource = context.Customers .Select(x => x) .Where(x => x.Name == Name.Text) .Where(x => x.Age == age).ToList(); } else if (Name.Text != null && Name.Text != "") { CustomerGrid.ItemsSource = context.Customers .Select(x => x) .Where(x => x.Name == Name.Text).ToList(); } } }
public CustomerRepository(ShopBase context) { this.db = context; }
public OrderReprository(ShopBase context) { this.db = context; }