public async Task <ActionResult> GetTeamInfo(string teamCode) { if (string.IsNullOrEmpty(teamCode)) { return(NotFound()); } var team = await _wpbService.GetTeamByTeamCodeDto(teamCode); var teamStats = await _wpbService.GetTeamStat(teamCode); var teamSubdivision = team.SubDivisionCode; var subDivCount = await _wpbService.GetSubDivisionCountAsync(teamSubdivision); // get all teams in this subdivision var teamPeers = await _wpbService.GetTeamsBySubDivisionAllAsync(team.SubDivisionCode); // Remove the team with the teamCode passed in var teamSelf = teamPeers.FirstOrDefault(x => x.TeamCode == teamCode); teamPeers.Remove(teamSelf); var nextFixture = Task.Run <FixturesDto>(() => { var query = _wpbService.GetFixturesAsDtoAll(); var filter = query.Where(x => (x.AwayTeamCode == team.TeamCode || x.HomeTeamCode == team.TeamCode) && x.FixtureDate >= System.DateTime.Now.Date) .OrderBy(x => x.FixtureDate).ToList(); var entity = (filter.Count >= 1) ? filter[0] : null; return(entity); }); nextFixture.Wait(); var lastResult = Task.Run <GameResultDto>(() => { var query = _wpbService.GetResultsAsDtoAll(); var filter = query.Where(x => x.AwayTeamCode == team.TeamCode || x.HomeTeamCode == team.TeamCode) .OrderBy(x => x.TimeStamp).ToList(); var entity = (filter.Count >= 1) ? filter[0] : null; return(entity); }); lastResult.Wait(); if (team != null && teamStats != null) { team = AddTeamStat(teamStats, team); team.SubDivisionCount = subDivCount; team.TeamNextMatch = nextFixture.Result; team.TeamLastResult = lastResult.Result; team.Peers = teamPeers; return(Ok(team)); } else { return(NotFound()); } }
public async Task <IActionResult> GetAllMatchesForTeam(string teamCode) { if (string.IsNullOrEmpty(teamCode)) { return(NotFound()); } var team = await _wpbService.GetTeamByTeamCodeDto(teamCode); if (team == null) { return(NotFound()); } var fixturesQuery = Task.Run <List <FixturesDto> >(() => { var query = _wpbService.GetFixturesAsDtoAll(); var filter = query.Where(x => (x.AwayTeamCode == team.TeamCode || x.HomeTeamCode == team.TeamCode) && x.FixtureDate >= System.DateTime.Now.Date) .OrderBy(x => x.FixtureDate).ToList(); var entity = (filter.Count >= 1) ? filter : null; return(entity); }); fixturesQuery.Wait(); return(Ok(fixturesQuery.Result)); }