Ejemplo n.º 1
0
        private static GetProductsByCategoryRequest GenerateProductSearchRequestFrom(JsonProductSearchRequest jsonProductSearchRequest)
        {
            GetProductsByCategoryRequest productSearchRequest = new GetProductsByCategoryRequest();

            productSearchRequest.NumberOfResultsPerPage = ApplicationSettingsFactory.GetApplicationSettings().NumberOfResultsPerPage;
            productSearchRequest.Index      = jsonProductSearchRequest.Index;
            productSearchRequest.CategoryId = jsonProductSearchRequest.CategoryId;
            productSearchRequest.SortBy     = jsonProductSearchRequest.SortBy;

            List <RefinementGroup> refinementGroups = new List <RefinementGroup>();
            RefinementGroup        refinementGroup;

            foreach (JsonRefinementGroup jsonRefinementGroup in jsonProductSearchRequest.RefinementGroups)
            {
                switch ((RefinementGroupings)jsonRefinementGroup.GroupId)
                {
                case RefinementGroupings.brand:
                    productSearchRequest.BrandIds = jsonRefinementGroup.SelectedRefinements;
                    break;

                case RefinementGroupings.colour:
                    productSearchRequest.ColourIds = jsonRefinementGroup.SelectedRefinements;
                    break;

                case RefinementGroupings.size:
                    productSearchRequest.SizeIds = jsonRefinementGroup.SelectedRefinements;
                    break;

                default:
                    break;
                }
            }
            return(productSearchRequest);
        }
Ejemplo n.º 2
0
        private static GetProductsByCategoryRequest GenerateProductSearchRequestFrom(
            DTOs.ProductSearchRequest productSearchRequest)
        {
            var request = new GetProductsByCategoryRequest();

            request.NumberOfResultsPerPage = int.Parse(ApplicationSettingsFactory
                                                       .GetApplicationSettings().NumberOfResultsPerPage);
            request.Index      = productSearchRequest.Index;
            request.CategoryId = productSearchRequest.CategoryId;
            request.SortBy     = productSearchRequest.SortBy;

            var refinementGroups = new List <RefinementGroup>();

            foreach (var refinementGroup in productSearchRequest.RefinementGroups)
            {
                switch ((RefinementGroupings)refinementGroup.GroupId)
                {
                case RefinementGroupings.brand:
                    request.BrandIds = refinementGroup.SelectedRefinements;
                    break;

                case RefinementGroupings.color:
                    request.ColorIds = refinementGroup.SelectedRefinements;
                    break;

                case RefinementGroupings.size:
                    request.SizeIds = refinementGroup.SelectedRefinements;
                    break;

                default:
                    break;
                }
            }
            return(request);
        }
        public static Expression <Func <Product, bool> > CreateQuery(GetProductsByCategoryRequest getProductsByCategoryRequest)
        {
            var predicate = PredicateBuilder.Create <Product>(item => true);

            predicate = x => x.ProductTitle.Category.Id == getProductsByCategoryRequest.CategoryId;

            //Add Filter by BrandId
            if (getProductsByCategoryRequest.BrandIds != null && getProductsByCategoryRequest.BrandIds.Count() > 0)
            {
                predicate = predicate.Or(y => getProductsByCategoryRequest.BrandIds.Contains(y.ProductTitle.Brand.Id));
            }

            //Add Filter by ColorId
            if (getProductsByCategoryRequest.ColorIds != null && getProductsByCategoryRequest.ColorIds.Count() > 0)
            {
                predicate = predicate.And(c => getProductsByCategoryRequest.ColorIds.Contains(c.ProductTitle.Colour.Id));
            }

            //Add Filter by SizeIds
            if (getProductsByCategoryRequest.SizeIds != null && getProductsByCategoryRequest.SizeIds.Count() > 0)
            {
                predicate = predicate.And(s => getProductsByCategoryRequest.SizeIds.Contains(s.Size.Id));
            }

            return(predicate);
        }
