Exemplo n.º 1
0
 public IEnumerable <Round> GetBySeasonCompetition(SeasonCompetition seasonCompetition)
 {
     using (var roundRepository = RepositoryFactory.CreateRoundRepository())
     {
         return(roundRepository.GetBySeasonCompetition(seasonCompetition.Id));
     }
 }
Exemplo n.º 2
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 matchDate = matchDateManager.GetNextMatchDate(CompetitionType.NationalSuperCup, roundNr);

                var superCupRound = RoundFactory.CreateRound("Final", superCupSeasonCompetition, matchDate, roundNr, superCupCompetition);
                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          = matchDate;
                match.DrawPermitted = false;
                match.CompetitionId = superCupCompetition.Id;
                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.º 3
0
        public CompetitionSchedule CreateDuringSeasonFriendlyRounds(SeasonCompetition seasonCompetition, List <DateTime> matchDates, int startIndex)
        {
            // The during season friendly schedule only consists of rounds. The matches in the rounds are determined during the season.
            var competitionSchedule = new CompetitionSchedule();

            foreach (var matchDate in matchDates)
            {
                var friendlyRound = RoundFactory.CreateRound(null, seasonCompetition, matchDate, startIndex, _competition);

                competitionSchedule.Rounds.Add(friendlyRound);
                startIndex++;
            }

            return(competitionSchedule);
        }
Exemplo n.º 4
0
        public IEnumerable <Match> GetMatchesBetweenTeams(SeasonCompetition seasonCompetition, string team1Id, string team2Id)
        {
            var matches = Find(m =>
                               m.SeasonId == seasonCompetition.SeasonId &&
                               m.CompetitionId == seasonCompetition.CompetitionId &&
                               (m.HomeTeamId == team1Id && m.AwayTeamId == team2Id ||
                                m.HomeTeamId == team2Id && m.AwayTeamId == team1Id));

            var matchesBetweenTeams = matches.ToList();

            foreach (var match in matchesBetweenTeams)
            {
                GetReferencedData(match);
            }

            return(matchesBetweenTeams);
        }
Exemplo n.º 5
0
        public CompetitionSchedule CreatePreSeasonSchedule(List <Team> teams, Season season, MatchDateManager matchDateManager)
        {
            var competitionSchedule = new CompetitionSchedule();

            // Create a friendly season competition for all friendlies in the season.
            SeasonCompetition friendlySeasonCompetition = new SeasonCompetition
            {
                Competition = _competition,
                Season      = season
            };

            competitionSchedule.SeasonCompetitions.Add(friendlySeasonCompetition);

            var roundsAndMatches = CreatePreSeasonRoundsAndMatches(teams);

            foreach (var round in roundsAndMatches)
            {
                var matchDate = matchDateManager.GetNextMatchDate(CompetitionType.Friendly, round.Key);

                var friendlyRound = RoundFactory.CreateRound(null, friendlySeasonCompetition, matchDate, round.Key, _competition);
                competitionSchedule.Rounds.Add(friendlyRound);

                foreach (var match in round.Value)
                {
                    match.Season        = season;
                    match.Round         = friendlyRound;
                    match.Date          = matchDate;
                    match.CompetitionId = _competition.Id;
                    competitionSchedule.Matches.Add(match);
                }
            }

            // Add the teams to the pre-season friendly competition of this season.
            foreach (var team in teams)
            {
                var seasonCompetitionTeam = new SeasonCompetitionTeam
                {
                    SeasonCompetition = friendlySeasonCompetition,
                    Team = team
                };
                competitionSchedule.SeasonCompetitionTeams.Add(seasonCompetitionTeam);
            }

            return(competitionSchedule);
        }
