public async Task <ActionResult <ProductDto> > GetProduct(int id) { var spec = new ProductWithTypeAndBrandSpec(id); var product = await _productRepo.GetEntityWithSpec(spec); if (product == null) { return(NotFound(new ApiResponse(404))); } return(_mapper.Map <Product, ProductDto>(product)); }
public async Task <ActionResult <Pagination <ProductDto> > > GetProducts( [FromQuery] ProductSpecParams specParams) { var spec = new ProductWithTypeAndBrandSpec(specParams); var products = await _productRepo.ListAsync(spec); var countSpec = new ProductWithFiltersForCountSpec(specParams); var count = await _productRepo.CountAsync(countSpec); var productDtos = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(products); return(Ok(new Pagination <ProductDto>(specParams.PageIndex, specParams.PageSize, count, productDtos))); }
public async Task <IActionResult> GetProducts(int id) { //var query1 = new ProductWithTypeAndBrandSpec(9).AndAlso(new BrandWithTypeSpec(2)); //var products = await _genericRepo.GetEntityExpression(query1); var query = new ProductWithTypeAndBrandSpec(id); var product = await _productRepo.GetEntityWithSpec(query); var result = _mapper.Map <ProductResponse>(product); if (result == null) { return(NotFound()); } return(Ok(result)); }