Esempio n. 1
0
 public List <Order> GetAllOrders()
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("items").ToList <Order>());
     }
 }
Esempio n. 2
0
 public List <Order> QueryByCustormer(String custormer)
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("items")
                .Where(o => o.Customer.Equals(custormer)).ToList <Order>());
     }
 }
Esempio n. 3
0
 public Order GetOrder(String Id)
 {
     using (var db = new OrderDB())
     {
         return(db.Order.Include("Items").
                SingleOrDefault(o => o.Id == Id));
     }
 }
Esempio n. 4
0
 public List <Order> QueryByGoods(String product)
 {
     using (var db = new OrderDB())
     {
         var query = db.Order.Include("items")
                     .Where(o => o.Items.Where(
                                item => item.Product.Equals(product)).Count() > 0);
         return(query.ToList <Order>());
     }
 }
Esempio n. 5
0
 public void Delete(String orderId)
 {
     using (var db = new OrderDB())
     {
         var order = db.Order.Include("Items").SingleOrDefault(o => o.Id == orderId);
         db.OrderItem.RemoveRange(order.Items);
         db.Order.Remove(order);
         db.SaveChanges();
     }
 }
Esempio n. 6
0
 public void Add(Order order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Add(order);
         //db.Order.Attach(order);
         //db.Entry(order).State = EntityState.Added;
         db.SaveChanges();
     }
 }
Esempio n. 7
0
 public void Update(Order order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         order.Items.ForEach(
             item => db.Entry(item).State = EntityState.Modified);
         db.SaveChanges();
     }
 }