Ejemplo n.º 1
0
        public IList <NflGame> GetNflScores()
        {
            //string url = "http://www.nfl.com/liveupdate/scores/scores.json";
            string url = "http://www.nfl.com/liveupdate/scorestrip/ss.xml";
            //http://www.nfl.com/ajax/scorestrip?season=2017&seasonType=REG&week=4

            var webpage = new WebClient();
            var html    = webpage.DownloadString(url);
            var xmlDoc  = new XmlDocument();

            xmlDoc.LoadXml(html);
            XmlNode result = xmlDoc.SelectNodes("//ss/gms")[0];

            var gamesList = new List <NflGame>();

            foreach (XmlNode game in result.ChildNodes)
            {
                var nflGame = new NflGame
                {
                    HomeTeamAbbrev    = game.Attributes["h"].Value,
                    HomeTeamName      = CapWord(game.Attributes["hnn"].Value),
                    VisitorTeamAbbrev = game.Attributes["v"].Value,
                    VisitorTeamName   = CapWord(game.Attributes["vnn"].Value),
                    CurrentQuarter    = game.Attributes["q"].Value,
                    DayOfWeek         = game.Attributes["d"].Value,
                    GameId            = game.Attributes["gsis"].Value,
                    HomeScore         = Convert.ToInt16(game.Attributes["hs"].Value),
                    VisitorScore      = Convert.ToInt16(game.Attributes["vs"].Value),
                    GameTime          = game.Attributes["t"].Value,
                    InRedzone         = BoolConvert(game.Attributes["rz"].Value)
                };
                gamesList.Add(nflGame);
            }
            return(gamesList);
        }
Ejemplo n.º 2
0
 private float GetFantasyPointsForTeamInGame(NflGame game, Guid teamId)
 {
     if (game.PrimaryTeamId == teamId)
     {
         if (game.PrimaryPoints > game.SecondaryPoints)
         {
             return(FANTASY_POINTS_FOR_WIN);
         }
         else if (game.PrimaryPoints == game.SecondaryPoints)
         {
             return(FANTASY_POINTS_FOR_TIE);
         }
         else
         {
             return(FANTASY_POINTS_FOR_LOSS);
         }
     }
     else if (game.SecondaryTeamId == teamId)
     {
         if (game.SecondaryPoints > game.PrimaryPoints)
         {
             return(FANTASY_POINTS_FOR_WIN);
         }
         else if (game.SecondaryPoints == game.PrimaryPoints)
         {
             return(FANTASY_POINTS_FOR_TIE);
         }
         else
         {
             return(FANTASY_POINTS_FOR_LOSS);
         }
     }
     return(0.0f); // team was not involved (not primary or secondary)
 }
Ejemplo n.º 3
0
        public IActionResult Index()
        {
            var games = NflGame.GetGames("11");

            //List<NflGame> gameList = new List<NflGame>();
            //foreach (var game in games)
            //{
            //    gameList.Add(game);
            //}
            return(View(games));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateGames()
        {
            _context.Database.ExecuteSqlCommand("TRUNCATE TABLE [NflGames]");
            var games = NflGame.GetGames("5");

            foreach (var game in games)
            {
                _context.NflGames.Add(game);
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }