How to group monthly sales by currency in Blazor Server application?

Cenk
1,026
Reputation points
Hello, I am working on a Blazor Server application and I want to get the monthly total sales. I need to group these sales by the currency (USD, EURO, TL) that they were sold. Here is the query I am currently using to group monthly sales, but I need to group by currency as well. How can I group by monthly sales based on currency?
public async Task<ICollection<ReportSalesDto>> GetMonthlySales(int year, string status)
{
await using var ctx = await _db.CreateDbContextAsync();
return await ctx.OrdersDetail
.Where(x => x.Order.OrderDateTime.Year == year && x.Status == status)
.GroupBy(x => new { Month = x.Order.OrderDateTime.Month, Status = x.Status, Currency = x.Currency })
.Select(u => new ReportSalesDto()
{
Month = u.Key.Month,
//Status = u.Key.Status,
//Currency = u.Key.Currency,
TotalSales = u.Sum(x => x.TotalSellPrice)
})
.OrderBy(u => u.Month)
.ToListAsync();
}
Sign in to answer