private static Specification <Product> GetProductSpecification(ProductsSearchRequestModel model)
 {
     return(new ProductByNameSpecification(model.Query)
            //.And(new ProductByPriceSpecification(model.MinPrice, model.Price))
            .And(new ProductByCategorySpecification(model.Category))
            .And(new ProductByColorSpecification(model.Color))
            .And(new ProductBySizeSpecification(model.Size)));
 }
        private async Task <int> GetTotalPages(ProductsSearchRequestModel model)
        {
            var specification = GetProductSpecification(model);

            var total = await AllAsNoTracking
                        .Where(specification)
                        .CountAsync()
                        .ConfigureAwait(false);

            return((int)Math.Ceiling((double)total / ProductsPerPage));
        }
        public async Task <ProductsSearchResponseModel> ProductSearchAsync(ProductsSearchRequestModel model)
        {
            var specification = GetProductSpecification(model);

            var products = await Mapper
                           .ProjectTo <ProductsListingResponseModel>(AllAsNoTracking
                                                                     .Where(specification)
                                                                     .Skip((model.Page - 1) * ProductsPerPage)
                                                                     .Take(ProductsPerPage))
                           .ToListAsync()
                           .ConfigureAwait(false);

            var totalPages = await GetTotalPages(model).ConfigureAwait(false);

            return(new ProductsSearchResponseModel
            {
                Products = products,
                Page = model.Page,
                TotalPages = totalPages
            });
        }
예제 #4
0
 private Specification <Product> GetProductSpecification(
     ProductsSearchRequestModel model)
 => new ProductByNameSpecification(model.Query)
 .And(new ProductByPriceSpecification(model.MinPrice, model.MaxPrice))
 .And(new ProductByCategorySpecification(model.Category));
 public async Task <ProductsSearchResponseModel> Search([FromQuery] ProductsSearchRequestModel model)
 {
     return(await _products.ProductSearchAsync(model));
 }