public ProductWithFiltersForCountSpecification(ProductSpecsParams productParams) : base(x =>
                                                                                         (string.IsNullOrEmpty(productParams.Search) || x.Name.ToLower().Contains(productParams.Search)) &&
                                                                                         (!productParams.BrandId.HasValue || x.ProductBrandId == productParams.BrandId) &&
                                                                                         (!productParams.TypeId.HasValue || x.ProductTypeId == productParams.TypeId)
                                                                                         )
 {
 }
Exemple #2
0
        public ProductsWithTypesAndBrandsSpecification(ProductSpecsParams productParams) : base(x =>
                                                                                                (string.IsNullOrEmpty(productParams.Search) || x.Name.ToLower().Contains(productParams.Search)) &&
                                                                                                (!productParams.BrandId.HasValue || x.ProductBrandId == productParams.BrandId) &&
                                                                                                (!productParams.TypeId.HasValue || x.ProductTypeId == productParams.TypeId)
                                                                                                )
        {
            AddInclude(x => x.ProductBrand);
            AddInclude(x => x.ProductType);
            AddOrderBy(x => x.Name);
            ApplyPaging(productParams.PageSize * (productParams.PageIndex - 1), productParams.PageSize);
            if (!string.IsNullOrEmpty(productParams.Sort))
            {
                switch (productParams.Sort)
                {
                case "priceAsc":
                    AddOrderBy(p => p.Price);
                    break;

                case "priceDesc":
                    AddOrderByDescending(p => p.Price);
                    break;

                default:
                    AddOrderBy(p => p.Name);
                    break;
                }
            }
        }