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()); }
public string Build(int type) { IOrderClauseStrategy orderStrategy = _orderStrategyFactory[(SortConstants)type]; return(orderStrategy.GetType().ToString()); }