public List <Team> GetBestTeamsOn(List <League> leagues, BestTeamCriteria criteria) { List <Team> bestTeams = new List <Team>(); foreach (League league in leagues) { Team bestTeam = GetBestTeamFromLeagueOn(league, criteria); bestTeams.Add(bestTeam); } return(bestTeams); }
public Team GetBestTeamFromLeagueOn(League league, BestTeamCriteria criteria) { Dictionary <string, Team> teams = new Dictionary <string, Team>(); foreach (Match match in league.Matches) { if (match.Score == null) { continue; } if (teams.ContainsKey(match.Team1)) { teams[match.Team1].GoalsScored += match.Score.Ft[0]; teams[match.Team1].ConcededGoals += match.Score.Ft[1]; } else { teams[match.Team1] = new Team( match.Team1, match.Score.Ft[0], match.Score.Ft[1]); } if (teams.ContainsKey(match.Team2)) { teams[match.Team2].GoalsScored += match.Score.Ft[1]; teams[match.Team2].ConcededGoals += match.Score.Ft[0]; } else { teams[match.Team2] = new Team( match.Team2, match.Score.Ft[1], match.Score.Ft[0]); } } Team bestTeam = teams.OrderByDescending(match => match.Value, new ComparerByGoals(criteria)).FirstOrDefault().Value; bestTeam.LeagueNumber = league.LeagueNumber; return(bestTeam); }
public ComparerByGoals(BestTeamCriteria criteria) { _currentCriteria = criteria; }