예제 #1
0
 public Order GetOrder(uint id)
 {
     using (var management = new OrderManagement())
     {
         return(orders.Where(o => o.OrderId == id).FirstOrDefault());
     }
 }
예제 #2
0
 public OrderService()
 {
     using (var management = new OrderManagement())
     {
         orders = new List <Order>();
     }
 }
예제 #3
0
 public List <Order> QueryOrdersByCustomerName(string customerName)
 {
     using (var management = new OrderManagement())
     {
         return(orders
                .Where(order => order.Customer == customerName)
                .OrderBy(o => o.TotalPrice)
                .ToList());
     }
 }
예제 #4
0
 public List <Order> QueryOrdersByGoodsName(string goodsName)
 {
     using (var management = new OrderManagement())
     {
         var query = orders
                     .Where(order => order.Items.Exists(item => item.GoodsName == goodsName))
                     .OrderBy(o => o.TotalPrice);
         return(query.ToList());
     }
 }
예제 #5
0
 public void AddOrder(Order order)
 {
     if (orders.Contains(order))
     {
         throw new ApplicationException($"Add Order Error: Order with id {order.OrderId} already exists!");
     }
     using (var management = new OrderManagement())
     {
         orders.Add(order);
     }
 }
예제 #6
0
        public void RemoveOrder(uint orderId)
        {
            Order order = GetOrder(orderId);

            if (order != null)
            {
                using (var management = new OrderManagement())
                {
                    orders.Remove(order);
                }
            }
        }
예제 #7
0
 public void UpdateOrder(Order newOrder)
 {
     using (var management = new OrderManagement())
     {
         Order oldOrder = GetOrder(newOrder.OrderId);
         if (oldOrder == null)
         {
             throw new ApplicationException($"Update Error:the order with id {newOrder.OrderId} does not exist!");
         }
         orders.Remove(oldOrder);
         orders.Add(newOrder);
     }
 }