public async Task <IList <ProductByCategoryStatisticsDto> > Handle(GetProductsStatisticsByCategory request, CancellationToken cancellationToken) { var notifications = GetQuery(); var groupedTypes = await notifications .GroupBy(g => new { g.CategoryId }) .Select(s => new { s.Key.CategoryId, Count = s.Count() }).ToListAsync(cancellationToken); var products = groupedTypes.Select(x => new ProductByCategoryStatisticsDto { CategoryName = _context.Categories.FirstOrDefault(y => y.Id.Equals(x.CategoryId))?.Name ?? "deleted", Count = x.Count }).ToList(); return(products); }
public async Task <IActionResult> GetProductStatisticsByCategory([FromQuery] GetProductsStatisticsByCategory query) { var statistics = await _mediator.Send(query); return(Ok(statistics)); }