public ActionResult <List <Player> > GetPlayers(int teamId) { teamId = teamId == 0 ? 7 : teamId; List <Player> players = new List <Player>(); NhlRoster roster = new NhlRoster(); players = _hockeyApiService.GetPlayersByTeamId(teamId); return(Ok(players)); }
/// <summary> /// Get a roster object containing a list of players /// </summary> /// <param name="teamId"></param> /// <returns></returns> public NhlRoster GetTeamRosterByTeamId(int teamId) { NhlRoster roster = new NhlRoster(); string url = _externalApiRoot.AppendPathSegment("api").AppendPathSegment("v1") .AppendPathSegment("teams") .AppendPathSegment(teamId) .AppendPathSegment("roster"); var client = new RestClient(url); var response = client.Execute <NhlRoster>(new RestRequest()); return(JsonConvert.DeserializeObject <NhlRoster>(response.Content)); }
public List <Player> GetPlayersByTeamId(int teamId) { //List<Task> tasks = new List<Task>(); List <NhlPlayer> nhlPlayers = new List <NhlPlayer>(); List <Player> hfiPlayers = new List <Player>(); NhlRoster roster = GetTeamRosterByTeamId(teamId); nhlPlayers = roster.roster; //TODO: map objects without foreach //TODO: check null or count //foreach(NhlPlayer nhlPlayer in nhlPlayers) Parallel.ForEach(nhlPlayers, nhlPlayer => { Player player = AssemblePlayer(nhlPlayer); hfiPlayers.Add(player); }); return(hfiPlayers); }