From 387f8878c894cb61ae20b79f66f9a0a0f84b7c48 Mon Sep 17 00:00:00 2001 From: Komilov Dilshod Date: Wed, 25 Oct 2023 10:50:00 +0500 Subject: [PATCH] change it --- .../Reports/GetProductAggregatesQueryHandler.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/warehouse/Application/Reports/GetProductAggregatesQueryHandler.cs b/src/warehouse/Application/Reports/GetProductAggregatesQueryHandler.cs index 66b6a53..78f8ca8 100644 --- a/src/warehouse/Application/Reports/GetProductAggregatesQueryHandler.cs +++ b/src/warehouse/Application/Reports/GetProductAggregatesQueryHandler.cs @@ -30,32 +30,36 @@ public async Task Handle(GetProductAggregatesQuery re var mostPurchases = await _context.ProductPurchases .GroupBy(s => s.ProductName) - .OrderByDescending(a => a.Sum(s => s.Quantity)) + .OrderByDescending(a => a.Sum(s => s.TotalPrice)) .Select(s => new { Purchase = s.First(), - Quantity = s.Sum(s => s.Quantity) + Quantity = s.Sum(s => s.Quantity), + TotalPrice = s.Sum(s => s.TotalPrice) }) .Take(10) .ToListAsync(cancellationToken); mostPurchases.ForEach(s => { s.Purchase.Quantity = s.Quantity; + s.Purchase.TotalPrice = s.TotalPrice; }); var mostSellers = await _context.SaleProducts .GroupBy(s => s.ProductName) - .OrderByDescending(a => a.Sum(s => s.Quantity)) + .OrderByDescending(a => a.Sum(s => s.TotalPrice)) .Select(s => new { ProductSale = s.First(), - Quantity = s.Sum(s => s.Quantity) + Quantity = s.Sum(s => s.Quantity), + TotalPrice = s.Sum(s => s.TotalPrice) }) .Take(10) .ToListAsync(cancellationToken); mostSellers.ForEach(s => { s.ProductSale.Quantity = s.Quantity; + s.ProductSale.TotalPrice = s.TotalPrice; }); return new ProductAggregatesResponse