Exemplo n.º 1
0
 public ProductWithFiltersForCountSpecification(ProductsSpecParams 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))
 {
 }
        public ProductsWithTypesAndBrandsSpecification(ProductsSpecParams 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(n => n.Name);
                    break;
                }
            }
        }
        public ProductWithBrandAndTypesSpecification(ProductsSpecParams 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)
                )
        {
            //registration of specs of query to be executed.
            //methods provided by basespecification.
            this.AddInclude(p => p.ProductType);
            this.AddInclude(p => p.ProductBrand);

            //adding pagination specs.
            this.AddPagination(ProductParams.PageSize * (ProductParams.PageIndex - 1), ProductParams.PageSize);


            switch (ProductParams.Sort)
            {
            case "priceAsc":
            {
                this.AddOrderBy(p => p.Price);
                break;
            }

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

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