public YahooPlayersCollection FilterByPlayerNameThenCreateInstance(string playerName) { string leagueKey = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey(); string uriPlayersCollection = _endPoints.PlayersCollectionForPlayerName(leagueKey, playerName).EndPointUri; YahooPlayersCollection yPc = CreatePlayersCollectionInstance(uriPlayersCollection); return(yPc); }
// PRIMARY METHOD: OPTION 1 // STATUS [ June 9, 2019 ] : this works /// <summary> /// Create instance of yahoo team model; save it to the database /// </summary> /// <param name="managerId"> /// A number 0 - X; Where X is the total number of teams in the league; /// Basically every manager has their own single number Id; /// Select the Id of the Manager you would want to view /// </param> /// <example> /// var teamBase = CreateYahooTeamResourceInstance(7); /// </example> public YahooTeamResource CreateYahooTeamResourceInstance(int managerId) { // _h.StartMethod(); YahooTeamResource tB = new YahooTeamResource(); string leagueKey = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey(); var uriTeamBase = endPoints.TeamResourceEndPoint(leagueKey, managerId).EndPointUri; // Console.WriteLine($"MANAGER CONTROLLER > leagueKey: {leagueKey}"); Console.WriteLine($"uriTeamBase: {uriTeamBase}"); // for each team in the league, dig through their team json, find the required items to create the new YahooTeamBase and set those items JObject resourceJson = _yahooApiRequestController.GenerateYahooResourceJObject(uriTeamBase); PopulateInitialTeamResourceInstanceProperties(tB, resourceJson); // Managers is nested under 'teamBasePath' var managerPath = resourceJson["fantasy_content"]["team"]["managers"]["manager"]; // The type under 'manager' will indicate if the team has one manager or co-managers // Type for one manager = "Newtonsoft.Json.Linq.JObject" // Type for co-managers = "Newtonsoft.Json.Linq.JArray" var managerPathChildrenType = managerPath.GetType().ToString(); const string jObjectType = "Newtonsoft.Json.Linq.JObject"; const string jArrayType = "Newtonsoft.Json.Linq.JArray"; // One manager path if (string.Equals(managerPathChildrenType, jObjectType, StringComparison.Ordinal)) { PopulateTeamResourceInstanceWithOneManager(tB, managerPath); } // Co-manager path List <YahooManager> teamManagersList = new List <YahooManager>(); tB.TeamManagersList = new List <YahooManager>(); if (string.Equals(managerPathChildrenType, jArrayType, StringComparison.Ordinal)) { PopulateTeamBaseWithCoManagers(tB, managerPath, teamManagersList); } _h.Dig(tB); // _h.CompleteMethod(); return(tB); }