public async Task <ActionResult <Product> > getProduct(int id) { var spec = new ProductWithBrandAndTypesSpecification(id); //criteria will be set var product = await _productRepo.GetEntityBySpec(spec); //data access code in the cotroller.P if (product == null) { return(NotFound(new ApiResponse(400))); } return(Ok(_mapper.Map <Product, ProductDto>(product))); }
public async Task <ActionResult <Pagination <ProductDto> > > getProducts([FromQuery] ProductsSpecParams ProductParams) { var spec = new ProductWithBrandAndTypesSpecification(ProductParams); var countSpec = new ProductsWithFiltersSpecification(ProductParams); //to send the count of items that fulfil the query. var products = await _productRepo.ListAsync(spec); var count = await _productRepo.CountAsync(countSpec); var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(products); return(Ok(new Pagination <ProductDto>(ProductParams.PageIndex, ProductParams.PageSize, count, data))); }