Exemplo n.º 1
0
 public List <Order> FindOrder(int orderID)
 {
     using (var management = new OrderManagement())
     {
         var query = management.Orders.Include(o => o.OrderDetails.Select(i => i.Goods))
                     .Include("Customer")
                     .Where(order => orderID == int.MinValue || order.ID == orderID)
                     .OrderBy(order => order.ID);
         return(query.ToList());
     }
 }
Exemplo n.º 2
0
 public void DeleteOrder(int orderID)
 {
     using (var management = new OrderManagement())
     {
         var order = management.Orders.Include("OrderItems").FirstOrDefault(o => o.ID == orderID);
         if (order != null)
         {
             management.Orders.Remove(order);
             management.SaveChanges();
         }
     }
 }
Exemplo n.º 3
0
 public int AddOrder(Order order)
 {
     if (order == null)
     {
         throw new ArgumentException("Cannot add an empty order!");
     }
     using (var management = new OrderManagement())
     {
         management.Orders.Add(order);
         management.SaveChanges();
     }
     return(order.ID);
 }
Exemplo n.º 4
0
 public OrderService()//构造函数
 {
     using (var management = new OrderManagement())
     {
         //若无商品(数据库初始化),默认添加商品
         if (management.Goodss.Count(goods => true) == 0)
         {
             management.Goodss.Add(new Goods()
             {
                 Name = "milk", Price = 5.3
             });
             management.Goodss.Add(new Goods()
             {
                 Name = "cola", Price = 9.2
             });
             management.SaveChanges();
         }
     }
 }
Exemplo n.º 5
0
        public void AlterOrder(int orderID, String alterType, object alterData, int orderItemID = 0)
        {
            using (var management = new OrderManagement())
            {
                var order = management.Orders.Include("OrderItems").FirstOrDefault(o => o.ID == orderID);
                if (order != null)
                {
                    switch (alterType)
                    {
                    case "customer": order.CustomerID = IsInt(alterData); break;

                    case "quantity":
                        int amount = order.OrderDetails.FirstOrDefault(
                            i => i.ID == orderItemID).Amount;; break;

                    default: throw new ArgumentException("No such operation!");
                    }
                    management.SaveChanges();
                }
            }
        }