public IActionResult Get(int id) { string url = "http://stats.nba.com/stats/commonteamroster?LeagueID=00&Season=2017-18&TeamID=" + id; try { var players = new List <Player>(); //Add your user agent of choice. This is mine, just as an example. var response = _customWebClient.GetResponse(url); var releases = JObject.Parse(response); var test = releases["resultSets"][0]["rowSet"].Children(); foreach (var playerLinq in test) { players.Add(new Player { TeamID = (int)playerLinq[0], SEASON = playerLinq[1].ToString(), LeagueID = playerLinq[2].ToString(), PLAYER = playerLinq[3].ToString(), NUM = playerLinq[4].ToString(), POSITION = playerLinq[5].ToString(), HEIGHT = playerLinq[6].ToString(), WEIGHT = playerLinq[7].ToString(), birth_date = playerLinq[8].ToString(), AGE = (decimal)playerLinq[9], EXP = playerLinq[10].ToString(), SCHOOL = playerLinq[11].ToString(), player_id = (int)playerLinq[12], photoUrl = "" }); } return(Ok(players.ToArray())); } catch (Exception e) { throw; } }
public IActionResult Get(int id) { try { MemoryCacheEntryOptions cacheExpirationOptions = new MemoryCacheEntryOptions(); cacheExpirationOptions.AbsoluteExpiration = DateTime.Now.AddDays(7); cacheExpirationOptions.Priority = CacheItemPriority.Normal; var stats = new List <Stats>(); if (!cache.TryGetValue <List <Stats> >(id, out stats)) { var response = _customWebClient.GetResponse("https://stats.nba.com/stats/playerprofilev2?LeagueID=00&PerMode=PerGame&PlayerID=" + id); var releases = JObject.Parse(response); var test = releases["resultSets"][0]["rowSet"].Children(); stats = new List <Stats>(); foreach (var playerLinq in test) { stats.Add(new Stats { Player_id = (int)playerLinq[0], Season_id = playerLinq[1].ToString(), League_id = playerLinq[2].ToString(), Team_id = (int)playerLinq[3], Team_abbreviation = playerLinq[4].ToString(), Player_age = (int)playerLinq[5], Gp = (int)playerLinq[6], Gs = (int)playerLinq[7], Min = (int)playerLinq[8], Fgm = (decimal)playerLinq[9], Fga = (decimal)playerLinq[10], Fg_pct = (decimal)playerLinq[11], Fg3m = (decimal)playerLinq[12], Fg3a = (int)playerLinq[13], Fg3_pct = (decimal)playerLinq[14], Ftm = (decimal)playerLinq[15], Fta = (decimal)playerLinq[16], Ft_pct = (decimal)playerLinq[17], Oreb = (decimal)playerLinq[18], Dreb = (decimal)playerLinq[19], Reb = (decimal)playerLinq[20], Ast = (decimal)playerLinq[21], Stl = (decimal)playerLinq[22], Blk = (decimal)playerLinq[23], Tov = (decimal)playerLinq[24], Pf = (decimal)playerLinq[25], Pts = (decimal)playerLinq[26] }); } cache.Set(id, stats, cacheExpirationOptions); } else { stats = cache.Get <List <Stats> >(id); } // stats = cache.Get<List<Stats>>(id); //Add your user agent of choice. This is mine, just as an example. return(Ok(stats.ToArray())); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(Ok("value")); }