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()); }
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 }); }
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()); } }
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 }); }