public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        {
            var spec = new ProductWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProductWithFiltersForCountSpecification(productParams);

            var totalIems = await _productRepo.CountAsync(countSpec);

            var products = await _productRepo.ListAsync(spec);

            var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);

            return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex,
                                                          productParams.PageSize, totalIems, data)));
        }
        public async Task <IActionResult> GetProducts([FromQuery] ProductSpecParams productParams)
        {
            // work also
            // _mapper.Map<IReadOnlyList<Product>, IReadOnlyList<ProductResponse>>(products)


            var products = await _productRepo.ListAsync(new ProductWithTypeAndBrandSpec(productParams));

            var total = await _productRepo.CountAsync(new ProductWithTypeAndBrandSpecCount(productParams));

            return(Ok(new GenericResponse <ProductResponse> {
                Data = _mapper.Map <IReadOnlyList <ProductResponse> >(products),
                Count = total,
                PageIndex = productParams.PageIndex,
                PageSize = productParams.PageSize
            }));
        }
Esempio n. 3
0
        public async Task <ActionResult <QueryResult <ProductDto> > > GetProducts([FromQuery] ProductSpecParams spec)
        {
            ProductSpecification  productSpecification = new ProductSpecification(spec);
            IEnumerable <Product> products             = await _unitOfWork.Repository <Product>().GetEntitiesWithSpecAsync(productSpecification);

            IEnumerable <ProductDto> productsDto = _mapper.Map <IEnumerable <ProductDto> >(products);

            ProductPagingSpecification pagingSpec = new ProductPagingSpecification(spec);
            int totalCount = await _unitOfWork.Repository <Product>().GetTotalCountAsync(pagingSpec);

            QueryResult <ProductDto> queryResult =
                new QueryResult <ProductDto> {
                Count = totalCount, Data = productsDto, PageIndex = spec.PageIndex, PageSize = spec.PageSize
            };

            return(Ok(queryResult));
        }
        public async Task <IActionResult> GetProducts([FromQuery] ProductSpecParams productSpecParams)
        {
            var spec      = new ProductsWithTypeAndBrandSpecification(productSpecParams);
            var countSpec = new ProductWithFiltersForCountSpecification(productSpecParams);
            var count     = await _productRepo.CountAsync(countSpec);

            var products = await _productRepo.ListAsync(spec);

            var productToReturnList = _mapper.Map <IReadOnlyList <ProductToReturnDto> >(products);

            return(Ok(new Pagination <ProductToReturnDto> {
                PageIndex = productSpecParams.PageIndex,
                PageSize = productSpecParams.pageSize,
                Count = count,
                Data = productToReturnList
            }));
        }
Esempio n. 5
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProductsAsync(
            [FromQuery] ProductSpecParams productParams)
        {
            //var spec = new ProductsWithVariantsAndVariantOptionsAndSKUs(productParams);
            //var countSpec = new ProductWithFiltersForCountSpecification(productParams);

            // var totalItems = await this.productsRepo.CountAsync(countSpec);

            var products = await this.simpleRepo.GetProductsAsync(productParams);

            var totalItems = await this.simpleRepo.GetProductCountAsync();

            return(Ok(new Pagination <ProductToReturnDto>(
                          productParams.PageIndex,
                          productParams.PageSize,
                          totalItems, products)));
        }
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        // brand id and type id are optional ? int input parameters
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams); // pass them in here

            var countSpec = new ProductWithFilteringForCountSpecification(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)));
        }
