示例#1
0
 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();
     }
 }
示例#2
0
        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;
                    }
                }
            }
        }
示例#3
0
 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();
         }
     }
 }
示例#4
0
 public CustomerRepository(ShopBase context)
 {
     this.db = context;
 }
示例#5
0
 public OrderReprository(ShopBase context)
 {
     this.db = context;
 }