public GetTeamsResponse GetTeams(int id) { Dictionary <string, float> teamScores = new Dictionary <string, float>(); var championship_Teams = _context.Championship_Teams .Where(c => c.IdChampionship == id) .OrderBy(c => c.Score) .ToList(); if (championship_Teams == null) { throw new NotFoundChampionShipException("Nie znaleziono zawodow"); } foreach (var c in championship_Teams) { var teamName = _context.Teams.SingleOrDefault(t => t.IdTeam == c.IdTeam).TeamName; teamScores.Add(teamName, c.Score); } GetTeamsResponse response = new GetTeamsResponse { IdChampionship = id, Score = teamScores }; return(response); }
public GetTeamsResponse Get() { try { var response = new GetTeamsResponse { Code = _responseSettings.Value.SuccessfulResponseCode, Message = _responseSettings.Value.SuccessfulResponseMessage, }; response.Teams = _teamDataManager.Get().Select(x => new Team { Id = x.Id, Name = x.Name, Suburb = x.Suburb, City = x.City, Province = x.Province, StadiumName = x.Stadium?.Name, TotalPlayers = x.Players.Count, CreatedDate = x.CreatedDate }).ToArray(); return(response); } catch (Exception exception) { return(new GetTeamsResponse { Code = _responseSettings.Value.ErrorOccuredCode, Message = _responseSettings.Value.ErrorOccuredMessage, }); } }
public async Task GetTeams_WhenDataStoreIsUnavailable_ReturnsDataStoreUnavailableResponse() { statsDownloadApiDataStoreServiceMock.IsAvailable().Returns(false); GetTeamsResponse actual = await InvokeGetTeams(); Assert.That(actual.Success, Is.False); Assert.That(actual.Errors?.Count, Is.EqualTo(1)); Assert.That(actual.Errors?[0].ErrorCode, Is.EqualTo(ApiErrorCode.DataStoreUnavailable)); Assert.That(actual.Errors?[0].ErrorMessage, Is.EqualTo(Constants.ErrorMessages.DataStoreUnavailableMessage)); }
public async Task GetTeams_WhenDatabaseMissingRequiredObjects_ReturnsDatabaseMissingRequiredObjectsResponse() { statsDownloadApiDatabaseServiceMock .IsAvailable().Returns((false, DatabaseFailedReason.DatabaseMissingRequiredObjects)); GetTeamsResponse actual = await InvokeGetTeams(); Assert.That(actual.Success, Is.False); Assert.That(actual.Errors?.Count, Is.EqualTo(1)); Assert.That(actual.Errors?[0].ErrorCode, Is.EqualTo(ApiErrorCode.DatabaseMissingRequiredObjects)); Assert.That(actual.Errors?[0].ErrorMessage, Is.EqualTo(Constants.ErrorMessages.DatabaseMissingRequiredObjectsMessage)); }
public async Task GetTeams_WhenInvoked_ReturnsSuccessGetTeamsResponse() { var teams = new[] { new Team(0, ""), new Team(0, "") }; statsDownloadApiDataStoreServiceMock.GetTeams().Returns(teams); GetTeamsResponse actual = await InvokeGetTeams(); Assert.That(actual.Success, Is.True); Assert.That(actual.Errors, Is.Null); Assert.That(actual.ErrorCount, Is.Null); Assert.That(actual.FirstErrorCode, Is.EqualTo(ApiErrorCode.None)); Assert.That(actual.Teams, Is.EqualTo(teams)); Assert.That(actual.TeamCount, Is.EqualTo(2)); }
public async Task <ActionResult <GetTeamsResponse> > GetTeam([FromRoute] int teamId, CancellationToken cancellationToken) { var response = new GetTeamsResponse { Team = _mapper.Map <TeamDto>(await _teamsRepository.GetByIdAsync(teamId, cancellationToken)) }; if (response.Team != null) { return(Ok(response)); } else { return(NotFound()); } }
public ActionResult <GetTeamsResponse> GetAllTeams() { var response = new GetTeamsResponse(); var teams = _context.Teams.ToList(); foreach (var team in teams) { response.Teams.Add(new TeamDTO() { Id = team.Id, Name = team.Name, Nickname = team.Nickname, Location = team.Location, StadiumId = team.StadiumId }); } return(Ok(response)); }
public async Task <GetTeamsResponse> GetTeams() { loggingService.LogMethodInvoked(); var errors = new List <ApiError>(); bool isNotPreparedToRun = await IsNotPreparedToGetTeams(errors); if (isNotPreparedToRun) { loggingService.LogMethodFinished(); return(new GetTeamsResponse(errors)); } IList <Team> teams = await statsDownloadApiDataStoreService.GetTeams(); var teamsResponse = new GetTeamsResponse(teams); loggingService.LogMethodFinished(); return(teamsResponse); }
public Task <List <TeamDTO> > GetTeamsAsync(CancellationTokenSource cancellationTokenSource) => Task <List <TeamDTO> > .Run(async() => { if (!CrossConnectivity.Current.IsConnected) { throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION); } List <TeamDTO> foundTeams = null; GetTeamsRequest getTeamsRequest = new GetTeamsRequest() { AccessToken = GlobalSettings.Instance.UserProfile.AccesToken, Url = GlobalSettings.Instance.Endpoints.TeamEndPoints.GetAllTeams }; try { GetTeamsResponse getTeamsResponse = await _requestProvider.GetAsync <GetTeamsRequest, GetTeamsResponse>(getTeamsRequest); if (getTeamsResponse != null) { foundTeams = (getTeamsResponse.Data != null) ? getTeamsResponse.Data.ToList() : new List <TeamDTO>(); } else { throw new InvalidOperationException(TeamService.GET_TEAMS_COMMON_ERROR_MESSAGE); } } catch (ServiceAuthenticationException exc) { _identityUtilService.RefreshToken(); throw exc; } catch (Exception exc) { Crashes.TrackError(exc); throw; } return(foundTeams); }, cancellationTokenSource.Token);