Exemplo n.º 6
0
        public static Round CreateRound(string name, SeasonCompetition seasonCompetition, DateTime matchDate, int order, Competition competition)
        {
            AssertNotNull(seasonCompetition, nameof(seasonCompetition));
            AssertNotNull(seasonCompetition.Season, nameof(seasonCompetition.Season));
            AssertNotNull(matchDate, nameof(matchDate));
            AssertNotNull(competition, nameof(competition));

            var round = new Round
            {
                Name = name,
                SeasonCompetition = seasonCompetition,
                Season            = seasonCompetition.Season,
                Order             = order,
                CompetitionId     = competition.Id,
                CompetitionName   = competition.Name,
                CompetitionType   = competition.CompetitionType,
                MatchDate         = matchDate
            };

            return(round);
        }
Exemplo n.º 7
0
        public CompetitionSchedule CreateSchedule(List <Team> teams, Season season, MatchDateManager matchDateManager)
        {
            var competitionSchedule = new CompetitionSchedule();

            // Create a cup season competition.
            SeasonCompetition cupSeasonCompetition = new SeasonCompetition
            {
                Competition = _competition,
                Season      = season
            };

            competitionSchedule.SeasonCompetitions.Add(cupSeasonCompetition);

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

            int numberOfRounds = DetermineNumberOfRounds(teams.Count);

            var firstScheduleItem = cupSchedule.First();
            var matchDate         = matchDateManager.GetNextMatchDate(CompetitionType.NationalCup, firstScheduleItem.Key);

            // Create the first round and its matches.
            int roundIndex = 0;
            var firstRound = RoundFactory.CreateRound(GetCupRoundName(numberOfRounds, roundIndex), cupSeasonCompetition, matchDate, roundIndex, _competition);

            foreach (var match in firstScheduleItem.Value)
            {
                match.Season        = season;
                match.Round         = firstRound;
                match.Date          = matchDate;
                match.DrawPermitted = false;
                match.CompetitionId = _competition.Id;
                competitionSchedule.Matches.Add(match);
            }

            competitionSchedule.Rounds.Add(firstRound);

            // Create remaining rounds for the tournament, these rounds do not have matches yet.
            // The date on which the matches on these rounds will be played are stored in the round.
            int numberOfRoundsLeft = numberOfRounds - 1;

            if (numberOfRoundsLeft > 0)
            {
                for (int i = 0; i < numberOfRoundsLeft; i++)
                {
                    roundIndex++;

                    matchDate = matchDateManager.GetNextMatchDate(CompetitionType.NationalCup, roundIndex);
                    var round = RoundFactory.CreateRound(GetCupRoundName(numberOfRounds, roundIndex), cupSeasonCompetition, matchDate, roundIndex, _competition);
                    competitionSchedule.Rounds.Add(round);
                }
            }

            // 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.º 8
0
        private void CreateLeague(CompetitionSchedule competitionSchedule, Competition leagueCompetition, List <Team> teams, Season season, MatchDateManager matchDateManager)
        {
            // Create a competition for the League and save it to the database.
            var leagueSeasonCompetition = new SeasonCompetition
            {
                Competition = leagueCompetition,
                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 = leagueCompetition;
            }

            // Create a match schedule.
            var roundRobinTournamentManager = new RoundRobinTournamentManager();
            var matchSchedule = roundRobinTournamentManager.GetSchedule(teams);

            foreach (var round in matchSchedule)
            {
                var matchDate   = matchDateManager.GetNextMatchDate(CompetitionType.League, round.Key);
                var leagueRound = RoundFactory.CreateRound($"Round {round.Key + 1}", leagueSeasonCompetition, matchDate, round.Key, leagueCompetition);
                competitionSchedule.Rounds.Add(leagueRound);

                foreach (var match in round.Value)
                {
                    match.Season        = season;
                    match.Round         = leagueRound;
                    match.Date          = matchDate;
                    match.CompetitionId = leagueCompetition.Id;
                    competitionSchedule.Matches.Add(match);
                }
            }

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

            leagueTable.LeagueTablePositions = new List <LeagueTablePosition>();
            int position = 1;

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

            competitionSchedule.LeagueTables.Add(leagueTable);
        }