public async Task <IEnumerable <ProductDto> > Handle(GetProductsByCategoryIdQuery request, CancellationToken cancellationToken) { var products = await _unitOfWork.Products.GetAllAsync(); return(products.Select(p => new ProductDto { Id = p.Id, Name = p.Name, Price = p.Price, Description = p.Description, Rating = p.Rating, ThumbnailImageUrl = _storageService.GetFileUrl(p.ImageFileName) }).ToList()); }
public async Task <IEnumerable <ProductDto> > Handle(GetProductsByCategoryIdQuery request, CancellationToken cancellationToken) { var products = await _context.Products .Where(p => p.ProductCategories.Any(pc => pc.CategoryId == request.CategoryId)).ToListAsync(); return(products.Select(p => new ProductDto { Id = p.Id, Name = p.Name, Price = p.Price, Description = p.Description, Rating = p.Rating, ThumbnailImageUrl = _storageService.GetFileUrl(p.ImageFileName) }).ToList()); }