Exemplo n.º 1
0
        public CompetitionSchedule CreateSchedule(Team team1, Team team2, Season season, MatchDateManager matchDateManager)
        {
            var competitionSchedule = new CompetitionSchedule();

             using (var competitionRepository = new RepositoryFactory().CreateCompetitionRepository())
             {
            // Create a super cup season competition and round and save it to the database.
            var superCupCompetition = competitionRepository.GetNationalSuperCup();
            var superCupSeasonCompetition = new SeasonCompetition
            {
               Competition = superCupCompetition,
               Season = season
            };
            competitionSchedule.SeasonCompetitions.Add(superCupSeasonCompetition);

            const int roundNr = 0;
            var superCupRound = new Round
            {
               Id = IdGenerator.GetId(),
               Name = "Super Cup Final",
               SeasonCompetition = superCupSeasonCompetition,
               Order = roundNr,
               CompetitionName = "Super Cup",
               CompetitionType = CompetitionType.NationalSuperCup
            };
            competitionSchedule.Rounds.Add(superCupRound);

            // Create the super cup match and save it to the database.
            var teams1 = new List<Team> { team1 };
            var teams2 = new List<Team> { team2 };
            var singleRoundTournamentManager = new SingleRoundTournamentManager();
            var match = singleRoundTournamentManager.GetMatches(teams1, teams2).Single();

            match.Season = season;
            match.Round = superCupRound;
            match.Date = matchDateManager.GetNextMatchDate(CompetitionType.NationalSuperCup, roundNr);
            match.DrawPermitted = false;

            competitionSchedule.Matches.Add(match);

            // Add both teams to the super cup competition of this season.
            var seasonCompetitionTeam1 = new SeasonCompetitionTeam
            {
               Team = team1,
               SeasonCompetition = superCupSeasonCompetition
            };
            var seasonCompetitionTeam2 = new SeasonCompetitionTeam
            {
               Team = team2,
               SeasonCompetition = superCupSeasonCompetition
            };
            competitionSchedule.SeasonCompetitionTeams.Add(seasonCompetitionTeam1);
            competitionSchedule.SeasonCompetitionTeams.Add(seasonCompetitionTeam2);
             }

             return competitionSchedule;
        }
Exemplo n.º 2
0
        public CompetitionSchedule CreateSchedules(List<Team> teamsLeague1, List<Team> teamsLeague2, List<Team> teamsLeague3, List<Team> teamsLeague4, Season season, MatchDateManager matchDateManager)
        {
            var competitionSchedule = new CompetitionSchedule();

             using (var competitionRepository = new RepositoryFactory().CreateCompetitionRepository())
             {
            // Create the leagues with the teams.
            CreateLeague(competitionSchedule, competitionRepository.GetLeague1(), teamsLeague1, season, matchDateManager);
            CreateLeague(competitionSchedule, competitionRepository.GetLeague2(), teamsLeague2, season, matchDateManager);
            CreateLeague(competitionSchedule, competitionRepository.GetLeague3(), teamsLeague3, season, matchDateManager);
            CreateLeague(competitionSchedule, competitionRepository.GetLeague4(), teamsLeague4, season, matchDateManager);
             }

             return competitionSchedule;
        }
