public async Task <List <LeagueSessionScheduleViewModel> > GetAllActiveSessionsAsync(CancellationToken ct = default(CancellationToken))
        {
            // this will ensure that whenever we retrieve sessions we always check to see they are active or not
            // await this.UpdateActiveSessionsAsync();

            List <LeagueSessionScheduleViewModel> activeSessions = LeagueSessionScheduleConverter.ConvertList(await this._sessionScheduleRepository.GetAllActiveSessionsAsync(ct));
            HashSet <TeamViewModel> teams = new HashSet <TeamViewModel>();

            // for each session loop through all matches and include the team. EF is not returning teams for some reason. HomeTeam or AwayTeam
            foreach (LeagueSessionScheduleViewModel session in activeSessions)
            {
                foreach (MatchViewModel match in session.Matches)
                {
                    TeamViewModel awayTeam = null;
                    TeamViewModel homeTeam = null;

                    // if the match has a bye, AwayTeamId won't be set
                    if (match.AwayTeamId != null)
                    {
                        awayTeam = await this.GetTeamByIdAsync(match.AwayTeamId, ct);
                    }
                    // if the match has a bye, HomeTeamId won't be set
                    if (match.HomeTeamId != null)
                    {
                        homeTeam = await this.GetTeamByIdAsync(match.HomeTeamId, ct);
                    }

                    match.AwayTeamName          = awayTeam?.Name ?? "BYE";
                    match.HomeTeamName          = homeTeam?.Name ?? "BYE";
                    match.MatchResult.SessionId = session.Id;

                    // stash retrieved teams so we don't have to hit the database again to retrieve team names
                    teams.Add(awayTeam);
                    teams.Add(homeTeam);
                }

                // teamSession.teamName is used by the front end scoreboard to avoid having dependency on sport types store. Before
                // /scoreboards route expected sport types store to have values, but if user navigates straight to scoreboards then
                // we cannot display a filter to allow user to filter by team name easily
                foreach (TeamSessionViewModel teamSession in session.TeamsSessions)
                {
                    teamSession.TeamName = teams.Where(t => t?.Id == teamSession.TeamId).FirstOrDefault()?.Name;
                }

                LeagueViewModel league = await GetLeagueByIdAsync(session.LeagueID, ct);

                // these properties are not set by converters because they do not belong on the model
                session.LeagueName = league?.Name;

                SportTypeViewModel sportType = await GetSportTypeByIdAsync(league.SportTypeID, ct);

                // these properties are not set by converters because they do not belong on the model
                session.SportTypeID   = sportType?.Id;
                session.SportTypeName = sportType?.Name;
            }

            return(activeSessions);
        }
        public async Task <List <ActiveSessionInfoViewModel> > GetActiveSessionsInfoAsync(List <string> leagueIDs, CancellationToken ct = default(CancellationToken))
        {
            //await this.UpdateActiveSessionsAsync(leagueIDs);

            List <LeagueSessionScheduleViewModel> activeSessions             = LeagueSessionScheduleConverter.ConvertList(await this._sessionScheduleRepository.GetAllActiveSessionsAsync(ct)); // use GetAllSessions and filter the list
            List <ActiveSessionInfoViewModel>     filteredActiveSessionsInfo = activeSessions.Where(s => s.Active == true && leagueIDs.Any(leagueID => s.LeagueID == leagueID)).Select(session => new ActiveSessionInfoViewModel
            {
                SessionId = session.Id,
                LeagueId  = session.LeagueID,
                StartDate = session.SessionStart,
                EndDate   = session.SessionEnd
            }).ToList();

            return(filteredActiveSessionsInfo);
        }
        public async Task <List <LeagueSessionScheduleViewModel> > GetAllSessionsByLeagueIdAsync(string leagueId, CancellationToken ct = default)
        {
            List <LeagueSessionScheduleViewModel> leagueSessions = LeagueSessionScheduleConverter.ConvertList(await this._sessionScheduleRepository.GetAllSessionsByLeagueIdAsync(leagueId, ct));

            return(leagueSessions);
        }