コード例 #1
0
        public void AddToOrder([FromBody] OrderItemManagementData data)
        {
            Dal.Order order = this.ordersDataProvider.GetById(data.OrderId);
            OrderItem item  = order.Items.Where(x => x.ProductId == data.ProductId).FirstOrDefault();

            if (item == null)
            {
                Product product = MessageQueue.SendMessage <Product>("GetProduct", new
                {
                    ProductId = data.ProductId
                }).Result;

                order.Items.Add(new OrderItem
                {
                    ProductId    = data.ProductId,
                    Price        = product.Price,
                    ProductTitle = product.Title,
                    Quantity     = data.Quantity
                });
            }
            else
            {
                item.Quantity = data.Quantity;
            }

            this.ordersDataProvider.Update(order.ToDalOrderUpdatingData());
        }
コード例 #2
0
 public static Dal.OrderUpdatingData ToDalOrderUpdatingData(this Dal.Order order)
 {
     return(new Dal.OrderUpdatingData
     {
         OrderId = order.Id,
         Items = order.Items.Select(x => x.ToDalOrderItemManagementData(order.Id)).ToList(),
         Status = order.Status
     });
 }
コード例 #3
0
        public void DeleteFromOrder([FromBody] OrderItemManagementData data)
        {
            Dal.Order order = this.ordersDataProvider.GetById(data.OrderId);
            OrderItem item  = order.Items.Where(x => x.ProductId == data.ProductId).FirstOrDefault();

            if (item != null)
            {
                order.Items.Remove(item);
                this.ordersDataProvider.Update(order.ToDalOrderUpdatingData());
            }
        }
コード例 #4
0
 public static Order ToOrder(this Dal.Order order)
 {
     return(new Order
     {
         Id = order.Id,
         CreationDate = order.CreationDate,
         Customer = order.Customer,
         Items = order.Items,
         Status = order.Status,
         Total = order.Items.Any() ? order.Items.Sum(x => x.Price * x.Quantity) : 0
     });
 }