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); }
public SeasonManager(RepositoryFactory repositoryFactory, Team managersTeam) { _repositoryFactory = repositoryFactory; _managersTeam = managersTeam; _leagueManager = new LeagueManager(); }