Ejemplo n.º 4
0
        public GetProductsByCategoryResponse GetProductsByCategory(GetProductsByCategoryRequest request)
        {
            IProductSearchSpecification colourSpecification   = new ProductIsInColorSpecification(request.ColorIds);
            IProductSearchSpecification brandSpecification    = new ProductIsInBrandSpecification(request.BrandIds);
            IProductSearchSpecification sizeSpecification     = new ProductIsInSizeSpecification(request.SizeIds);
            IProductSearchSpecification categorySpecification = new ProductIsInCategorySpecification(request.CategoryId);
            IEnumerable <Product>       matchingProducts      = FindAllProducts().Where(colourSpecification.IsSatisfiedBy)
                                                                .Where(brandSpecification.IsSatisfiedBy)
                                                                .Where(sizeSpecification.IsSatisfiedBy)
                                                                .Where(categorySpecification.IsSatisfiedBy);

            switch (request.SortBy)
            {
            case ProductsSortBy.PriceLowToHigh:
                matchingProducts = matchingProducts.OrderBy(p => p.Price).ThenBy(p => p.Brand.Name).ThenBy(p => p.Name);

                break;

            case ProductsSortBy.PriceHighToLow:
                matchingProducts = matchingProducts.OrderByDescending(p => p.Price).ThenBy(p => p.Brand.Name).ThenBy(p => p.Name);

                break;
            }

            GetProductsByCategoryResponse response = CreateProductSearchResultFrom(matchingProducts, request);

            response.SelectedCategoryName = GetAllCategories().Categories.FirstOrDefault(c => c.Id == request.CategoryId)?.Name;

            return(response);
        }
Ejemplo n.º 5
0
        public ActionResult GetProductsByAjax(GetProductsByCategoryRequest request)
        {
            GetProductsByCategoryRequest  productSearchRequest = GenarateProductSeachRequest(request);
            GetProductsByCategoryResponse response             = service.GetProductsByCategory(productSearchRequest);

            return(Json(response));
        }
Ejemplo n.º 6
0
        public GetProductsByCategoryResponse GetProductsByCategory(GetProductsByCategoryRequest request)
        {
            var spec = new ProductDtoIsInCategorySpecification(request.CategoryId)
                       .And(new ProductDtoIsInColourSpecification(request.ColourIds))
                       .And(new ProductDtoIsMadeByBrandSpecification(request.BrandIds))
                       .And(new ProductDtoIsInSizeSpecification(request.SizeIds));

            IEnumerable <ProductDto> matchingProducts = FindAllProducts().Where(spec.IsSatisfiedBy);

            switch (request.SortBy)
            {
            case ProductsSortBy.PriceLowToHigh:
                matchingProducts = matchingProducts.OrderBy(p => p.Price);
                break;

            case ProductsSortBy.PriceHighToLow:
                matchingProducts = matchingProducts.OrderByDescending(p => p.Price);
                break;
            }

            GetProductsByCategoryResponse response = matchingProducts.CreateProductSearchResultFrom(request);

            response.SelectedCategoryName =
                GetAllCategories().Categories.Where(c => c.Id == request.CategoryId).FirstOrDefault().Name;

            return(response);
        }
