コード例 #1
0
        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();
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
        }