public Order GetOrder(uint id) { using (var management = new OrderManagement()) { return(orders.Where(o => o.OrderId == id).FirstOrDefault()); } }
public OrderService() { using (var management = new OrderManagement()) { orders = new List <Order>(); } }
public List <Order> QueryOrdersByCustomerName(string customerName) { using (var management = new OrderManagement()) { return(orders .Where(order => order.Customer == customerName) .OrderBy(o => o.TotalPrice) .ToList()); } }
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()); } }
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); } }
public void RemoveOrder(uint orderId) { Order order = GetOrder(orderId); if (order != null) { using (var management = new OrderManagement()) { orders.Remove(order); } } }
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); } }