Ejemplo n.º 7
0
        private static GetProductsByCategoryRequest GenerateProductSearchRequestFrom(JsonProductSearchRequest jsonRequest)
        {
            var request = new GetProductsByCategoryRequest();

            request.NumberOfResultsPerPage = 6;
            request.CategoryId             = jsonRequest.CategoryId;
            request.PageIndex = jsonRequest.PageIndex;
            request.SortBy    = jsonRequest.SortBy;

            foreach (var item in jsonRequest.RefinementGroups)
            {
                switch ((RefinementGroupings)item.GroupId)
                {
                case RefinementGroupings.brand:
                    request.BrandIds = item.SelectedRefinements ?? new int[0];
                    break;

                case RefinementGroupings.color:
                    request.ColorIds = item.SelectedRefinements ?? new int[0];
                    break;

                case RefinementGroupings.size:
                    request.SizeIds = item.SelectedRefinements ?? new int[0];
                    break;

                default:
                    break;
                }
            }

            return(request);
        }
        /// <summary>
        /// Get list product with selected category, seach string, order, filter after price range, filter after brands, paging
        /// </summary>
        /// <param name="request">conditions for filter</param>
        /// <returns>list product matching with conditions</returns>
        private IEnumerable <ecom_Products> GetAllProductsMatchingQueryAndSort(GetProductsByCategoryRequest request)
        {
            var searchQuery = PredicateBuilder.True <ecom_Products>();

            if (request.BrandIds.Count() > 0)
            {
                searchQuery = searchQuery.And(p => request.BrandIds.Contains((int)p.BrandId));
            }
            if (request.BeginPrice != null)
            {
                searchQuery = searchQuery.And(p => p.Price >= request.BeginPrice);
            }
            if (request.EndPrice != null)
            {
                searchQuery = searchQuery.And(p => p.Price <= request.EndPrice);
            }
            if (request.SearchString != null && request.SearchString != string.Empty)
            {
                searchQuery = searchQuery.And(p => p.Name.Contains(request.SearchString));
            }
            if (request.CategoryId != null)
            {
                searchQuery = searchQuery.And(p => p.ecom_Categories.Select(c => c.Id).Contains((int)request.CategoryId));
            }

            searchQuery = searchQuery.And(p => p.Status == (int)OnlineStore.Infractructure.Utility.Define.Status.Active);

            IEnumerable <ecom_Products> productsMatchingRefinement = db.Get(
                filter: searchQuery, includeProperties: "ecom_Brands,ecom_Categories,share_Images");

            switch (request.SortBy)
            {
            case ProductsSortBy.PriceLowToHigh:
                productsMatchingRefinement = productsMatchingRefinement
                                             .OrderBy(p => p.Price);
                break;

            case ProductsSortBy.PriceHighToLow:
                productsMatchingRefinement = productsMatchingRefinement
                                             .OrderByDescending(p => p.Price);
                break;

            case ProductsSortBy.ProductNameAToZ:
                productsMatchingRefinement = productsMatchingRefinement
                                             .OrderBy(p => p.Name);
                break;

            case ProductsSortBy.ProductNameZToA:
                productsMatchingRefinement = productsMatchingRefinement
                                             .OrderByDescending(p => p.Name);
                break;

            default: productsMatchingRefinement = productsMatchingRefinement
                                                  .OrderByDescending(p => p.SortOrder);
                break;
            }

            return(productsMatchingRefinement.ToList());
        }
Ejemplo n.º 9
0
        public IActionResult GetProductsByCategory(int categoryId)
        {
            GetProductsByCategoryRequest  productSearchRequest    = GenerateInitialProductSearchRequestFrom(categoryId);
            GetProductsByCategoryResponse response                = _cachedProductCatalogService.GetProductsByCategory(productSearchRequest);
            ProductSearchResultView       productSearchResultView = GetProductSearchResultViewFrom(response);

            return(View("ProductSearchResults", productSearchResultView));
        }
Ejemplo n.º 10
0
        public IActionResult GetProducts([FromBody] ProductSearchRequest jsonProductSearchRequest)
        {
            GetProductsByCategoryRequest  productSearchRequest    = GenerateProductSearchRequestFrom(jsonProductSearchRequest);
            GetProductsByCategoryResponse response                = _cachedProductCatalogService.GetProductsByCategory(productSearchRequest);
            ProductSearchResultView       productSearchResultView = GetProductSearchResultViewFrom(response);

            return(Ok(productSearchResultView));
        }
Ejemplo n.º 11
0
        public JsonResult GetProductsByAjax(JsonProductSearchRequest jsonProductSearchRequest)
        {
            GetProductsByCategoryRequest  productSearchRequest = GenerateProductSearchRequestFrom(jsonProductSearchRequest);
            GetProductsByCategoryResponse response             = _productService.GetProductsByCategory(productSearchRequest);

            ProductSearchResultView productSearchResultView = GetProductSearchResultViewFrom(response);

            return(Json(productSearchResultView));
        }
