Пример #1
0
 public void CreateProduct(Product product)
 {
     using (var context = new ContextGrabber())
     {
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
Пример #2
0
 public void CreateOrder(Order order)
 {
     using (var context = new ContextGrabber())
     {
         context.Orders.Add(order);
         context.SaveChanges();
     }
 }
Пример #3
0
 public void CreateCustomer(Customer customer)
 {
     using (var context = new ContextGrabber())
     {
         context.Customers.Add(customer);
         context.SaveChanges();
     }
 }
Пример #4
0
 public void EditProduct(Product product)
 {
     using (var context = new ContextGrabber())
     {
         context.Products.Add(product);
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #5
0
 public void EditOrder(Order order)
 {
     using (var context = new ContextGrabber())
     {
         context.Orders.Add(order);
         context.Entry(order).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #6
0
 public void EditCustomer(Customer customer)
 {
     using (var context = new ContextGrabber())
     {
         context.Customers.Add(customer);
         context.Entry(customer).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #7
0
 public void DeleteProduct(Product product)
 {
     using (var context = new ContextGrabber())
     {
         context.Products.Attach(product);
         context.Products.Remove(product);
         context.SaveChanges();
     }
 }
Пример #8
0
 public void DeleteCustomer(Customer customer)
 {
     using (var context = new ContextGrabber())
     {
         context.Customers.Attach(customer);
         context.Customers.Remove(customer);
         context.SaveChanges();
     }
 }
Пример #9
0
        public void DeleteOrder(Order order)
        {
            using (var context = new ContextGrabber())
            {
                var orderContext = context.Orders.Find(order.OrderID);

                foreach (var detail in order.Details.ToList())
                {
                    var detailContext = context.OrderDetails.Find(detail.OrderDetailID);
                    context.OrderDetails.Attach(detailContext);
                    context.OrderDetails.Remove(detailContext);
                    context.SaveChanges();
                }

                context.Orders.Attach(orderContext);
                context.Orders.Remove(orderContext);
                context.SaveChanges();
            }
        }