public void SaveTeamChampionshipRatings(int championshipId, List <TeamChampionshipScore> teamScores) { foreach (TeamChampionshipScore teamChampionshipScore in teamScores) { TeamChampionshipScore tcs = _dbContext.Set <TeamChampionshipScore>().Find(championshipId, teamChampionshipScore.TeamId); tcs.Rating = teamChampionshipScore.Rating; } _dbContext.SaveChanges(); }
private static int TeamRatingComparator(TeamChampionshipScore tcs1, TeamChampionshipScore tcs2) { if (tcs1.Score is null || tcs2.Score is null) { throw new Exception("Cannot calculate ratings! One or more teams do not have scores set!"); } int score1 = tcs1.Score ?? default; int score2 = tcs2.Score ?? default; if (score1 == score2) { string name1 = tcs1.Team.Name; string name2 = tcs2.Team.Name; return(string.Compare(name1, name2, StringComparison.OrdinalIgnoreCase)); } else { return(score2 - score1); } }
public TeamChampionshipScore CreateTeamChampionshipResult(int championshipId, int teamId, int score) { TeamChampionshipScore entry = _dbContext.Set <TeamChampionshipScore>().Find(championshipId, teamId); if (entry is null) { entry = new TeamChampionshipScore { ChampionshipId = championshipId, TeamId = teamId, Score = score }; _dbContext.Add(entry); } else { entry.Score = score; } _dbContext.SaveChanges(); return(entry); }