コード例 #1
0
        public async Task <bool> UpdateSportTypeAsync(SportTypeViewModel sportTypeToUpdate, CancellationToken ct = default(CancellationToken))
        {
            SportType sportType = await _sportTypeRepository.GetByIdAsync(sportTypeToUpdate.Id, ct);

            if (sportType == null)
            {
                return(false);
            }

            sportType.Name   = sportTypeToUpdate.Name;
            sportType.Active = sportTypeToUpdate.Active;

            // if sport type successfully updated, update all of its leagues
            if (await this._sportTypeRepository.UpdateAsync(sportType, ct))
            {
                // when the sport type name changes we also need to update all of the associated leagues type property
                // since the type property on the league represents the name of the sport
                List <LeagueViewModel> leagues = await GetLeaguesBySportTypeIdAsync(sportType.Id);

                List <LeagueViewModel> updatedLeagues = new List <LeagueViewModel>();

                foreach (LeagueViewModel league in leagues)
                {
                    league.Type = sportTypeToUpdate.Name;
                    updatedLeagues.Add(league);
                }

                return(await UpdateLeaguesAsync(updatedLeagues, ct));
            }

            // if updating sport type failed
            return(false);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public async Task <ActionResult <SportTypeViewModel> > Update([FromBody] SportTypeViewModel updatedSportType, CancellationToken ct = default(CancellationToken))
        {
            if (!await this._supervisor.UpdateSportTypeAsync(updatedSportType, ct))
            {
                return(BadRequest(Errors.AddErrorToModelState(ErrorCodes.SportTypeUpdate, ErrorDescriptions.SportTypeUpdateFailure, ModelState)));
            }

            updatedSportType = await this._supervisor.GetSportTypeByIdAsync(updatedSportType.Id, ct);

            return(new JsonResult(updatedSportType));
        }
コード例 #4
0
        public async Task <ActionResult <SportTypeViewModel> > Create([FromBody] SportTypeViewModel newSportType, CancellationToken ct = default(CancellationToken))
        {
            newSportType = await this._supervisor.AddSportTypeAsync(newSportType, ct);

            if (newSportType == null)
            {
                return(BadRequest(Errors.AddErrorToModelState(ErrorCodes.SportTypeAdd, ErrorDescriptions.SportTypeAddFailure, ModelState)));
            }

            return(new JsonResult(newSportType));
        }
コード例 #5
0
        public static SportTypeViewModel Convert(SportType sportType)
        {
            SportTypeViewModel model = new SportTypeViewModel();

            model.Id      = sportType.Id;
            model.Leagues = sportType.Leagues == null ? null : LeagueConverter.ConvertList(sportType.Leagues);
            model.Name    = sportType.Name;
            model.Active  = sportType.Active;

            return(model);
        }
コード例 #6
0
        public async Task <SportTypeViewModel> AddSportTypeAsync(SportTypeViewModel newSportType, CancellationToken ct = default(CancellationToken))
        {
            SportType sportType = new SportType();

            sportType.Name = newSportType.Name;
            sportType      = await _sportTypeRepository.AddAsync(sportType, ct);

            newSportType.Id = sportType.Id;

            return(newSportType);
        }
コード例 #7
0
        public async Task <bool> DeleteSportTypeAsync(string id, CancellationToken ct = default(CancellationToken))
        {
            SportTypeViewModel sportTypeToDelete = SportTypeConverter.Convert(await this._sportTypeRepository.GetByIdAsync(id, ct));

            if (sportTypeToDelete == null)
            {
                return(false);
            }

            sportTypeToDelete.Active = false;
            return(await UpdateSportTypeAsync(sportTypeToDelete, ct));
        }
コード例 #8
0
        public static List <SportTypeViewModel> ConvertList(IEnumerable <SportType> sportTypes)
        {
            return(sportTypes.Select(sportType =>
            {
                SportTypeViewModel model = new SportTypeViewModel();
                model.Id = sportType.Id;
                model.Leagues = sportType.Leagues == null ? null : LeagueConverter.ConvertList(sportType.Leagues);
                model.Name = sportType.Name;
                model.Active = sportType.Active;

                return model;
            }).ToList());
        }
コード例 #9
0
        public async Task <SportTypeViewModel> GetSportTypeByIdAsync(string id, CancellationToken ct = default(CancellationToken))
        {
            SportTypeViewModel sportType = SportTypeConverter.Convert(await this._sportTypeRepository.GetByIdAsync(id, ct));

            return(sportType);
        }