Exemplo n.º 3
0
        public CompetitionSchedule CreateSchedule(List<Team> teams, Season season, MatchDateManager matchDateManager)
        {
            //Draws the first round.
             //Gets the schedule for all rounds, where only the first round has a HomeTeam and AwayTeam.
             //Determines match dates with the DateMatchManager.
             //Creates SeasonCompetition, Rounds etc.

             var competitionSchedule = new CompetitionSchedule();

             // Create a cup season competition.
             SeasonCompetition cupSeasonCompetition;

             using (var competitionRepository = new RepositoryFactory().CreateCompetitionRepository())
             {
            var cup = competitionRepository.GetNationalCup();
            cupSeasonCompetition = new SeasonCompetition
            {
               Competition = cup,
               Season = season
            };
             }

             competitionSchedule.SeasonCompetitions.Add(cupSeasonCompetition);

             var cupSchedule = new KnockoutTournamentManager().GetSchedule(teams);

             foreach (var round in cupSchedule)
             {
            var cupRound = new Round
            {
               Id = IdGenerator.GetId(),
               Name = GetCupRoundName(cupSchedule.Count, round.Key),
               SeasonCompetition = cupSeasonCompetition,
               Order = round.Key,
               CompetitionName = "Cup",
               CompetitionType = CompetitionType.NationalCup
            };
            competitionSchedule.Rounds.Add(cupRound);

            foreach (var match in round.Value)
            {
               match.Season = season;
               match.Round = cupRound;
               match.Date = matchDateManager.GetNextMatchDate(CompetitionType.NationalCup, round.Key);
               match.DrawPermitted = false;

               competitionSchedule.Matches.Add(match);
            }
             }

             // Add the teams to the cup of this season.
             foreach (var team in teams)
             {
            var seasonCompetitionTeam = new SeasonCompetitionTeam
            {
               SeasonCompetition = cupSeasonCompetition,
               Team = team
            };
            competitionSchedule.SeasonCompetitionTeams.Add(seasonCompetitionTeam);
             }

             return competitionSchedule;
        }
Exemplo n.º 4
0
        private void CreateLeague(CompetitionSchedule competitionSchedule, Competition league, List<Team> teams, Season season, MatchDateManager matchDateManager)
        {
            // Create a competition for the League and save it to the database.
             var leagueSeasonCompetition = new SeasonCompetition
             {
            Competition = league,
            Season = season
             };

             competitionSchedule.SeasonCompetitions.Add(leagueSeasonCompetition);

             // Add the teams to the league.
             foreach (var team in teams)
             {
            var seasonCompetitionTeam = new SeasonCompetitionTeam
            {
               SeasonCompetition = leagueSeasonCompetition,
               Team = team
            };
            competitionSchedule.SeasonCompetitionTeams.Add(seasonCompetitionTeam);

            // Update current league for the team.
            team.CurrentLeagueCompetition = league;
             }

             // Create a match schedule.
             var roundRobinTournamentManager = new RoundRobinTournamentManager();
             var matchSchedule = roundRobinTournamentManager.GetSchedule(teams);
             foreach (var round in matchSchedule)
             {
            var leagueRound = new Round
            {
               Id = IdGenerator.GetId(),
               Name = $"{league.Name} round {round.Key + 1}",
               SeasonCompetition = leagueSeasonCompetition,
               Order = round.Key,
               CompetitionName = league.Name,
               CompetitionType = CompetitionType.League
            };

            competitionSchedule.Rounds.Add(leagueRound);

            foreach (var match in round.Value)
            {
               match.Season = season;
               match.Round = leagueRound;
               match.Date = matchDateManager.GetNextMatchDate(CompetitionType.League, round.Key);
               competitionSchedule.Matches.Add(match);
            }
             }

             // Create a league table.
             var leagueTable = new LeagueTable
             {
            CompetitionName = league.Name,
            SeasonCompetition = leagueSeasonCompetition,
            Game = season.Game
             };

             leagueTable.LeagueTablePositions = new List<LeagueTablePosition>();
             foreach (var team in teams)
             {
            leagueTable.LeagueTablePositions.Add(new LeagueTablePosition { Team = team, LeagueTable = leagueTable, Position = team.CurrentLeaguePosition });
             }

             competitionSchedule.LeagueTables.Add(leagueTable);
        }
Exemplo n.º 5
0
        private void SaveCompetitionSchedule(CompetitionSchedule competitionSchedule, IUnitOfWorkRepository repository)
        {
            repository.RegisterInsert(competitionSchedule.LeagueTables);
             foreach (var leagueTable in competitionSchedule.LeagueTables)
             {
            repository.RegisterInsert(leagueTable.LeagueTablePositions);
             }

             repository.RegisterInsert(competitionSchedule.SeasonCompetitions);

             repository.RegisterInsert(competitionSchedule.SeasonCompetitionTeams);

             repository.RegisterInsert(competitionSchedule.Rounds);

             repository.RegisterInsert(competitionSchedule.Matches);
        }