Exemple #1
0
        public void Post(CreateTeamsAndMatchesRequest request)
        {
            using (var transaction = this.Db.OpenTransaction(IsolationLevel.ReadCommitted))
            {
                long competitionId = request.CompetitionId;

                var teamInscriptions = this.Db.Select(Db.From <TeamInscription>().Where(p => p.CompetitionId == competitionId && p.AssignedLeagueId != null));
                var teams            = teamInscriptions.CreateTeams();

                teams.ForEach(team => team.Id = (int)this.Db.Insert(team, true));

                var matches = MatchFactory.CreateLeagueMatches(teams, leagueId => Db.SingleById <League>(leagueId).LeagueMatchCreationMode).ToList();

                this.Db.InsertAll(matches);

                var leagueIds = matches.Select(s => s.LeagueId).Distinct().ToList();
                leagueIds.ForEach(leagueId => StandingsCalculator.Calculate(this.Db, leagueId));

                transaction.Commit();
            }
        }