Ejemplo n.º 1
0
        public static SeasonResource Create(Season season, SeasonLinks seasonLinks)
        {
            var seasonResource = new SeasonResource(seasonLinks)
             {
            Name = season.Name
             };

             return seasonResource;
        }
Ejemplo 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 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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
 public SeasonTeamStatistics(Season season, Team team)
 {
     Season = season;
      Team = team;
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
 public SeasonStatistics(Season season)
 {
     Season = season;
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private SeasonAndCompetitionSchedules CreateSeasonAndCompetitionSchedules(NewSeasonInfo newSeasonInfo)
        {
            var seasonAndCompetitionSchedules = new SeasonAndCompetitionSchedules();

             // Create a new season.
             string seasonName = $"Season {newSeasonInfo.SeasonNumber + 1}";
             var season = new Season
             {
            Name = seasonName,
            GameOrder = newSeasonInfo.SeasonNumber,
            Game = newSeasonInfo.Game,
            SeasonStatus = SeasonStatus.Started
             };

             seasonAndCompetitionSchedules.Season = season;

             var competitionManagerFactory = new CompetitionManagerFactory();
             var matchDateManager = new MatchDateManager(newSeasonInfo.SeasonNumber);
             matchDateManager.Initialize();

             // Create leagues and schedule.
             var leagueManager = competitionManagerFactory.CreateLeagueManager();
             seasonAndCompetitionSchedules.LeaguesSchedule = leagueManager.CreateSchedules(newSeasonInfo.TeamsLeague1, newSeasonInfo.TeamsLeague2, newSeasonInfo.TeamsLeague3, newSeasonInfo.TeamsLeague4, season, matchDateManager);

             // Create a national cup tournament.
             var nationalCupManager = competitionManagerFactory.CreateNationalCupManager();
             seasonAndCompetitionSchedules.NationalCupSchedule = nationalCupManager.CreateSchedule(newSeasonInfo.AllTeams.ToList(), season, matchDateManager);

             // Create friendlies and save it to the database.
             var friendlyManager = competitionManagerFactory.CreateFriendlyManager();
             seasonAndCompetitionSchedules.PreSeasonFriendliesSchedule = friendlyManager.CreatePreSeasonSchedule(
            newSeasonInfo.TeamsLeague1,
            newSeasonInfo.TeamsLeague2,
            newSeasonInfo.TeamsLeague3,
            newSeasonInfo.TeamsLeague4,
            4,
            season,
            matchDateManager);

             // Create Super Cup and save it to the database.
             var nationalSuperCupManager = competitionManagerFactory.CreateNationalSuperCupManager();
             seasonAndCompetitionSchedules.NationalSuperCupSchedule = nationalSuperCupManager.CreateSchedule(newSeasonInfo.NationalChampion, newSeasonInfo.NationalCupWinner, season, matchDateManager);

             // In the mean time data of the teams has changed, so add them to the SeasonAndCompetitionSchedules object so they can be updated in the database.
             seasonAndCompetitionSchedules.Teams = newSeasonInfo.AllTeams;

             return seasonAndCompetitionSchedules;
        }
Ejemplo n.º 9
0
        private SeasonResource GetSeasonResource(Season currentSeason, Team team)
        {
            var seasonLinks = new SeasonLinks(currentSeason.Id, team.CurrentLeagueCompetitionId, team.Id);
             var seasonResource = SeasonResourceFactory.Create(currentSeason, seasonLinks);

             return seasonResource;
        }