private IQueryable <Player> FilterPlayers(IQueryable <Player> query, PlayerFilter filter) { if (filter != null) { if (filter.Id != 0) { query = query.Where(m => m.Id == filter.Id); } if (!String.IsNullOrEmpty(filter.Name)) { query = query.Where(m => m.Name.Contains(filter.Name)); } if (filter.Archived != null) { query = query.Where(m => m.Archived == filter.Archived); } } return(query); }
public async Task <IEnumerable <Player> > GetAllWithFilter(PlayerFilter filter) { return(await FilterPlayers(db.Players, filter).OrderBy(p => p.Name).ToListAsync()); }