public ProductsWithTypesAndBrandsSpecification(ProductParams productParams)
            : base(p =>
                   (string.IsNullOrEmpty(productParams.Search) || p.Name.ToLower().Contains(productParams.Search)) &&
                   (!productParams.BrandId.HasValue || p.ProductBrandId == productParams.BrandId) &&
                   (!productParams.TypeId.HasValue || p.ProductTypeId == productParams.TypeId)
                   )
        {
            AddInclude(p => p.ProductBrand);
            AddInclude(p => p.ProductType);
            AddOrderBy(p => p.Name);
            //AddOrderByDesc(p => p.Name);
            AddPaging(productParams.PageSize * (productParams.PageIndex - 1), productParams.PageSize);

            if (!string.IsNullOrEmpty(productParams.Sort))
            {
                switch (productParams.Sort)
                {
                case "priceAsc":
                    AddOrderBy(p => p.Price);
                    break;

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

                default:
                    AddOrderBy(p => p.Name);
                    break;
                }
            }
        }
Example #2
0
 public ProductWithFiltersForCountSpecification(ProductParams productParams)
     : base(p =>
            (string.IsNullOrEmpty(productParams.Search) || p.Name.ToLower().Contains(productParams.Search)) &&
            (!productParams.BrandId.HasValue || p.ProductBrandId == productParams.BrandId) &&
            (!productParams.TypeId.HasValue || p.ProductTypeId == productParams.TypeId)
            )
 {
 }