public SeasonPage(int seasonId) { InitializeComponent(); this.seasonId = seasonId; thisSeason = new Season(seasonId); List <Race> seasonRaces = new List <Race>(); seasonRaces = DatabaseManager.Instance.SeasonRepository.GetRacesFromSeason(seasonId); seasonRaceNumber = seasonRaces.Count(); DatabaseManager.Instance.SeasonRepository.CreateNewSeason(seasonId); thisSeason.CalculateTable(seasonRaces, seasonParticipants); seasonTracks = DatabaseManager.Instance.RaceTrackRepository.GetAllRaceTracks().ToList(); listOfDrivers = DatabaseManager.Instance.DriverRepository.GetAllDrivers().ToList(); dgTable.ItemsSource = seasonParticipants.OrderByDescending(x => x.Points).ToList();; if (seasonRaceNumber >= seasonTracks.Count()) { lblNextRace.Content = "Season finished"; btnNextRace.IsEnabled = false; btnNextSeason.Visibility = Visibility.Visible; } else { lblNextRace.Content = "Next race: " + seasonTracks[seasonRaceNumber].Name; } }