Skip to content

Commit

Permalink
change it
Browse files Browse the repository at this point in the history
  • Loading branch information
Komilov Dilshod committed Oct 25, 2023
1 parent 65c5d6f commit 387f887
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,36 @@ public async Task<ProductAggregatesResponse> 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
Expand Down

0 comments on commit 387f887

Please sign in to comment.