public IEnumerable <Team> Handle(TeamsByIdsQuery query)
        {
            List <string> teamIds = new List <string>();

            teamIds.AddRange(query.HomeTeamIds);
            teamIds.AddRange(query.AwayTeamIds);
            teamIds.Distinct();

            EntitiesByIdQuery <Team> teamsQuery = new EntitiesByIdQuery <Team>(teamIds);
            IEnumerable <Team>       teams      = teamsHandler.Handle(teamsQuery);

            return(teams);
        }
Exemplo n.º 2
0
        public IEnumerable <MatchResult> Handle(AllMatchesQuery query)
        {
            IEnumerable <Match> matches = matchesCache.All(_ => true).OrderBy(x => x.Type).Take(query.Take);

            EntitiesByIdQuery <Tournament> tournamentsQuery = new EntitiesByIdQuery <Tournament>(matches.Select(x => x.TournamentId).Distinct());
            IEnumerable <Tournament>       tournaments      = tournamentsHandler.Handle(tournamentsQuery);

            TeamsByIdsQuery    teamsQuery = new TeamsByIdsQuery(matches.Select(x => x.HomeTeamId), matches.Select(x => x.AwayTeamId));
            IEnumerable <Team> teams      = teamsHandler.Handle(teamsQuery);

            ICollection <MatchResult> matchResults = new List <MatchResult>();

            foreach (var match in matches)
            {
                MatchResult matchResult = Mapper.Map <MatchResult>(match);
                matchResult.HomeTeam   = teams.First(x => x.Id == match.HomeTeamId).Name;
                matchResult.AwayTeam   = teams.First(x => x.Id == match.AwayTeamId).Name;
                matchResult.Tournament = tournaments.First(x => x.Id == match.TournamentId).Name;

                matchResults.Add(matchResult);
            }

            return(matchResults);
        }