Ejemplo n.º 12
0
        public GetProductsByCategoryResponse GetProductsByCategory(GetProductsByCategoryRequest request)
        {
            Expression <Func <Product, bool> > productQuery          = ProductSearchRequestQueryGenerator.CreateQueryFor(request);
            IEnumerable <Product>         productsMatchingRefinement = GetAllProductsMatchingQueryAndSort(request, productQuery);
            GetProductsByCategoryResponse response = CreateProductSearchResultFrom(productsMatchingRefinement, request);

            response.SelectedCategoryName = _categoryRepository.FindBy(request.CategoryId).Name;

            return(response);
        }
Ejemplo n.º 13
0
        private static GetProductsByCategoryRequest GenerateInitialProductSearchRequestFrom(int categoryId)
        {
            GetProductsByCategoryRequest productSearchRequest = new GetProductsByCategoryRequest();

            productSearchRequest.NumberOfResultsPerPage = ApplicationSettingsFactory.GetApplicationSettings().NumberOfResultsPerPage;
            productSearchRequest.CategoryId             = categoryId;
            productSearchRequest.Index  = 1;
            productSearchRequest.SortBy = ProductsSortBy.PriceHighToLow;
            return(productSearchRequest);
        }
Ejemplo n.º 14
0
        private GetProductsByCategoryRequest GenerateInitialProductSearchRequestFrom(int categoryId)
        {
            GetProductsByCategoryRequest productSearchRequest = new GetProductsByCategoryRequest();

            productSearchRequest.NumberOfResultsPerPage = int.Parse(_configuration["NumberOfResultsPerPage"]);
            productSearchRequest.CategoryId             = categoryId;
            productSearchRequest.Index  = 1;
            productSearchRequest.SortBy = ProductsSortBy.PriceHighToLow;

            return(productSearchRequest);
        }
