Esempio n. 1
0
        public IActionResult CreateYahooManagerModelFromUrl(int managerId)
        {
            // _h.StartMethod();
            string leagueKey = _yahooApiRequestController.GetTheGameIsTheGameLeagueKey();
            // Console.WriteLine($"MANAGER CONTROLLER > leagueKey: {leagueKey}");

            // Create the uri that will be used to generate the appropriate json
            // Use Lg. Standings endpoint because mgr. details are nested in league standings json
            var uriLeagueStandings = _endPoints.LeagueStandingsEndPoint(leagueKey).EndPointUri;

            JObject leagueStandings = _yahooApiRequestController.GenerateYahooResourceJObject(uriLeagueStandings);

            YahooManager yM = new YahooManager
            {
                // these pull from the yahoo response (xml or json) to set each item
                ManagerId = _endPoints.TeamItem(leagueStandings, managerId, "ManagerId"),
                NickName  = _endPoints.TeamItem(leagueStandings, managerId, "Nickname"),
                Guid      = _endPoints.TeamItem(leagueStandings, managerId, "Guid"),
            };

            // Only the commish of the league will have  the "IsCommissioner" field
            try { yM.IsCommissioner = _endPoints.TeamItem(leagueStandings, managerId, "IsCommissioner"); }
            catch (Exception ex) { Console.WriteLine("ERROR IN: YahooManagerController.CreateYahooManagerModel() --> user not the commish"); }


            // "IsCurrentLogin" will only return data of current user is fetching their league's data
            try { yM.IsCurrentLogin = _endPoints.TeamItem(leagueStandings, managerId, "IsCurrentLogin"); }
            catch (Exception ex)
            { Console.WriteLine("ERROR IN: YahooManagerController.CreateYahooManagerModel() --> user not looged in "); }


            // Yahoo managers can hide their email; if hidden, you'll get an error
            try { yM.Email = _endPoints.TeamItem(leagueStandings, managerId, "Email"); }
            catch (Exception ex)
            { Console.WriteLine("ERROR IN: YahooManagerController.CreateYahooManagerModel() --> User has no email"); }

            yM.ImageUrl = _endPoints.TeamItem(leagueStandings, managerId, "ImageUrl");
            // PrintYahooManagerDetails(yM);
            return(Content(yM.ToString()));
        }