Пример #1
0
        public ProductsWithTypesAndBrandsSpecification(ProductSpecificationParams productParameters)
            : base(x =>
                   (string.IsNullOrEmpty(productParameters.Search) || x.Name.ToLower().Contains(productParameters.Search)) &&
                   (!productParameters.BrandId.HasValue || x.ProductBrandId == productParameters.BrandId) &&
                   (!productParameters.TypeId.HasValue || x.ProductTypeId == productParameters.TypeId)
                   )
        {
            AddInclude(x => x.ProductType);
            AddInclude(x => x.ProductBrand);
            AddOrderBy(x => x.Name);
            ApplyPaging(productParameters.PageSize * (productParameters.PageIndex - 1), productParameters.PageSize);

            if (string.IsNullOrEmpty(productParameters.Sort))
            {
                return;
            }

            switch (productParameters.Sort)
            {
            case "priceAsc":
                AddOrderBy(o => o.Price);
                break;

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

            default:
                AddOrderBy(o => o.Name);
                break;
            }
        }
Пример #2
0
 public ProductWithFiltersForCountSpecification(ProductSpecificationParams productParameters)
     : base(x =>
            (string.IsNullOrEmpty(productParameters.Search) || x.Name.ToLower().Contains(productParameters.Search)) &&
            (!productParameters.BrandId.HasValue || x.ProductBrandId == productParameters.BrandId) &&
            (!productParameters.TypeId.HasValue || x.ProductTypeId == productParameters.TypeId)
            )
 {
 }