Esempio n. 7
0
        public async Task <PagedList <ProductDto> > GetProductsWithSpec(
            [FromQuery] ProductSpecParams productSpecParams)
        {
            //specifation for product(s) with department, category, and product type
            var spec = new ProductsWithDeptCatProdTypeSpec(productSpecParams);
            //specification for total count of filtered products
            var countSpec = new ProductWithFiltersCountSpec(productSpecParams);

            var totalItems = await _productService.Count(countSpec);

            var products = await _productService.GetProductsWithSpec(spec);

            var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(products);

            _logger.LogInformation("Products retreived: {{{ string.Join(", ", data.Name)}}}");

            return(new PagedList <ProductDto>(productSpecParams.PageIndex, productSpecParams.PageSize, totalItems, data));
        }
        /// <summary>
        /// Assynchronously sets the Specifications and brings a list of products according to it.
        /// </summary>
        /// <param name="productParam">A class with properties,as sort and filters , to configure our query</param>
        /// <returns>List of products</returns>
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            //FromQuery is necessary to inform the API that the parameters will be passed by Query String.
            //It would work properly without it if instead pass a class in GetProducts arguments, we pass the argmuments individually
            [FromQuery] ProductSpecParams productParams
            )
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProducWithFiltersForCountSpecification(productParams);

            var totalItems = await _productsRepo.CountAsync(countSpec);

            var products = await _productsRepo.ListAsync(spec);

            var data = this._mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);

            return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex, productParams.PageSize, totalItems, data)));
        }
Esempio n. 9
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams productParams
            )
        {
            // var products = await _context.Products.ToListAsync(); // After Interfaces made
            // var products = await _productsRepo.ListAllAsync(); // Before spec
            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)));
        }
        public async Task <ProductData> GetProducts(ProductSpecParams productParams)
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProductWithFiltersForCountSpecification(productParams);

            var totalItems = await _unitOfWork.Repository <Product>().CountAsync(countSpec);

            var products = await _unitOfWork.Repository <Product>().ListAsync(spec);

            var productsData = new ProductData
            {
                Products   = products,
                TotalItems = totalItems
            };

            return(productsData);
        }
Esempio n. 11
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams specParams)
        {
            // pour ajouter les spécifications marque/type
            var spec      = new ProductWithBrandAndTypeSpecification(specParams);
            var Countspec = new ProductFilterForCount(specParams);
            // pour récupérer la quantité réelle d'items
            var totalItem = await _productRepo.CountAsync(Countspec); //Countspec

            // on récupère les specifications

            var products = await _productRepo.ListAsyncWithSpec(spec);

            //  var productsDto = _mapper.Map<IEnumerable<>>
            var datas = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);

            return(Ok(new Pagination <ProductToReturnDto>(specParams.PageIndex,
                                                          specParams.ItemsPerPage, totalItem, datas)));
        }
Esempio n. 12
0
        public async Task <ActionResult <Pagination <IReadOnlyList <ProductDto> > > > GetProductsAsync(
            [FromQuery] ProductSpecParams specParams)
        {
            System.Console.Write(specParams.BrandId);
            System.Console.Write(specParams.TypeId);
            System.Console.Write(specParams.Sort);

            var spec = new ProductsWithTypesAndBrandsSpecification(specParams);

            var countSpec = new ProductsWithFiltersForCountSpecification(specParams);

            var totlaItems = await _productRepository.CountAsync(countSpec);

            var product = await _productRepository.ListAsync(spec);

            var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(product);

            return(Ok(new Pagination <ProductDto>(specParams.PageIndex, specParams.PageSize, totlaItems, data)));
        }
Esempio n. 13
0
        GetProducts([FromQuery] ProductSpecParams productParams)
        {
            // Just watch on NAME of class to read ->
            // get listAsync with spec(Products with Types and Brands)
            // this is Specification pattern
            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)));
        }
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        {
            //using generic repository to implement
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);
            //create a instance to count using specification class
            var countSpec = new ProductWithFiltersForCountSpecification(productParams);

            var totalItems = await _productsRepo.CountAsync(countSpec);

            //make the action doing Asynchronous
            var products = await _productsRepo.ListAsync(spec);

            var data = _mapper
                       .Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);

            //instead return the products, return the list of dto object to show what we want to show to clients
            return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex,
                                                          productParams.PageSize, totalItems, data)));
        }
        public async Task <ActionResult <Pagination <Product> > > GetProductList(
            [FromQuery] ProductSpecParams productSpecParams)
        {
            var spec      = new ProductWithDetailSpecification(productSpecParams);
            var countSpec = new ProductWithFilterForCountSpecification(productSpecParams);

            var productList = await _productRepository.ListAsync(spec);

            var totalItems = await _productRepository.CountAsync(countSpec);

            var products = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(productList);

            return(Ok(new Pagination <ProductDto>()
            {
                Count = totalItems,
                PageIndex = productSpecParams.PageIndex,
                PageSize = productSpecParams.PageSize,
                Data = products
            }));
        }
