private int SortOnPointsAndGoals(LeagueTablePosition pos1, LeagueTablePosition pos2) { // Points will be sorted ascending, hence Y followed by X. int result = pos2.Points.CompareTo(pos1.Points); // If necessary, matches will be sorted descending, hence X followed by Y. if (result == 0) { result = pos1.Matches.CompareTo(pos2.Matches); } // If necessary, goal difference will be sorted. if (result == 0) { result = pos2.GoalDifference.CompareTo(pos1.GoalDifference); } // If necessary, goals scored will be sorted. if (result == 0) { result = pos2.GoalsScored.CompareTo(pos1.GoalsScored); } return(result); }
private static int CheckMatchResults(LeagueTable leagueTable, LeagueTablePosition pos1, LeagueTablePosition pos2, IMatchRepository matchRepository) { int result = 0; var team1 = pos1.TeamId; var team2 = pos2.TeamId; var matches = matchRepository.GetMatchesBetweenTeams(leagueTable.SeasonCompetition, team1, team2).ToList(); if (matches.Any()) { int team1GoalDiff = 0; int team2GoalDiff = 0; foreach (var match in matches) { if (match.HomeTeamId == team1) { team1GoalDiff += match.HomeScore - match.AwayScore; team2GoalDiff += match.AwayScore - match.HomeScore; } else { team1GoalDiff += match.AwayScore - match.HomeScore; team2GoalDiff += match.HomeScore - match.AwayScore; } } result = team2GoalDiff.CompareTo(team1GoalDiff); } return(result); }