Esempio n. 1
0
        public async Task <IList <Product> > Build(NameValueCollection qs = null)
        {
            // include
            _query = _context.Products
                     .Include(p => p.SubImages)
                     .Include(p => p.SubCategory)
                     .Include(p => p.Reviews).AsQueryable();

            // order clause using strategy
            // if qs[Sort] is not defined, assign 0 as default
            int sortId = (qs[QueryConstants.Sort] == null) ? 0 : Convert.ToInt32(qs[QueryConstants.Sort]);

            SortConstants sortConst = (SortConstants)sortId;

            IOrderClauseStrategy orderStrategy = _orderStrategyFactory[sortConst];

            _query = orderStrategy.GetOrderClause(_query);

            // remove Sort name and value from qs
            qs.Remove(QueryConstants.Sort);

            // where clause using specification
            // add Where clause only when qs include others rather than sort
            if (qs.Count != 0)
            {
                _query = _query.Where(_specificationBuilder.Build(qs)).AsQueryable();
            }

            return(await _query.ToListAsync());
        }
Esempio n. 2
0
 public async Task <IActionResult> Get([FromQuery] TodoQueryParams specParams)
 {
     return(Ok(new
     {
         Todos = await _context.Todos.Where(
             _specBuilder.Build(specParams).Expression
             ).ToListAsync()
     }));
 }
Esempio n. 3
0
        public IExpectInitialLoyaltyPointBalanceSpecification WithIdentity(ISpecificationBuilder <LoyaltyPointAccountIdentitySpecification> specificationBuilder)
        {
            var specification = new LoyaltyPointAccountSpecification
            {
                Identity = specificationBuilder.Build()
            };

            return(new LoyaltyPointAccountSpecificationBuilder(specification));
        }
Esempio n. 4
0
        public SearchRequest Create<TModel>(SearchRequestModel data) where TModel : class
        {
            Check.NotNull(data, "data");

            var searchSpecification = data.FilterSettings.Filters.Any()
                ? _specificationBuilder.Build<TModel>(data.FilterSettings)
                : null;

            var request = new SearchRequest
            {
                Specification = searchSpecification,
                SortingSettings = data.SortingSettings,
                PagingSettings = data.PagingSettings
            };
            return request;
        }
Esempio n. 5
0
 public PasswordFieldValidationRule(string message, string field, ISpecificationBuilder <Test, ITestPasswordSpecification> specificationBuilder)
     : base(message, field, specificationBuilder.Build())
 {
 }
Esempio n. 6
0
 public bool TestValidate(Test test)
 {
     return(_testPasswordSpecificationBuilder.Build().IsSatisfiedBy(test));
 }
Esempio n. 7
0
 public Expression <Func <Product, bool> > Build(NameValueCollection qs)
 {
     return(_spBuilder.Build(qs));
 }