Ejemplo n.º 15
0
        private static GetProductsByCategoryRequest GenerateInitialSearchRequestFrom(int categoryId)
        {
            var request = new GetProductsByCategoryRequest();

            request.NumberOfResultsPerPage = 6;
            request.CategoryId             = categoryId;
            request.PageIndex = 1;
            request.SortBy    = ProductsSortBy.PriceHighToLow;

            return(request);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Genarate initial Request object to get list product after category
        /// </summary>
        /// <param name="categoryId">id of selected category</param>
        /// <returns></returns>
        private GetProductsByCategoryRequest CreateInitialProductSearchRequest(int categoryId)
        {
            GetProductsByCategoryRequest request = new GetProductsByCategoryRequest()
            {
                CategoryId             = categoryId,
                Index                  = 1,
                NumberOfResultsPerPage = productPerPage,
                SortBy                 = ProductsSortBy.ProductNameAToZ
            };

            return(request);
        }
Ejemplo n.º 17
0
        public GetProductsByCategoryResponse GetProductsByCategory(GetProductsByCategoryRequest request)
        {
            var query = ProductSearchRequestQueryGenerator.CreateQueryFor(request);

            var products = _productRepository.FindBy(query);

            var response = products.CreateResultFrom(request);

            response.SelectedCategoryName = _categoryRepository.FindBy(request.CategoryId).Name;

            return(response);
        }
Ejemplo n.º 18
0
        public static GetProductsByCategoryResponse CreateProductSearchResultFrom(
            this IEnumerable <Product> productsMatchingRefinement,
            GetProductsByCategoryRequest request)
        {
            GetProductsByCategoryResponse productSearchResultView = new GetProductsByCategoryResponse();
            IEnumerable <ProductTitle>    productsFound           = productsMatchingRefinement.Select(p => p.ProductTitle).Distinct();

            productSearchResultView.SelectedCategory    = request.CategoryId;
            productSearchResultView.NumberOfTitlesFound = productsFound.Count();
            productSearchResultView.TotalNumberOfPages  = NoOfResultPagesGiven(request.NumberOfResultsPerPage, productSearchResultView.NumberOfTitlesFound);
            productSearchResultView.RefinementGroups    = GenerateAvailableProductRefinementsFrom(productsFound);
            productSearchResultView.Products            = CropProductListToSatisfyGivenIndex(request.Index, request.NumberOfResultsPerPage, productsFound);
            return(productSearchResultView);
        }
        public static Query CreateQueryFor(
            GetProductsByCategoryRequest getProductsByCategoryRequest)
        {
            Query productQuery = new Query();
            Query colorQuery   = new Query();
            Query brandQuery   = new Query();
            Query sizeQuery    = new Query();

            colorQuery.QueryOperator = QueryOperator.Or;
            foreach (int id in getProductsByCategoryRequest.ColorIds)
            {
                colorQuery.Add(Criterion.Create <Product>(p => p.Color.Id, id,
                                                          CriteriaOperator.Equal));
            }

            if (colorQuery.Criteria.Count() > 0)
            {
                productQuery.AddSubQuery(colorQuery);
            }

            brandQuery.QueryOperator = QueryOperator.Or;
            foreach (int id in getProductsByCategoryRequest.BrandIds)
            {
                brandQuery.Add(Criterion.Create <Product>(p => p.Brand.Id, id,
                                                          CriteriaOperator.Equal));
            }

            if (brandQuery.Criteria.Count() > 0)
            {
                productQuery.AddSubQuery(brandQuery);
            }

            sizeQuery.QueryOperator = QueryOperator.Or;
            foreach (int id in getProductsByCategoryRequest.SizeIds)
            {
                sizeQuery.Add(Criterion.Create <Product>(p => p.Size.Id, id,
                                                         CriteriaOperator.Equal));
            }

            if (sizeQuery.Criteria.Count() > 0)
            {
                productQuery.AddSubQuery(sizeQuery);
            }

            productQuery.Add(Criterion.Create <Product>(p => p.Category.Id,
                                                        getProductsByCategoryRequest.CategoryId, CriteriaOperator.Equal));

            return(productQuery);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Genarate request object to get list matched products from service
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private GetProductsByCategoryRequest GenarateProductSeachRequest(GetProductsByCategoryRequest request)
        {
            GetProductsByCategoryRequest productSeachRequest = new GetProductsByCategoryRequest()
            {
                CategoryId             = request.CategoryId,
                BrandIds               = request.BrandIds,
                SortBy                 = request.SortBy,
                BeginPrice             = request.BeginPrice,
                EndPrice               = request.EndPrice,
                Index                  = request.Index,
                NumberOfResultsPerPage = productPerPage,
                SearchString           = request.SearchString
            };

            return(productSeachRequest);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Get ProductView contain list product of selected category
        /// </summary>
        /// <param name="id">id of category</param>
        /// <returns></returns>
        public ActionResult GetProductByCategory(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GetProductsByCategoryRequest  request  = CreateInitialProductSearchRequest((int)id);
            GetProductsByCategoryResponse response = service.GetProductsByCategory(request);

            PopulateStatusDropDownList();
            PopulateNewProductList();
            PopulateBestSellProductList();
            PopulateCategoryList();
            PopulateTopCategoryList();
            return(View("DisplayProducts", response));
        }
Ejemplo n.º 22
0
        private IEnumerable <Product> GetAllProductsMatchingQueryAndSort(GetProductsByCategoryRequest request, Expression <Func <Product, bool> > where)
        {
            IEnumerable <Product> productsMatchingRefinement = _productRepository.GetMany(where);

            switch (request.SortBy)
            {
            case ProductsSortBy.PriceLowToHigh:
                productsMatchingRefinement = productsMatchingRefinement.OrderBy(p => p.Price);
                break;

            case ProductsSortBy.PriceHighToLow:
                productsMatchingRefinement = productsMatchingRefinement.OrderByDescending(p => p.Price);
                break;
            }
            return(productsMatchingRefinement);
        }
Ejemplo n.º 23
0
        private IEnumerable <Product> GetAllProductsMatchingQueryAndSort(GetProductsByCategoryRequest request, Query productQuery)
        {
            IEnumerable <Product> productsMatchingRefinement = _productRepository.FindBy(productQuery);

            switch (request.SortBy)
            {
            case ProductsSortBy.PriceLowToHigh:
                productsMatchingRefinement = productsMatchingRefinement.OrderBy(p => p.Price);
                break;

            case ProductsSortBy.PriceHighToLow:
                productsMatchingRefinement = productsMatchingRefinement.OrderByDescending(p => p.Price);
                break;
            }
            return(productsMatchingRefinement);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Get ProductView contain list product of selected category
        /// </summary>
        /// <param name="id">id of category</param>
        /// <returns></returns>
        public ActionResult GetProductByCategory(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GetProductsByCategoryRequest  request  = CreateInitialProductSearchRequest((int)id);
            GetProductsByCategoryResponse response = service.GetProductsByCategory(request);

            PopulateStatusDropDownList();
            PopulateNewProductList();
            PopulateCategoryTreeViewDataSource();
            ViewBag.BakeryCategoryList       = GetChildrenCategories(8);
            ViewBag.KitchenToolsCategoryList = GetChildrenCategories(9);

            return(View("DisplayProducts", response));
        }
        public GetProductsByCategoryResponse GetProductsByCategory(GetProductsByCategoryRequest request)
        {
            GetProductsByCategoryResponse response;

            //ISpecification<Product> productSpec = ProductSearchRequestQueryGenerator.CreateSpecificationFor(request);

            var productsMatchingRefinement = GetAllProductsMatchingQuery(request);

            response = productsMatchingRefinement.CreateProductSearchResultFrom(request);

            var category = _presentationRepository.FindFirstByExample <CategoryDto>(new { Id = request.CategoryId });

            response.SelectedCategoryName = category.Name;


            return(response);
        }
        public GetProductsByCategoryResponse GetProductsByCategory(GetProductsByCategoryRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var response = new GetProductsByCategoryResponse();

            var specification =
                new DirectSpecification <Product>(product => product.ProductTitle.Category.Id == request.CategoryId);

            switch (request.SortBy)
            {
            case ProductsSortBy.PriceHighToLow:
            {
                response =
                    _productRepository.GetBySpec(specification).OrderByDescending(p => p.ProductTitle.Price).
                    CreateProductSearchResultFrom(request);
                break;
            }

            case ProductsSortBy.PriceLowToHigh:
            {
                response =
                    _productRepository.GetBySpec(specification).OrderBy(p => p.ProductTitle.Price).
                    CreateProductSearchResultFrom(request);
                break;
            }
            }

            var singleCategory =
                _categoryRepository.GetBySpec(
                    new DirectSpecification <Category>(category => category.Id == request.CategoryId)).SingleOrDefault();

            if (singleCategory != null)
            {
                response.SelectedCategoryName = singleCategory.Name;
            }

            return(response);
        }
Ejemplo n.º 27
0
        private GetProductsByCategoryRequest GenerateProductSearchRequestFrom(ProductSearchRequest jsonProductSearchRequest)
        {
            GetProductsByCategoryRequest productSearchRequest = new GetProductsByCategoryRequest();

            productSearchRequest.NumberOfResultsPerPage = int.Parse(_configuration["NumberOfResultsPerPage"]);

            if (jsonProductSearchRequest != null)
            {
                productSearchRequest.Index      = jsonProductSearchRequest.Index;
                productSearchRequest.CategoryId = jsonProductSearchRequest.CategoryId;
                productSearchRequest.SortBy     = jsonProductSearchRequest.SortBy;

                foreach (var jsonRefinementGroup in jsonProductSearchRequest.RefinementGroups)
                {
                    switch ((RefinementGroupings)jsonRefinementGroup.GroupId)
                    {
                    case RefinementGroupings.Brand:
                        productSearchRequest.BrandIds = jsonRefinementGroup.SelectedRefinements;

                        break;

                    case RefinementGroupings.Color:
                        productSearchRequest.ColorIds = jsonRefinementGroup.SelectedRefinements;

                        break;

                    case RefinementGroupings.Size:
                        productSearchRequest.SizeIds = jsonRefinementGroup.SelectedRefinements;

                        break;

                    default:
                        break;
                    }
                }
            }

            return(productSearchRequest);
        }
Ejemplo n.º 28
0
        public static GetProductsByCategoryResponse CreateResultFrom(
            this IEnumerable <Product> products,
            GetProductsByCategoryRequest request)
        {
            var result = new GetProductsByCategoryResponse();

            var titlesFound = products.Select(p => p.Title).Distinct();

            result.SelectedCategory = request.CategoryId;

            result.NumberOfTitlesFound = titlesFound.Count();

            result.TotalNumberOfPages = NoOfResultPagesGiven(request.NumberOfResultsPerPage, result.NumberOfTitlesFound);

            result.RefinementGroups = GenerateAvailableProductRefinementsFrom(titlesFound);

            result.Products = CropProductListToSatisfyGivenIndex(request.PageIndex, request.NumberOfResultsPerPage, titlesFound);

            result.CurrentPage = request.PageIndex;

            return(result);
        }
        private IEnumerable <ProductDto> GetAllProductsMatchingQuery(GetProductsByCategoryRequest request)
        {
            var queryDtoSpec = new ProductDtoIsInCategorySpecification(request.CategoryId)
                               .And(new ProductDtoIsInColourSpecification(request.ColourIds))
                               .And(new ProductDtoIsMadeByBrandSpecification(request.BrandIds))
                               .And(new ProductDtoIsInSizeSpecification(request.SizeIds));

            IEnumerable <ProductDto> productsMatchingRefinement =
                _presentationRepository.FindBySpec <ProductDto>(queryDtoSpec);


            // TODO: Correct Sort By Logic)
            //switch (request.SortBy)
            //{
            //    case ProductsSortBy.PriceLowToHigh:
            //        productsMatchingRefinement = productsMatchingRefinement.OrderBy(p => p.Price);
            //        break;
            //    case ProductsSortBy.PriceHighToLow:
            //        productsMatchingRefinement = productsMatchingRefinement.OrderByDescending(p => p.Price);
            //        break;
            //}

            return(productsMatchingRefinement);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Get list product after category
        /// </summary>
        /// <param name="request">condition for filter</param>
        /// <returns>matched condition products</returns>
        public GetProductsByCategoryResponse GetProductsByCategory(GetProductsByCategoryRequest request)
        {
            string categoryName = categoryRepository.GetByID(request.CategoryId).Name;
            IEnumerable <ecom_Products> foundProducts = GetAllProductsMatchingQueryAndSort(request);

            GetProductsByCategoryResponse reponse = new GetProductsByCategoryResponse()
            {
                SelectedCategoryName = categoryName,
                SelectedCategory     = request.CategoryId,
                BeginPrice           = request.BeginPrice,
                EndPrice             = request.EndPrice,
                NumberOfTitlesFound  = foundProducts.Count(),
                TotalNumberOfPages   = (int)Math.Ceiling((double)foundProducts.Count() / request.NumberOfResultsPerPage),
                CurrentPage          = request.Index,
                TotalProducts        = foundProducts.Count(),
                SearchString         = request.SearchString,
                SortBy   = (int)request.SortBy,
                BrandIds = request.BrandIds,
                Products = CropProductListToSatisfyGivenIndex(foundProducts, request.Index, request.NumberOfResultsPerPage).ConvertToProductSummaryViews(),
                Brands   = foundProducts.Select(p => p.ecom_Brands).Where(b => b != null).Distinct().ToList().ConvertToBrandSummaryViews()// return list Brand exist in group product belong to selected category
            };

            return(reponse);
        }