public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts([FromQuery] ProductSpecParams prodcutParams) { var spec = new ProductsWithTypesAndBrandsSpecification(prodcutParams); var countSpec = new ProductWithFiltersCountSpecification(prodcutParams); var totalItems = await _productRepo.CountAsync(countSpec); var products = await _productRepo.ListAsync(spec); var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products); return(Ok(new Pagination <ProductToReturnDto>(prodcutParams.PageIndex, prodcutParams.PageSize, totalItems, data))); }
public async Task <ActionResult> GetProducts([FromQuery] ProductSpecParams productParams) { var spec = new ProductWithTypesAndBrandSpecification(productParams); var countSpec = new ProductWithFiltersCountSpecification(productParams); var totalItems = await productsRepo.CountAsync(countSpec); var products = await productsRepo.GetListWithSpec(spec); var result = mapper.Map <IReadOnlyList <ProductDTO> >(products); return(Ok(new PaginationResult <ProductDTO>(productParams.PageIndex, productParams.PageSize, totalItems, result))); }
/* Asagida method boyleydi "GetProducts(string sort, int? brandId, int? typeId)" * Bu method un parametrelerini asagidaki gibi bir class objesine donusturduk. * Obje oldugu icin GetProducts methodu, bu objeyi request in body'sinde bulmaya calisacak. * int olsaydi, query params'tan cekebilecekti. QueryParams'tan cekmesi icin [FromQuery] diye ekledik. */ public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts([FromQuery] ProductSpecParams productParams) { var spec = new ProductsWithTypesAndBrandsSpecification(productParams); var countSpec = new ProductWithFiltersCountSpecification(productParams); var totalItems = await _productsRepo.CountAsync(countSpec); var products = await _productsRepo.ListAsync(spec); var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products); return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex, productParams.PageSize, totalItems, data))); // return products.Select(product => new ProductToReturnDto // { // Id = product.Id, // Name = product.Name, // Description = product.Description, // PictureUrl = product.PictureUrl, // Price = product.Price, // ProductBrand = product.ProductBrand.Name, // ProductType = product.ProductType.Name // }).ToList(); // return Ok(products); }