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