Esempio n. 16
0
        public async Task <ActionResult> GetProducts([FromQuery] ProductSpecParams productParams)
        {
            var spec = new ProductAndCategorySpec(productParams);

            var countSpec = new ProductWithFiltersForCountSpecification(productParams);

            var totalItems = await _productService.CountAsync(countSpec);

            var products = await _productService.GetProductsAsync(productParams);

            if (products.Count > 0)
            {
                var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(products);
                return(Ok(new Pagination <ProductDto>(productParams.PageIndex, productParams.PageSize, totalItems, data)));
            }
            else
            {
                return(NotFound(new ApiResponse(404, "Product is not found!!")));
            }
        }
Esempio n. 17
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        {
            //return "this will be a list of products, plural";

            //var products = await _context.Products.ToListAsync();
            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(products);
            // code below converts an "Entity" to a "DTO"
            return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex,
                                                          productParams.PageSize, totalItems, data)));
        }
Esempio n. 18
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        {
            var countSpec  = new ProductWithFiltersforCountSpecification(productParams);
            var totalItems = await _productRepo.CountAsync(countSpec);

            var spec     = new ProductsWithTypesAndBrandsSpecification(productParams);
            var products = await _productRepo.ListAsync(spec);

            var dto = products.Select(product =>
                                      _mapper.Map <Product, ProductToReturnDto>(product)
                                      ).ToList();
            var dtos      = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);
            var paginated = new Pagination <ProductToReturnDto>(
                productParams.PageIndex,
                productParams.PageSize,
                totalItems,
                dtos);

            return(Ok(paginated));
        }
Esempio n. 19
0
        public async Task <IActionResult> GetProducts([FromQuery] ProductSpecParams productParams)
        {
            var spec      = new ProductsWithTypesAndBrandsSpecification(productParams);
            var countSpec = new ProductsWithFiltersForCountSpecification(productParams);

            var products = await _productRepo.ListAsync(spec);

            var totalItems = await _productRepo.CountAsync(countSpec);

            var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);

            var model = new Pagination <ProductToReturnDto>
            {
                Count     = totalItems,
                Data      = data,
                PageIndex = productParams.PageIndex,
                PageSize  = productParams.PageSize
            };

            return(Ok(model));
        }
Esempio n. 20
0
        public async Task <ActionResult <Pagination <IReadOnlyList <ProductToReturnDto> > > > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        {
            var paramsLog = Newtonsoft.Json.JsonConvert.SerializeObject(productParams);

            System.Diagnostics.Debug.WriteLine(paramsLog);

            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProductWithFiltersForCountSpecification(productParams);

            var totalItems = await _productRepo.CountAsync(countSpec);

            var products = await _productRepo.ListAsync(spec);

            var data = _mapper.Map <IReadOnlyList <Product>,
                                    IReadOnlyList <ProductToReturnDto> >(products);

            var returnDto = new Pagination <ProductToReturnDto>(productParams.PageIndex, productParams.PageSize, totalItems, data);

            return(Ok(returnDto));
        }
Esempio n. 21
0
        //public async Task<ActionResult<List<Product>>> GetProducts()
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        {
            //var products = await _context.Products.ToListAsync();
            //var products = await _repo.GetProductsAsync();
            //var products = await _productsRepo.ListAllAsync();

            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 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);

            //return Ok(_mapper.Map<IReadOnlyList<Product>,
            //  IReadOnlyList<ProductToReturnDto>>(products));

            return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex,
                                                          productParams.PageSize, totalItems, data)));
        }
