public async Task <IEnumerable <TeamPlayer> > GetAvailableAwayOpponents(int id, MatchFilter filter)
        {
            if (filter == null)
            {
                filter = new MatchFilter();
            }
            filter.Played = false;
            var filterMatch = filter.FilterMatchs(db.Matches);

            // Get all teamPlayers which is id not <id> that have at least one unplayed match with the player with <id>
            return(await db.TeamPlayers.Where(tp => tp.Id != id &&
                                              tp.Scores.Any(sc => filterMatch.Contains(sc.Match) &&
                                                            sc.Location == Location.Away &&
                                                            sc.Match.Scores.Any(sc2 => sc2.TeamPlayerId == id)))
                   .Include(tp => tp.Player)
                   .Include(tp => tp.Team)
                   .OrderBy(tp => tp.Player.Name)
                   .ThenBy(tp => tp.Team.Name)
                   .ToListAsync());
        }
        public async Task <IEnumerable <TeamPlayer> > GetAllWithUnplayedMatches(Location location, MatchFilter filter)
        {
            if (filter == null)
            {
                filter = new MatchFilter();
            }
            filter.Played = false;
            var filterMatch = filter.FilterMatchs(db.Matches);

            return(await db.TeamPlayers.Where(tp => tp.Scores.Any(s => filterMatch.Contains(s.Match) &&
                                                                  s.Location == location))
                   .Include(tp => tp.Player)
                   .Include(tp => tp.Team)
                   .OrderBy(tp => tp.Player.Name)
                   .ThenBy(tp => tp.Team.Name)
                   .ToListAsync());
        }
Example #3
0
 public async Task <IEnumerable <Match> > GetAllWithFilter(MatchFilter filter)
 {
     return(await FilterMatchs(db.Matches, filter).ToListAsync());
 }