From 1ff2cd7677430c0b6e1cee639b83c5665e3650a2 Mon Sep 17 00:00:00 2001 From: Fredi Machado Date: Sat, 25 May 2024 21:06:19 +1000 Subject: [PATCH] Fix quantities --- src/Cashier/NCafe.Cashier.Domain/Commands/PlaceOrder.cs | 5 ++++- src/UI/NCafe.Web/Pages/Cashier/Index.razor | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Cashier/NCafe.Cashier.Domain/Commands/PlaceOrder.cs b/src/Cashier/NCafe.Cashier.Domain/Commands/PlaceOrder.cs index d2f84ed..f25addf 100644 --- a/src/Cashier/NCafe.Cashier.Domain/Commands/PlaceOrder.cs +++ b/src/Cashier/NCafe.Cashier.Domain/Commands/PlaceOrder.cs @@ -28,6 +28,9 @@ public async Task Handle(PlaceOrder command, CancellationToken cancellationToken await _repository.Save(order); await _publisher.Publish( - new OrderPlacedMessage(order.Id, order.Items.Select(x => (Messages.OrderItem)x).ToArray(), order.Customer)); + new OrderPlacedMessage( + order.Id, + order.Items.GroupBy(i => i.ProductId).Select(i => new Messages.OrderItem(i.First().ProductId, i.First().Name, i.Sum(x => x.Quantity), i.First().Price)).ToArray(), + order.Customer)); } } diff --git a/src/UI/NCafe.Web/Pages/Cashier/Index.razor b/src/UI/NCafe.Web/Pages/Cashier/Index.razor index b5414c0..c901874 100644 --- a/src/UI/NCafe.Web/Pages/Cashier/Index.razor +++ b/src/UI/NCafe.Web/Pages/Cashier/Index.razor @@ -112,7 +112,7 @@ { var response = await Http.PostAsJsonAsync( $"{_baseAddress}/orders/add-item", - new { OrderId = _order.Id, item.ProductId, item.Quantity }); + new { OrderId = _order.Id, item.ProductId, Quantity = 1 }); response.EnsureSuccessStatusCode(); } catch (Exception ex)