Esempio n. 22
0
        public async Task <ActionResult <ProductToReturnDto> > GetProducts(
            [FromQuery] ProductSpecParams productParams)
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var results = await _dataAccess.GetProductByAsync(
                productParams.PageIndex,
                productParams.PageSize,
                productParams.Sort,
                productParams.BrandId,
                productParams.TypeId,
                productParams.Search);

            var totalItems = results.TotalCount;

            var products = results.Items;

            var data = _mapper.Map <IEnumerable <Product>, IEnumerable <ProductToReturnDto> >(products);



            return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex,
                                                          productParams.PageSize, totalItems, data)));
        }
Esempio n. 23
0
        public async Task <ActionResult <IReadOnlyList <ProductToReturnDto> > > GetProducts([FromQuery] ProductSpecParams productParams)
        {
            //var products = await _repo.GetProductsAsync();
            var spec     = new ProductsWithTypesAndBrandsSpecification(productParams);
            var products = await _productsRepo.ListAsync(spec);

            //return Ok(products);
            //  if (products == null) return NotFound(new ApiResponse(404));

            var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);

            return(Ok(data));
        }
        public async Task <int> GetProductsCountAsync(ProductSpecParams productParams)
        {
            var countSpec = new ProductWithFiltersForCountSpecification(productParams);

            return(await _productStorage.CountAsync(countSpec));
        }
Esempio n. 25
0
        public async Task <ActionResult <Pagination <ProductToReturnDTO> > > GetProducts([FromQuery] ProductSpecParams productParams)
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProductWithFiltersForCountSpecification(productParams);// the give counts of items

            var totalItems = await _productsRepo.CountAsync(countSpec);

            var product = await _productsRepo.ListAsync(spec);

            var data = _mapper.Map <List <Product>, List <ProductToReturnDTO> >(product);

            return(Ok(new Pagination <ProductToReturnDTO>(productParams.PageIndex,
                                                          productParams.Pagesize, totalItems, data)));
        }
Esempio n. 26
0
 public async Task<ActionResult> GetProducts([FromQuery] ProductSpecParams productParams)
 {
     Pagination<ProductToReturnDto> data = await _productManager.GetProducts(productParams);
     return Ok(data);
 }
Esempio n. 27
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts([FromQuery] ProductSpecParams productParams)
        {
            var spec = new ProductsWithTypesAndBrandsSpecification(productParams);

            var countSpec = new ProductWithFiltersForCountSpecification(productParams); // used to get a count of all items before sorting and filtering.

            var totalItems = await _productsRepository.CountAsync(countSpec);

            var products = await _productsRepository.ListAsync(spec);

            var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductToReturnDto> >(products);

            return(Ok(new Pagination <ProductToReturnDto>(productParams.PageIndex, productParams.PageSize, totalItems, data)));
        }
Esempio n. 28
0
        public async Task <ActionResult <Pagination <ProductDto> > > Get([FromQuery] ProductSpecParams spec)
        {
            var pg = await this._repo.GetProductsDtoAsync(spec);

            return(Ok(pg));
        }
Esempio n. 29
0
        [HttpGet]                                                                                                                     // Pagination v 65
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts([FromQuery] ProductSpecParams productParams) // if class check for body but we sent as query for get so used "fromQuery"// v 64
        {
            var spec       = new ProductsWithTypesAndBrandsSpecification(productParams);                                              // sort v 59
            var countSpec  = new ProductWithFiltersForCountSpecification(productParams);                                              //v 65
            var totalItems = await _productsRepo.CountAsync(countSpec);                                                               // 65

            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();
        }
Esempio n. 30
0
        public async Task <ActionResult <Pagination <ProductToReturnDto> > > GetProducts([FromQuery] ProductSpecParams productSpecParams)
        {
            var spec       = new ProductWithTypeAndBrandSpecification(productSpecParams);
            var countSpec  = new ProductWithFiltersForCountSpecification(productSpecParams);
            var totalItems = await _iProductRepository.CountAsync(countSpec);

            var products = await _iProductRepository.ListAsync(spec);

            var productDtos = products.Select(_mapper.Map <Product, ProductToReturnDto>).ToList();

            var result = new Pagination <ProductToReturnDto>(
                productSpecParams.PageIndex,
                productSpecParams.PageSize,
                totalItems,
                productDtos
                );

            return(Ok(result
                      ));
        }