private OrderItem GetOrderItem(OrderItemRecord orderItemRecord) { var id = new OrderItemIdentity(orderItemRecord.Id); var productId = new ProductIdentity(orderItemRecord.ProductId); var quantity = (int)orderItemRecord.Quantity; // TODO: VC: Make int var unitPrice = orderItemRecord.UnitPrice; var status = orderItemRecord.StatusId; return(new OrderItem(id, productId, unitPrice, quantity, status)); }
private async Task UpdateAsync(Order order, UpdateOrderRequest request) { var currentOrderDetails = order.OrderItems; var addedOrderRequestDetails = request.OrderItems.Where(e => e.Id == null).ToList(); var updatedOrderRequestDetails = request.OrderItems.Where(e => e.Id != null).ToList(); var deletedOrderDetails = order.OrderItems.Where(e => !request.OrderItems.Any(f => f.Id == e.Id.Value)).ToList(); foreach (var added in addedOrderRequestDetails) { var productId = new ProductIdentity(added.ProductId); var product = await _productReadRepository.FindAsync(productId); if (product == null) { throw new InvalidRequestException($"Product {productId} does not exist"); } var orderDetail = _orderFactory.CreateNewOrderItem(product, added.Quantity); order.AddOrderItem(orderDetail); } foreach (var updated in updatedOrderRequestDetails) { var orderDetailId = new OrderItemIdentity(updated.Id.Value); var orderDetail = order.OrderItems.First(e => e.Id == orderDetailId); var productId = new ProductIdentity(updated.ProductId); var product = await _productReadRepository.FindAsync(productId); if (product == null) { throw new InvalidRequestException($"Product {productId} does not exist"); } orderDetail.SetProduct(product); orderDetail.Quantity = updated.Quantity; } foreach (var deleted in deletedOrderDetails) { order.RemoveOrderItem(deleted.Id); } }
public void CanConstructValidOrderItem() { // Arrange var id = new OrderItemIdentity(Guid.NewGuid()); var productId = new ProductIdentity(Guid.NewGuid()); var unitPrice = 20.56m; var quantity = 4; var status = OrderItemStatus.Allocated; // Act var orderItem = new OrderItem(id, productId, unitPrice, quantity, status); // Assert orderItem.Id.Should().Be(id); orderItem.ProductId.Should().Be(productId); orderItem.UnitPrice.Should().Be(unitPrice); orderItem.Quantity.Should().Be(quantity); orderItem.Status.Should().Be(status); }
private void UpdateOrderItems(Order order, IEnumerable <IReadonlyProduct> products, IEnumerable <EditOrderItemCommand> updatedOrderItemRequests) { foreach (var orderItemRequest in updatedOrderItemRequests) { var orderItemId = new OrderItemIdentity(orderItemRequest.Id.Value); var orderItem = order.OrderItems.Single(e => e.Id == orderItemId); var productId = new ProductIdentity(orderItemRequest.ProductId); var unitPrice = orderItem.UnitPrice; if (orderItem.ProductId != productId) { var product = products.Single(e => e.Id == productId); unitPrice = product.ListPrice; } order.UpdateOrderItem(orderItemId, productId, unitPrice, orderItemRequest.Quantity); } }