示例#1
0
        public bool UpdatePlayers(string updateplayers)
        {
            bool success = true;
            GameCenterController gcController = new GameCenterController();
            PlayerController pController = new PlayerController();
            Dictionary<string, Player> playerDictionary = pController.GetPlayerDictionary();
            var players = new List<string>();
            foreach (var week in context.SeasonWeeks.Where(sw => sw.SeasonYear == 2016).OrderBy(sw => sw.SeasonWeekNum))
            {
                var gd = gcController.GetGameCenterData(week.SeasonYear, week.SeasonType, week.SeasonWeekNum);
                foreach (var g in gd)
                {
                    foreach(var p in g.Home.Stats.Where(s => s.PlayerProfileId == 0).Select(s => s.PlayerId).Distinct())
                    {
                        players.Add(p);
                    }
                    foreach(var p in g.Away.Stats.Where(s => s.PlayerProfileId == 0).Select(s => s.PlayerId).Distinct())
                    {
                        players.Add(p);                        
                    }
                }
            }

            foreach (var player in players)
            {
                if (!playerDictionary.ContainsKey(player))
                {
                    var profile = pController.GetPlayerProfile(player);
                }
            }
            
            return success;
        }
        public GameCenterData GetGameData(int gId)
        {
            var gameId = gId.ToString();
            PlayerController pController = new PlayerController();
            var playerDictionary = pController.GetPlayerDictionary();
            var scDictionary = BuildScoringConfigDictionary();

            GameCenterData gd = new GameCenterData();            

            var gameExists = context.Games.Where(g => g.GameId == gId).FirstOrDefault();
            var gameCenterJsonString = string.Empty;
            
            try
            {
                gameCenterJsonString = GetGameCenterJson(gId);
            }
            catch (Exception)
            {
                return gd;
            }

            gd.GameCenterJson = gameCenterJsonString;

            JObject gameCenterJson = JsonConvert.DeserializeObject<JObject>(gameCenterJsonString);
            if (gameCenterJson.Children().Count() == 0)
            {
                return gd;
            }   

            gd.GameId = Convert.ToInt32(gameCenterJson.Children().First().Value<JProperty>().Name);
            //gd.NextUpdate = gameCenterJson["nextupdate"].Value<int>();

            //gd = new GameData();
            gd.Home = new TeamData();
            gd.Away = new TeamData();

            gd.Home.Abbreviation = gameCenterJson[gameId]["home"]["abbr"].Value<string>();
            //gd.Home.TimeOuts = gameCenterJson[gameId]["home"]["to"].Value<int>();
            gd.Away.Abbreviation = gameCenterJson[gameId]["away"]["abbr"].Value<string>();
            //gd.Away.TimeOuts = gameCenterJson[gameId]["away"]["to"].Value<int>();
            //gd.Home.Players = new List<GameCenterPlayer>();
            //gd.Away.Players = new List<GameCenterPlayer>();
            //gd.Weather = new Weather();
            //gd.Media = new Media();
            //gd.YardLine = gameCenterJson[gameId]["yl"].Value<string>();
            gd.Quarter = gameCenterJson[gameId]["qtr"].Value<string>();
            //gd.Note = new Note();
            //gd.Down = gameCenterJson[gameId]["down"].Value<int>();
            //gd.ToGo = gameCenterJson[gameId]["togo"].Value<int>();
            //gd.Redzone = gameCenterJson[gameId]["redzone"].Value<bool>();
            gd.Clock = gameCenterJson[gameId]["clock"].Value<string>();
            //gd.PossessingTeam = gameCenterJson[gameId]["posteam"].Value<string>();
            //gd.Stadium = new Stadium();
            gd.PlayerStats = new List<Stats>();

            #region Home Score
            //var homeScore = new List<Score>();
            //Score homeQuarter1 = new Score
            //{
            //    Quarter = "1",
            //    ScoreNum = gameCenterJson[gameId]["home"]["score"]["1"].Value<int>()
            //};
            //Score homeQuarter2 = new Score
            //{
            //    Quarter = "2",
            //    ScoreNum = gameCenterJson[gameId]["home"]["score"]["2"].Value<int>()
            //};

            //Score homeQuarter3 = new Score
            //{
            //    Quarter = "3",
            //    ScoreNum = gameCenterJson[gameId]["home"]["score"]["3"].Value<int>()
            //};

            //Score homeQuarter4 = new Score
            //{
            //    Quarter = "4",
            //    ScoreNum = gameCenterJson[gameId]["home"]["score"]["4"].Value<int>()
            //};

            //Score homeOvertime = new Score
            //{
            //    Quarter = "OT",
            //    ScoreNum = gameCenterJson[gameId]["home"]["score"]["5"].Value<int>()
            //};

            //Score homeFinal = new Score
            //{
            //    Quarter = "T",
            //    ScoreNum = gameCenterJson[gameId]["home"]["score"]["T"].Value<int>()
            //};

            //homeScore.Add(homeQuarter1);
            //homeScore.Add(homeQuarter2);
            //homeScore.Add(homeQuarter3);
            //homeScore.Add(homeQuarter4);
            //homeScore.Add(homeOvertime);
            //homeScore.Add(homeFinal);
            //gd.Home.Score = homeScore;
            #endregion

            #region Away Score
            //var awayScore = new List<Score>();
            //Score awayQuarter1 = new Score
            //{
            //    Quarter = "1",
            //    ScoreNum = gameCenterJson[gameId]["home"]["score"]["1"].Value<int>()
            //};
            //Score awayQuarter2 = new Score
            //{
            //    Quarter = "2",
            //    ScoreNum = gameCenterJson[gameId]["away"]["score"]["2"].Value<int>()
            //};

            //Score awayQuarter3 = new Score
            //{
            //    Quarter = "3",
            //    ScoreNum = gameCenterJson[gameId]["away"]["score"]["3"].Value<int>()
            //};

            //Score awayQuarter4 = new Score
            //{
            //    Quarter = "4",
            //    ScoreNum = gameCenterJson[gameId]["away"]["score"]["4"].Value<int>()
            //};

            //Score awayOvertime = new Score
            //{
            //    Quarter = "OT",
            //    ScoreNum = gameCenterJson[gameId]["away"]["score"]["5"].Value<int>()
            //};

            //Score awayFinal = new Score
            //{
            //    Quarter = "T",
            //    ScoreNum = gameCenterJson[gameId]["away"]["score"]["T"].Value<int>()
            //};

            //awayScore.Add(awayQuarter1);
            //awayScore.Add(awayQuarter2);
            //awayScore.Add(awayQuarter3);
            //awayScore.Add(awayQuarter4);
            //awayScore.Add(awayOvertime);
            //awayScore.Add(awayFinal);
            //gd.Away.Score = awayScore;
            #endregion

            #region Team Stats
            gd.Home.TeamStats = new TeamStats
            {
                TotalFirstDowns = gameCenterJson[gameId]["home"]["stats"]["team"]["totfd"].Value<int>(),
                TotalYards = gameCenterJson[gameId]["home"]["stats"]["team"]["totyds"].Value<int>(),
                PassYards = gameCenterJson[gameId]["home"]["stats"]["team"]["pyds"].Value<int>(),
                RushYards = gameCenterJson[gameId]["home"]["stats"]["team"]["ryds"].Value<int>(),
                Penalties = gameCenterJson[gameId]["home"]["stats"]["team"]["pen"].Value<int>(),
                PenaltyYards = gameCenterJson[gameId]["home"]["stats"]["team"]["penyds"].Value<int>(),
                Turnovers = gameCenterJson[gameId]["home"]["stats"]["team"]["trnovr"].Value<int>(),
                Punts = gameCenterJson[gameId]["home"]["stats"]["team"]["pt"].Value<int>(),
                PuntYards = gameCenterJson[gameId]["home"]["stats"]["team"]["ptyds"].Value<int>(),
                PuntAvg = gameCenterJson[gameId]["home"]["stats"]["team"]["ptavg"].Value<int>(),
                TimeOfPossession = gameCenterJson[gameId]["home"]["stats"]["team"]["top"].Value<string>(),
                PointsScored = gameCenterJson[gameId]["home"]["score"]["T"].Value<int>(),
                PointsAllowed = gameCenterJson[gameId]["away"]["score"]["T"].Value<int>(),
                DefensiveTDs = 0,
                Safeties = 0,
                PuntReturnTDs = 0,
                KickReturnTDs = 0
            };

            gd.Away.TeamStats = new TeamStats
            {
                TotalFirstDowns = gameCenterJson[gameId]["away"]["stats"]["team"]["totfd"].Value<int>(),
                TotalYards = gameCenterJson[gameId]["away"]["stats"]["team"]["totyds"].Value<int>(),
                PassYards = gameCenterJson[gameId]["away"]["stats"]["team"]["pyds"].Value<int>(),
                RushYards = gameCenterJson[gameId]["away"]["stats"]["team"]["ryds"].Value<int>(),
                Penalties = gameCenterJson[gameId]["away"]["stats"]["team"]["pen"].Value<int>(),
                PenaltyYards = gameCenterJson[gameId]["away"]["stats"]["team"]["penyds"].Value<int>(),
                Turnovers = gameCenterJson[gameId]["away"]["stats"]["team"]["trnovr"].Value<int>(),
                Punts = gameCenterJson[gameId]["away"]["stats"]["team"]["pt"].Value<int>(),
                PuntYards = gameCenterJson[gameId]["away"]["stats"]["team"]["ptyds"].Value<int>(),
                PuntAvg = gameCenterJson[gameId]["away"]["stats"]["team"]["ptavg"].Value<int>(),
                TimeOfPossession = gameCenterJson[gameId]["away"]["stats"]["team"]["top"].Value<string>(),
                PointsScored = gameCenterJson[gameId]["away"]["score"]["T"].Value<int>(),
                PointsAllowed = gameCenterJson[gameId]["home"]["score"]["T"].Value<int>(),
                DefensiveTDs = 0,
                Safeties = 0,
                PuntReturnTDs = 0,
                KickReturnTDs = 0
            }; 
            #endregion

            #region Home Stats
            //var homeStats = new List<Stats>();

            if (gameCenterJson[gameId]["home"]["stats"]["passing"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["passing"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Passing", StatName = "Att", StatValue = stat.First()["att"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "Cmp", StatValue = stat.First()["cmp"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "Yds", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = (scDictionary["PtsPerPassingYard"] * stat.First()["yds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerPassingTD"] * stat.First()["tds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "INTs", StatValue = stat.First()["ints"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "2PCs Att", StatValue = stat.First()["twopta"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "2PCs", StatValue = stat.First()["twoptm"].Value<decimal>(), PointValue = (scDictionary["PtsPerTwoPointConversion"] * stat.First()["twoptm"].Value<decimal>()) });
                    
                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;

                    var ps = new Stats
                    {
                        StatType = "Passing",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["home"]["stats"]["rushing"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["rushing"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Att", StatValue = stat.First()["att"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Yds", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = (scDictionary["PtsPerRushingYard"] * stat.First()["yds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerRushingTD"] * stat.First()["tds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Longest Rush", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Longest Rush TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "2PCs Att", StatValue = stat.First()["twopta"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "2PCs", StatValue = stat.First()["twoptm"].Value<decimal>(), PointValue = (scDictionary["PtsPerTwoPointConversion"] * stat.First()["twoptm"].Value<decimal>()) });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Rushing",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["home"]["stats"]["receiving"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["receiving"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Rec", StatValue = stat.First()["rec"].Value<decimal>(), PointValue = (scDictionary["PtsPerReception"] * stat.First()["rec"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Yds", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = (scDictionary["PtsPerReceivingYard"] * stat.First()["yds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerReceivingTD"] * stat.First()["tds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Longest Catch", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Longest Receiving TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "2PCs Att", StatValue = stat.First()["twopta"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "2PCs", StatValue = stat.First()["twoptm"].Value<decimal>(), PointValue = (scDictionary["PtsPerTwoPointConversion"] * stat.First()["twoptm"].Value<decimal>()) });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Receiving",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["home"]["stats"]["fumbles"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["fumbles"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Total Fumbles", StatValue = stat.First()["tot"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Fumbles Recovered", StatValue = stat.First()["rcv"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Total Fumbles Recovered", StatValue = stat.First()["trcv"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Fumble Yards", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Fumbles Lost", StatValue = stat.First()["lost"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Fumbles",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["home"]["stats"]["kicking"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["kicking"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "FGs", StatValue = stat.First()["fgm"].Value<decimal>(), PointValue = (scDictionary["PtsPerFGMade"] * stat.First()["fgm"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "FGs Att", StatValue = stat.First()["fga"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "FG Yards", StatValue = stat.First()["fgyds"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "Total Pts FG", StatValue = stat.First()["totpfg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs", StatValue = stat.First()["xpmade"].Value<decimal>(), PointValue = (scDictionary["PtsPerExtraPoint"] * stat.First()["xpmade"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs Missed", StatValue = stat.First()["xpmissed"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs Att", StatValue = stat.First()["xpa"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs Blocked", StatValue = stat.First()["xpb"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "Total Pts XP", StatValue = stat.First()["xptot"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Kicking",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["home"]["stats"]["punting"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["punting"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punts", StatValue = stat.First()["pts"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punt Yards", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punt Avg", StatValue = stat.First()["avg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punts Inside 20", StatValue = stat.First()["i20"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Longest Punt", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Punting",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["home"]["stats"]["kickret"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["kickret"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Kick Returns", StatValue = stat.First()["ret"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Kick Return Avg", StatValue = stat.First()["avg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Kick Ret TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerKickReturnTD"] * stat.First()["tds"].Value<decimal>()) });

                    if (stat.First()["tds"].Value<int>() > 0)
                    {
                        gd.Home.TeamStats.KickReturnTDs += stat.First()["tds"].Value<int>();
                    }

                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Longest Kick Return", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Longest Kick Return TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Kick Return",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["home"]["stats"]["puntret"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["puntret"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Punt Returns", StatValue = stat.First()["ret"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Punt Return Avg", StatValue = stat.First()["avg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Punt Ret TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerPuntReturnTD"] * stat.First()["tds"].Value<decimal>()) });

                    if (stat.First()["tds"].Value<int>() > 0)
                    {
                        gd.Home.TeamStats.PuntReturnTDs += stat.First()["tds"].Value<int>();
                    }

                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Longest Punt Return", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Longest Punt Return TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Punt Return",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }


            if (gameCenterJson[gameId]["home"]["stats"]["defense"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["home"]["stats"]["defense"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Tackles", StatValue = stat.First()["tkl"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Assisted Sacks", StatValue = stat.First()["ast"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Sacks", StatValue = stat.First()["sk"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "INTs", StatValue = stat.First()["int"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Forced Fumbles", StatValue = stat.First()["ffum"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Defense",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //homeStats.Add(ps);
                }
            }

            //gd.Home.Stats = homeStats;
            #endregion

            #region Away Stats
            if (gameCenterJson[gameId]["away"]["stats"]["passing"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["passing"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Passing", StatName = "Att", StatValue = stat.First()["att"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "Cmp", StatValue = stat.First()["cmp"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "Yds", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = (scDictionary["PtsPerPassingYard"] * stat.First()["yds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerPassingTD"] * stat.First()["tds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "INTs", StatValue = stat.First()["ints"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "2PCs Att", StatValue = stat.First()["twopta"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Passing", StatName = "2PCs", StatValue = stat.First()["twoptm"].Value<decimal>(), PointValue = (scDictionary["PtsPerTwoPointConversion"] * stat.First()["twoptm"].Value<decimal>()) });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;

                    var ps = new Stats
                    {
                        StatType = "Passing",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["away"]["stats"]["rushing"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["rushing"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Att", StatValue = stat.First()["att"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Yds", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = (scDictionary["PtsPerRushingYard"] * stat.First()["yds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerRushingTD"] * stat.First()["tds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Longest Rush", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "Longest Rush TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "2PCs Att", StatValue = stat.First()["twopta"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Rushing", StatName = "2PCs", StatValue = stat.First()["twoptm"].Value<decimal>(), PointValue = (scDictionary["PtsPerTwoPointConversion"] * stat.First()["twoptm"].Value<decimal>()) });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Rushing",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["away"]["stats"]["receiving"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["receiving"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Rec", StatValue = stat.First()["rec"].Value<decimal>(), PointValue = (scDictionary["PtsPerReception"] * stat.First()["rec"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Yds", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = (scDictionary["PtsPerReceivingYard"] * stat.First()["yds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerReceivingTD"] * stat.First()["tds"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Longest Catch", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "Longest Receiving TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "2PCs Att", StatValue = stat.First()["twopta"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Receiving", StatName = "2PCs", StatValue = stat.First()["twoptm"].Value<decimal>(), PointValue = (scDictionary["PtsPerTwoPointConversion"] * stat.First()["twoptm"].Value<decimal>()) });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Receiving",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["away"]["stats"]["fumbles"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["fumbles"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Total Fumbles", StatValue = stat.First()["tot"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Fumbles Recovered", StatValue = stat.First()["rcv"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Total Fumbles Recovered", StatValue = stat.First()["trcv"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Fumble Yards", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Fumbles", StatName = "Fumbles Lost", StatValue = stat.First()["lost"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Fumbles",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["away"]["stats"]["kicking"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["kicking"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "FGs", StatValue = stat.First()["fgm"].Value<decimal>(), PointValue = (scDictionary["PtsPerFGMade"] * stat.First()["fgm"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "FGs Att", StatValue = stat.First()["fga"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "FG Yards", StatValue = stat.First()["fgyds"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "Total Pts FG", StatValue = stat.First()["totpfg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs", StatValue = stat.First()["xpmade"].Value<decimal>(), PointValue = (scDictionary["PtsPerExtraPoint"] * stat.First()["xpmade"].Value<decimal>()) });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs Missed", StatValue = stat.First()["xpmissed"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs Att", StatValue = stat.First()["xpa"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "XPs Blocked", StatValue = stat.First()["xpb"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kicking", StatName = "Total Pts XP", StatValue = stat.First()["xptot"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Kicking",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["away"]["stats"]["punting"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["punting"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punts", StatValue = stat.First()["pts"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punt Yards", StatValue = stat.First()["yds"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punt Avg", StatValue = stat.First()["avg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Punts Inside 20", StatValue = stat.First()["i20"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punting", StatName = "Longest Punt", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Punting",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["away"]["stats"]["kickret"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["kickret"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Kick Returns", StatValue = stat.First()["ret"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Kick Return Avg", StatValue = stat.First()["avg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Kick Ret TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerKickReturnTD"] * stat.First()["tds"].Value<decimal>()) });

                    if (stat.First()["tds"].Value<int>() > 0)
                    {
                        gd.Away.TeamStats.KickReturnTDs += stat.First()["tds"].Value<int>();
                    }

                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Longest Kick Return", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Kick Return", StatName = "Longest Kick Return TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Kick Return",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            if (gameCenterJson[gameId]["away"]["stats"]["puntret"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["puntret"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Punt Returns", StatValue = stat.First()["ret"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Punt Return Avg", StatValue = stat.First()["avg"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Punt Ret TDs", StatValue = stat.First()["tds"].Value<decimal>(), PointValue = (scDictionary["PtsPerPuntReturnTD"] * stat.First()["tds"].Value<decimal>()) });

                    if (stat.First()["tds"].Value<int>() > 0)
                    {
                        gd.Away.TeamStats.PuntReturnTDs += stat.First()["tds"].Value<int>();
                    }

                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Longest Punt Return", StatValue = stat.First()["lng"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Punt Return", StatName = "Longest Punt Return TD", StatValue = stat.First()["lngtd"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Punt Return",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }


            if (gameCenterJson[gameId]["away"]["stats"]["defense"] != null)
            {
                foreach (var stat in gameCenterJson[gameId]["away"]["stats"]["defense"].Children())
                {
                    var statValues = new List<Stat>();
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Tackles", StatValue = stat.First()["tkl"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Assisted Sacks", StatValue = stat.First()["ast"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Sacks", StatValue = stat.First()["sk"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "INTs", StatValue = stat.First()["int"].Value<decimal>(), PointValue = 0 });
                    statValues.Add(new Stat { StatType = "Defense", StatName = "Forced Fumbles", StatValue = stat.First()["ffum"].Value<decimal>(), PointValue = 0 });

                    var playerId = stat.Value<JProperty>().Name;
                    var player = (playerDictionary.ContainsKey(playerId) ? playerDictionary[playerId] : pController.GetPlayerProfile(playerId));
                    var nflId = player.PlayerId;
                    var ps = new Stats
                    {
                        StatType = "Defense",
                        PlayerId = playerId,
                        PlayerProfileId = nflId,
                        PlayerShortName = stat.First()["name"].Value<string>(),
                        PlayerName = player.Name,
                        PlayerSeasonWeekId = gameExists.SeasonWeekId,
                        PlayerGameId = gameExists.GameId,
                        Statistic = statValues
                    };

                    if (statValues.Where(sv => sv.PointValue != 0).Count() > 0)
                    {
                        var playerStatExists = gd.PlayerStats.Where(pss => pss.PlayerId == ps.PlayerId).FirstOrDefault();

                        if (playerStatExists == null)
                        {
                            var playerStat = ps;
                            playerStat.StatType = "Total";
                            playerStat.Statistic = statValues.Where(sv => sv.PointValue != 0).ToList();
                            gd.PlayerStats.Add(playerStat);
                        }
                        else
                        {
                            playerStatExists.Statistic.AddRange(statValues.Where(sv => sv.PointValue != 0));
                        }
                    }

                    //awayStats.Add(ps);
                }
            }

            //gd.Away.Stats = awayStats;
            #endregion           

            #region Drives
            //var drives = new List<Drive>();

            //foreach (var dr in gameCenterJson[gameId]["drives"])
            //{
            //    if (!dr.Value<JProperty>().Name.Equals("crntdrv"))
            //    {
            //        var drive = new Drive();
            //        drive.DriveNum = Convert.ToInt32(dr.Value<JProperty>().Name);
            //        drive.PossessingTeam = dr.First()["posteam"].Value<string>();
            //        drive.Redzone = dr.First()["redzone"].Value<bool>();
            //        var plays = new List<Play>();

            //        foreach (var pl in dr.First()["plays"].Children())
            //        {
            //            var play = new Play();
            //            play.PlayId = Convert.ToInt32(pl.Value<JProperty>().Name);
            //            play.ScoringPlay = pl.First()["sp"].Value<int>();
            //            play.Quarter = pl.First()["qtr"].Value<int>();
            //            play.Down = pl.First()["down"].Value<int>();
            //            play.Time = pl.First()["time"].Value<string>();
            //            play.YardLine = pl.First()["yrdln"].Value<string>();
            //            play.YardsToGo = pl.First()["ydstogo"].Value<int>();
            //            play.NetYards = pl.First()["ydsnet"].Value<int>();
            //            play.PossessingTeam = pl.First()["posteam"].Value<string>();
            //            play.Description = pl.First()["desc"].Value<string>();
            //            play.Note = pl.First()["note"].Value<string>();

            //            //var playPlayers = new List<PlayPlayers>();
            //            //foreach (var pp in pl.First()["players"].Children())
            //            //{
            //            //    var playPlayer = new PlayPlayers
            //            //    {

            //            //    };

            //            //    playPlayers.Add(playPlayer);
            //            //}

            //            //play.Players = playPlayers;
            //            plays.Add(play);
            //        }

            //        drive.Plays = plays;
            //        drive.FirstDowns = dr.First()["fds"].Value<int>();
            //        drive.Result = dr.First()["result"].Value<string>();
            //        drive.PenaltyYards = dr.First()["penyds"].Value<int>();
            //        drive.YardsGained = dr.First()["ydsgained"].Value<int>();
            //        drive.TimeOfPossession = dr.First()["postime"].Value<string>();
            //        drive.DriveStart = new DriveInfo
            //        {
            //            Quarter = dr.First()["start"]["qtr"].Value<int>(),
            //            Time = dr.First()["start"]["time"].Value<string>(),
            //            YardLine = dr.First()["start"]["yrdln"].Value<string>(),
            //            Team = dr.First()["start"]["team"].Value<string>()
            //        };

            //        drive.DriveEnd = new DriveInfo
            //        {
            //            Quarter = dr.First()["end"]["qtr"].Value<int>(),
            //            Time = dr.First()["end"]["time"].Value<string>(),
            //            YardLine = dr.First()["end"]["yrdln"].Value<string>(),
            //            Team = dr.First()["end"]["team"].Value<string>()
            //        };

            //        drives.Add(drive);
            //    }
            //}

            //gd.Drives = drives;
            #endregion

            #region Score Summary
            //var scoreSummary = new List<ScoreSummary>();

            foreach (var ss in gameCenterJson[gameId]["scrsummary"].Children())
            {
                //var scorePlayers = new List<ScorePlayers>();
                //foreach (var player in ss.First()["players"].Children())
                //{
                //    var playerName = player.Value<JProperty>().Name;
                //    if (!playerName.Equals(string.Empty))
                //    {
                //        var sp = new ScorePlayers
                //        {
                //            PlayerId = player.First().Value<string>(),
                //            PlayerProfileId = playerDictionary[player.First().Value<string>()].PlayerId,
                //            PlayerShortName = playerName
                //        };

                //        scorePlayers.Add(sp);
                //    }
                //}

                //var score = new ScoreSummary
                //{
                //    ScoreType = ss.First()["type"].Value<string>(),
                //    Description = ss.First()["desc"].Value<string>(),
                //    Quarter = ss.First()["qtr"].Value<int>(),
                //    Team = ss.First()["team"].Value<string>(),
                //    Players = scorePlayers
                //};

                if (ss.First()["type"].Value<string>() != null && ss.First()["type"].Value<string>().Equals("SAF"))
                {
                    if (gd.Home.Abbreviation.ToLower().Equals(ss.First()["team"].Value<string>().ToLower()))
                    {
                        gd.Home.TeamStats.Safeties++;
                    }

                    if (gd.Away.Abbreviation.ToLower().Equals(ss.First()["team"].Value<string>().ToLower()))
                    {
                        gd.Away.TeamStats.Safeties++;
                    }
                }

                if (ss.First()["type"].Value<string>() != null && ss.First()["type"].Value<string>().Equals("TD") && ss.First()["desc"].Value<string>().ToUpper().Contains("RETURN") && !ss.First()["desc"].Value<string>().ToUpper().Contains("PUNT"))
                {
                    if (gd.Home.Abbreviation.ToLower().Equals(ss.First()["team"].Value<string>().ToLower()))
                    {
                        gd.Home.TeamStats.DefensiveTDs++;
                    }

                    if (gd.Away.Abbreviation.ToLower().Equals(ss.First()["team"].Value<string>().ToLower()))
                    {
                        gd.Away.TeamStats.DefensiveTDs++;
                    }
                }

                //scoreSummary.Add(score);
            }

            //gd.ScoreSummary = scoreSummary;
            #endregion

            #region Team Player Stats

            foreach (var pstat in gd.PlayerStats)
            {
                pstat.TotalPoints = pstat.Statistic.Sum(s => s.PointValue);
            }

            var homeAbv = (gd.Home.Abbreviation.ToLower().Equals("jac") ? "jax" : gd.Home.Abbreviation.ToLower());
            var homeDST = context.Players.Where(p => p.PositionId == "DST" && p.TeamId == homeAbv).FirstOrDefault();
            var awayAbv = (gd.Away.Abbreviation.ToLower().Equals("jac") ? "jax" : gd.Away.Abbreviation.ToLower());
            var awayDST = context.Players.Where(p => p.PositionId == "DST" && p.TeamId == awayAbv).FirstOrDefault();
            var homePointsAllowed = gd.Home.TeamStats.PointsAllowed;
            var awayPointsAllowed = gd.Away.TeamStats.PointsAllowed;
            var homeReturnTDsAllowed = gd.Away.TeamStats.PuntReturnTDs + gd.Away.TeamStats.KickReturnTDs;
            var awayReturnTDsAllowed = gd.Home.TeamStats.PuntReturnTDs + gd.Home.TeamStats.KickReturnTDs;
            var homeDefensiveTDs = gd.Home.TeamStats.DefensiveTDs;
            var awayDefensiveTDs = gd.Away.TeamStats.DefensiveTDs;
            var homeSafeties = gd.Home.TeamStats.Safeties;
            var awaySafeties = gd.Away.TeamStats.Safeties;
            var homeAdjustedPointsAllowed = homePointsAllowed - (7 * homeReturnTDsAllowed) - (7 * awayDefensiveTDs) - (2 * awaySafeties);
            homeAdjustedPointsAllowed = (homeAdjustedPointsAllowed < 0 ? 0 : homeAdjustedPointsAllowed);
            var homePtsPointsAllowed = context.DefenseRangeConfigs.Where(drc => drc.StartRangeValue <= homeAdjustedPointsAllowed && drc.EndRangeValue >= homeAdjustedPointsAllowed).FirstOrDefault().PtsForRange;
            var awayAdjustedPointsAllowed = awayPointsAllowed - (7 * awayReturnTDsAllowed) - (7 * homeDefensiveTDs) - (2 * homeSafeties);
            awayAdjustedPointsAllowed = (awayAdjustedPointsAllowed < 0 ? 0 : awayAdjustedPointsAllowed);
            var awayPtsPointsAllowed = context.DefenseRangeConfigs.Where(drc => drc.StartRangeValue <= awayAdjustedPointsAllowed && drc.EndRangeValue >= awayAdjustedPointsAllowed).FirstOrDefault().PtsForRange;

            var homeDSTStat = new Stats
            {
                PlayerId = homeDST.NFLId,
                PlayerProfileId = homeDST.PlayerId,
                PlayerShortName = homeDST.Name,
                PlayerName = homeDST.Name,
                PlayerSeasonWeekId = gameExists.SeasonWeekId,
                PlayerGameId = gameExists.GameId,
                TotalPoints = 0
            };

            homeDSTStat.Statistic = new List<Stat>();
            homeDSTStat.Statistic.Add(new Stat { StatType = "Team Defense", StatName = "Pts Allowed", StatValue = homeAdjustedPointsAllowed, PointValue = homePtsPointsAllowed });
            if (homeDefensiveTDs > 0)
            {
                homeDSTStat.Statistic.Add(new Stat { StatType = "Team Defense", StatName = "Defensive TDs", StatValue = homeDefensiveTDs, PointValue = (homeDefensiveTDs * scDictionary["PtsPerDefensiveTD"]) });
            }

            if (homeSafeties > 0)
            {
                homeDSTStat.Statistic.Add(new Stat { StatType = "Team Defense", StatName = "Safeties", StatValue = homeSafeties, PointValue = (homeSafeties * scDictionary["PtsPerSafety"]) });

            }

            homeDSTStat.TotalPoints = homeDSTStat.Statistic.Sum(s => s.PointValue);

            gd.PlayerStats.Add(homeDSTStat);

            var awayDSTStat = new Stats
            {
                PlayerId = awayDST.NFLId,
                PlayerProfileId = awayDST.PlayerId,
                PlayerShortName = awayDST.Name,
                PlayerName = awayDST.Name,
                PlayerSeasonWeekId = gameExists.SeasonWeekId,
                PlayerGameId = gameExists.GameId,
                TotalPoints = 0
            };

            awayDSTStat.Statistic = new List<Stat>();
            awayDSTStat.Statistic.Add(new Stat { StatType = "Team Defense", StatName = "Pts Allowed", StatValue = awayAdjustedPointsAllowed, PointValue = awayPtsPointsAllowed });
            if (awayDefensiveTDs > 0)
            {
                awayDSTStat.Statistic.Add(new Stat { StatType = "Team Defense", StatName = "Defensive TDs", StatValue = awayDefensiveTDs, PointValue = (awayDefensiveTDs * scDictionary["PtsPerDefensiveTD"]) });
            }

            if (awaySafeties > 0)
            {
                awayDSTStat.Statistic.Add(new Stat { StatType = "Team Defense", StatName = "Safeties", StatValue = awaySafeties, PointValue = (awaySafeties * scDictionary["PtsPerSafety"]) });
            }

            awayDSTStat.TotalPoints = awayDSTStat.Statistic.Sum(s => s.PointValue);

            gd.PlayerStats.Add(awayDSTStat);

            #endregion

            return gd;
        }