示例#1
0
        private SeasonAndCompetitionSchedules CreateSeasonAndCompetitionSchedules(NewSeasonInfo newSeasonInfo)
        {
            var matchDateManager = new MatchDateManager(newSeasonInfo.StartYear);

            matchDateManager.Initialize();

            // The season officially ends a day after the last match so there is a possibility to add events between the last match and the end of the season.
            var endSeasonDateTime = matchDateManager.GetAllMatchDates().OrderBy(d => d).Last().AddDays(1);

            var season = new Season
            {
                StartYear    = newSeasonInfo.StartYear,
                SeasonStatus = SeasonStatus.Started,
                EndDateTime  = endSeasonDateTime
            };

            var seasonAndCompetitionSchedules = new SeasonAndCompetitionSchedules {
                Season = season
            };

            // Create leagues and schedule.
            var leagueManager = new LeagueManager();

            seasonAndCompetitionSchedules.LeaguesSchedule = leagueManager.CreateSchedules(newSeasonInfo.TeamsLeague1, newSeasonInfo.TeamsLeague2, newSeasonInfo.TeamsLeague3, newSeasonInfo.TeamsLeague4, season, matchDateManager);

            // Create a national cup tournament.
            var nationalCupManager = new NationalCupManager(_repositoryFactory);

            seasonAndCompetitionSchedules.NationalCupSchedule = nationalCupManager.CreateSchedule(newSeasonInfo.AllTeams.ToList(), season, matchDateManager);

            // Create pre-season friendlies.
            var preSeasonFriendlyManager = new PreSeasonFriendlyManager();

            seasonAndCompetitionSchedules.PreSeasonFriendliesSchedule = preSeasonFriendlyManager.CreatePreSeasonSchedule(newSeasonInfo.AllTeams.ToList(), season, matchDateManager);

            // Create friendlies during the season.
            // Determine on which dates these friendlies can be played. For now, this is only during the national cup tournament, except the first round and the final.
            var cupDates = seasonAndCompetitionSchedules.NationalCupSchedule.Rounds.Select(r => r.MatchDate).Skip(1).Take(seasonAndCompetitionSchedules.NationalCupSchedule.Rounds.Count - 2).ToList();
            var friendlyRoundsManager = new DuringSeasonFriendlyRoundsManager();

            seasonAndCompetitionSchedules.DuringSeasonFriendliesSchedule = friendlyRoundsManager.CreateDuringSeasonFriendlyRounds(seasonAndCompetitionSchedules.PreSeasonFriendliesSchedule.SeasonCompetitions.First(), cupDates, Constants.HowManyPreSeasonFriendlies + 1);

            // Create Super Cup.
            var nationalSuperCupManager = new NationalSuperCupManager();
            // The home team is always the national champion and the away team is either the cup winner or the league 1 runner up if the champion also won the cup.
            var homeTeam = newSeasonInfo.PreviousSeasonStatistics.NationalChampion;
            var awayTeam = newSeasonInfo.PreviousSeasonStatistics.NationalChampion.Equals(newSeasonInfo.PreviousSeasonStatistics.CupWinner) ? newSeasonInfo.PreviousSeasonStatistics.NationalChampionRunnerUp : newSeasonInfo.PreviousSeasonStatistics.CupWinner;

            seasonAndCompetitionSchedules.NationalSuperCupSchedule = nationalSuperCupManager.CreateSchedule(homeTeam, awayTeam, season, matchDateManager);

            // In the meantime 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);
        }
示例#2
0
        private void InsertGameDateTimes(TransactionManager transactionManager, SeasonAndCompetitionSchedules schedules)
        {
            // Determine the match dates the manager's team plays.
            var managersMatchDates = schedules.AllMatches.Where(m => m.TeamPlaysMatch(_managersTeam)).Select(m => m.Date);

            // Determine when the manager's team does not play: all dates in the season except the ones that were just determined.
            var otherTeamsMatchDates = schedules.AllMatchDates.Except(managersMatchDates);

            var gameDateTimeNanager = new GameDateTimeMutationManager(transactionManager, _repositoryFactory);

            gameDateTimeNanager.CreateNewForSeason(managersMatchDates, otherTeamsMatchDates, schedules.Season.EndDateTime);
        }
示例#3
0
        private void InsertSeasonAndCompetitionSchedule(TransactionManager transactionManager, SeasonAndCompetitionSchedules seasonAndCompetitionSchedules)
        {
            // Insert the season.
            transactionManager.RegisterInsert(seasonAndCompetitionSchedules.Season);

            // Insert league schedules.
            SaveCompetitionSchedule(seasonAndCompetitionSchedules.LeaguesSchedule, transactionManager);

            // Insert cup schedule.
            SaveCompetitionSchedule(seasonAndCompetitionSchedules.NationalCupSchedule, transactionManager);

            // Insert super cup schedule.
            SaveCompetitionSchedule(seasonAndCompetitionSchedules.NationalSuperCupSchedule, transactionManager);

            // Insert pre-season friendly schedule.
            SaveCompetitionSchedule(seasonAndCompetitionSchedules.PreSeasonFriendliesSchedule, transactionManager);

            // Insert during season friendlies.
            SaveCompetitionSchedule(seasonAndCompetitionSchedules.DuringSeasonFriendliesSchedule, transactionManager);

            // Update the teams.
            transactionManager.RegisterUpdate(seasonAndCompetitionSchedules.Teams);
        }
示例#4
0
        private void InsertSeasonRelatedStatistics(TransactionManager transactionManager, IEnumerable <Team> teams, SeasonAndCompetitionSchedules seasonAndCompetitionSchedules)
        {
            string league1LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[0].Id;
            string league2LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[1].Id;
            string league3LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[2].Id;
            string league4LeagueTableId = seasonAndCompetitionSchedules.LeaguesSchedule.LeagueTables[3].Id;

            // SeasonStatistics.
            var seasonStatistics = new SeasonStatistics(seasonAndCompetitionSchedules.Season, league1LeagueTableId, league2LeagueTableId, league3LeagueTableId, league4LeagueTableId);

            transactionManager.RegisterInsert(seasonStatistics);

            // SeasonTeamStatistics.
            foreach (var team in teams)
            {
                var seasonTeamStatistic = new SeasonTeamStatistics(seasonAndCompetitionSchedules.Season, team, team.CurrentLeagueCompetition.Name);
                transactionManager.RegisterInsert(seasonTeamStatistic);
            }
        }