public IEnumerable <Employee> Filter(FilterModel model, string[] includes = null) { Expression <Func <Employee, bool> > FilterExpression(FilterModel _model) { Expression <Func <Employee, bool> > expression = null; if (_model == null) { return(null); } if (!String.IsNullOrEmpty(_model.Name)) { expression = x => x.Name.Contains(_model.Name.ToString()); } if (!String.IsNullOrEmpty(_model.Position)) { expression = ExpressionCombiner.And <Employee>(expression, x => x.Position.Contains(_model.Position.ToString())); } return(expression); } var result = base.Filter(FilterExpression(model), includes); return(result); }
private Expression <Func <Gig, bool> > _getMyAttendingGigFilterExpression(GigFilterParams filter) { Expression <Func <Gig, bool> > filterExpression = g => g.DateTime > DateTime.Now; return(string.IsNullOrWhiteSpace(filter.SearchTerm) ? filterExpression : ExpressionCombiner.And(filterExpression, getSeachFilter(filter))); }
private Expression <Func <Gig, bool> > _getGigFilterExpression(GigFilterParams filter) { Expression <Func <Gig, bool> > filterExpression = g => g.DateTime > DateTime.Now && g.Artist.Activated && !g.IsCancelled; return(string.IsNullOrWhiteSpace(filter.SearchTerm) ? filterExpression : ExpressionCombiner.And(filterExpression, getSeachFilter(filter))); }
public Expression <Func <T, bool> > ToExpression <T>() where T : class { if (Filters.Count == 0) { return(x => true); } if (Filters.Count == 1) { return(Filters.First().ToExpression <T>()); } Expression <Func <T, bool> > expression = Filters.First().ToExpression <T>(); expression = Filters.ToList() .Skip(1) .Aggregate(expression, (current, filter) => Logic == FilterLogic.And ? ExpressionCombiner.And(current, filter.ToExpression <T>()) : ExpressionCombiner.Or(current, filter.ToExpression <T>())); return(expression); }
public IEnumerable <ApplicationUser> GetUsersByRoleId(string roleId, string query = null) { Expression <Func <ApplicationUser, bool> > filterExpression = u => u.Activated && u.Roles.Any(r => r.RoleId == roleId); if (query == null) { return(_context.Users .Where(filterExpression) .OrderBy(u => u.Name).ToList()); } { Expression <Func <ApplicationUser, bool> > nameFilter = u => u.Name.Contains(query); filterExpression = ExpressionCombiner.And(filterExpression, nameFilter); } return(_context.Users .Where(filterExpression) .OrderBy(u => u.Name).ToList()); }