public static Query CreateQueryFor(GetProductsByCategoryRequest request)
        {
            Query productQuery = new Query();
            Query colourQuery = new Query();
            Query brandQuery = new Query();
            Query sizeQuery = new Query();

            colourQuery.QueryOperator = QueryOperator.Or;
            foreach (int id in request.ColourIds)
                colourQuery.Add(Criterion.Create<Product>(p => p.Colour.Id, id, CriteriaOperator.Equal));

            if (colourQuery.Criteria.Count() > 0)
                productQuery.AddSubQuery(colourQuery);

            brandQuery.QueryOperator = QueryOperator.Or;
            foreach (int id in request.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 request.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, request.CategoryId, CriteriaOperator.Equal));
            return productQuery;
        }
        public GetFeaturedProductsResponse GetFeaturedProducts()
        {
            GetFeaturedProductsResponse response = new GetFeaturedProductsResponse();

            Query productQuery = new Query();

            productQuery.OrderByProperty = new OrderByClause() { Desc = true, PropertyName = PropertyNameHelper.ResolvePropertyName<ProductTitle>(pt => pt.Price) };

            response.Products = _productTitleRepository.FindBy(productQuery, 0, 6).ConvertToProductViews();

            return response;
        }
        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.º 4
0
 public void AddSubQuery(Query subQuery)
 {
     _subQueries.Add(subQuery);
 }