Exemplo n.º 1
0
        public IActionResult GetTeamPlayers(GetTrainingsInputDto input)
        {
            try
            {
                var teamPlayers = this.teamPlayerRepository.GetAll()
                                  .Where(tp => tp.SeasonID == input.SeasonId)
                                  .Where(tp => tp.TeamID == input.TeamId)
                                  .OrderBy(tp => tp.Player.LastName)
                                  .ThenBy(tp => tp.Player.FirstName)
                                  .Select(tp => new PlayerListDto
                {
                    PlayerId       = tp.PlayerID,
                    FirstName      = tp.Player.FirstName,
                    LastNamePrefix = tp.Player.LastNamePrefix,
                    LastName       = tp.Player.LastName
                })
                                  .ToList();

                return(this.Ok(new Result <List <PlayerListDto> >(teamPlayers)));
            }
            catch (Exception ex)
            {
                this.Logger.LogError($"Failed to retrieve team players for season '{input.SeasonId}' and team '{input.TeamId}'", ex);
                return(this.BadRequest(new Result <List <PlayerListDto> >($"Unable to retieve team players")));
            }
        }
Exemplo n.º 2
0
        public IActionResult GetTrainings(GetTrainingsInputDto input)
        {
            this.Logger.LogInformation($"Retrieve trainings for season '{input.SeasonId}' and team '{input.TeamId}'");
            try
            {
                var trainings = this.trainingRepository.GetAll()
                                .Where(t => t.SeasonID == input.SeasonId)
                                .Where(t => t.TeamID == input.TeamId)
                                .Where(t => t.IsBonus || !input.IncludeBonus)
                                .Select(t => new TrainingListDto
                {
                    Id           = t.Id,
                    Date         = t.TrainingDate,
                    IsBonus      = t.IsBonus,
                    NumAttendees = t.TrainingPlayers.Count
                })
                                .OrderBy(t => t.Date)
                                .ToList();

                return(this.Ok(new Result <List <TrainingListDto> >(trainings)));
            }
            catch (Exception ex)
            {
                this.Logger.LogError($"Failed to retrieve trainings for season '{input.SeasonId}' and team '{input.TeamId}'", ex);
                return(this.BadRequest(new Result <List <TrainingListDto> >($"Unable to retieve trainings")));
            }
        }