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