Ejemplo n.º 1
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecsParams productParams)
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProductWithFiltersForCountSpecification(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)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Pagination <ProductToReturnDTO> > > GetProducts([FromQuery] ProductSpecsParams productParams)
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProductWithFilterForCountSpecification(productParams);

            var totalItems = await this.productRepo.CountAsync(countSpec);

            var products = await this.productRepo.ListAsync(spec);

            var data = this.mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDTO> >(products);

            return(Ok(new Pagination <ProductToReturnDTO>(productParams.PageIndex, productParams.PageSize, totalItems, data)));
            // return products.Select(p => new ProductToReturnDTO()
            // {
            //     Id = p.Id,
            //     Name = p.Name,
            //     Description = p.Description,
            //     Price = p.Price,
            //     PictureUrl = p.PictureUrl,
            //     ProductBrand = p.ProductBrand.Name,
            //     ProductType = p.ProductType.Name
            // }).ToList();
        }