public ProductWithFiltersForCountSpecification(ProductSpecificationParams specificationParams)
     : base(x =>
            (string.IsNullOrEmpty(specificationParams.Search) || x.Name.ToLower().Contains(specificationParams.Search)) &&
            (!specificationParams.BrandId.HasValue || x.ProductBrandId == specificationParams.BrandId) &&
            (!specificationParams.TypeId.HasValue || x.ProductTypeId == specificationParams.TypeId))
 {
 }
Beispiel #2
0
        public ProductsWithTypesAndBrandsSpecification(ProductSpecificationParams productParams)
        // add criteria
            : base(p =>
                   (string.IsNullOrEmpty(productParams.Search) || p.Name.ToLower().Contains(productParams.Search)) && // search product by name
                   (!productParams.BrandId.HasValue || p.ProductBrandId == productParams.BrandId) &&                  // searach product by  brand id
                   (!productParams.TypeId.HasValue || p.ProductTypeId == productParams.TypeId))                       // search product by type id
        {
            AddInclude(item => item.ProductType);
            AddInclude(item => item.ProductBrand);
            AddOrderByAsc(x => x.Name);
            ApplyPaging(productParams.PageSize * (productParams.PageIndex - 1), productParams.PageSize); //set item on one page

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

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

                default:
                    AddOrderByAsc(n => n.Name);
                    break;
                }
            }
        }
Beispiel #3
0
        public ProductsWithTypesAndBrandsSpecification(ProductSpecificationParams 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.ProductType);
            AddInclude(x => x.ProductBrand);
            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;
                }
            }
        }
Beispiel #4
0
 public ProductWithFilterForCountSpecification(ProductSpecificationParams productParams)
     : base(q => // OR/Else condition
            (string.IsNullOrEmpty(productParams.Search) || q.Name.ToLower().Contains(productParams.Search)) &&
            (!productParams.BrandId.HasValue || q.ProductBrandId == productParams.BrandId) &&
            (!productParams.TypeId.HasValue || q.ProductTypeId == productParams.TypeId))
 {
 }
Beispiel #5
0
        public ProductsWithTypesAndBrandsSpecification(ProductSpecificationParams productParams)
            : base(q => // OR/Else condition
                   (string.IsNullOrEmpty(productParams.Search) || q.Name.ToLower().Contains(productParams.Search)) &&
                   (!productParams.BrandId.HasValue || q.ProductBrandId == productParams.BrandId) &&
                   (!productParams.TypeId.HasValue || q.ProductTypeId == productParams.TypeId))
        {
            AddInclude(q => q.ProductBrand);
            AddInclude(q => q.ProductType);

            // Sort or Ordering
            switch (productParams.Sort)
            {
            case "priceAsc":
                AddOrderBy(q => q.Price);
                break;

            case "priceDesc":
                AddOrderByDecending(q => q.Price);
                break;

            case "nameAsc":
                AddOrderBy(q => q.Price);
                break;

            case "nameDesc":
                AddOrderByDecending(q => q.Price);
                break;

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

            // Paging
            ApplyPaging(productParams.PageSize * (productParams.PageIndex - 1), productParams.PageSize);
        }