コード例 #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);
     }
 }