public YahooTeamStanding CreateYahooTeamStandingModel()
        {
            _h.StartMethod();

            // retrieve the league key from user secrets / yahoo league config
            string leagueKey = _theGameConfig.LeagueKey;

            Console.WriteLine($"leagueKey: {leagueKey}");

            // create the uri that will be used to generate the appropriate json; in this case, it's the League Standings endpoint (view YahooApiEndPoints.cs)
            var uriLeagueStandings = endPoints.LeagueStandingsEndPoint(leagueKey).EndPointUri;

            Console.WriteLine($"uriLeagueStandings: {uriLeagueStandings}");

            JObject   leagueStandings = _yahooApiRequestController.GenerateYahooResourceJObject(uriLeagueStandings);
            const int teamsInLeague   = 10;

            YahooTeamStanding yS = new YahooTeamStanding();

            for (var teamId = 0; teamId <= teamsInLeague - 1; teamId++)
            {
                yS.Rank                     = endPoints.TeamItem(leagueStandings, 0, "Rank");
                yS.PlayoffSeed              = endPoints.TeamItem(leagueStandings, 0, "PlayoffSeed");
                yS.GamesBack                = endPoints.TeamItem(leagueStandings, 0, "GamesBack");
                yS.OutcomeTotals.Wins       = endPoints.TeamItem(leagueStandings, 0, "Wins");
                yS.OutcomeTotals.Losses     = endPoints.TeamItem(leagueStandings, 0, "Losses");
                yS.OutcomeTotals.Ties       = endPoints.TeamItem(leagueStandings, 0, "Ties");
                yS.OutcomeTotals.Percentage = endPoints.TeamItem(leagueStandings, 0, "WinningPercentage");

                Console.WriteLine($"TEAM STANDINGS FOR TEAM ID {teamId}");
                Console.WriteLine(yS);
                Console.WriteLine();
            }
            // int X = 0;

            // var leagueStandingsTeamsTeamX = leagueStandings["fantasy_content"]["league"]["standings"]["teams"]["team"][X];

            // Console.WriteLine(leagueStandingsTeamsTeamX["team_stats"].GetType());

            return(yS);
        }
Exemple #2
0
        // 1 : DJB
        // 2 : DSch
        // 3 : CSt
        // 4 : SpMc
        // 5 : PJB
        // 6 : JB
        // 7 : Pants
        // 8 : JCuz
        // 9 : DBra
        // 10: MC

        #region YAHOO MANAGER - PRIMARY METHODS ------------------------------------------------------------


        // STATUS [ June 8, 2019 ] : this works
        /// <summary>
        ///     Instantiate new instance of a yahoo manager
        ///     The manager data in the requested json is found nested under league standings
        /// </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 yahooManager = CreateYahooManagerModel(1);
        /// </example>
        /// <returns>
        ///     A new YahooManager
        /// </returns>
        public YahooManager CreateYahooManagerModel(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(yM);
        }