Esempio n. 1
0
        public bool UpdateGames(string updategames)
        {
            bool success = true;

            foreach (var sweek in seasonWeeks)
            {
                var season = Convert.ToInt32(sweek.Split('-')[0].Trim());
                var stype = sweek.Split('-')[1].Trim();
                var week = Convert.ToInt32(sweek.Split('-')[2].Trim());
                
                var xml = HelperMethods.LoadHtmlFromUrl(string.Format("http://www.nfl.com/ajax/scorestrip?season={0}&seasonType={1}&week={2}", season, stype, week));
                var gameXml = XDocument.Parse(xml);

                if (gameXml.Descendants("g").Count() > 0)
                {
                    #region Insert Season Week
                    var seasonWeekExists = context.SeasonWeeks.Where(sw => sw.SeasonWeekId == sweek).FirstOrDefault();

                    if (seasonWeekExists == null)
                    {
                        seasonWeekExists = new SeasonWeek();
                        seasonWeekExists.SeasonWeekId = sweek;
                        seasonWeekExists.SeasonYear = season;
                        seasonWeekExists.SeasonType = stype;
                        seasonWeekExists.SeasonWeekNum = week;
                        seasonWeekExists.StartDtm = DateTime.Now;
                        seasonWeekExists.EndDtm = DateTime.Now;
                        context.SeasonWeeks.InsertOnSubmit(seasonWeekExists);
                    }
                    context.SubmitChanges(); 
                    #endregion

                    #region Insert Games
                    foreach (var game in gameXml.Descendants("g"))
                    {
                        var gameId = Convert.ToInt32(game.Attribute("eid").Value);
                        var gameYear = Convert.ToInt32(gameId.ToString().Substring(0, 4));
                        var gameMonth = Convert.ToInt32(gameId.ToString().Substring(4, 2));
                        var gameDay = Convert.ToInt32(gameId.ToString().Substring(6, 2));
                        var gameTime = game.Attribute("t").Value;
                        var gameHour = Convert.ToInt32(gameTime.Split(':')[0].Trim());
                        var gameMinute = Convert.ToInt32(gameTime.Split(':')[1].Trim());

                        var gameExists = context.Games.Where(g => g.GameId == gameId).FirstOrDefault();
                        if (gameExists == null)
                        {
                            Game g = new Game();
                            g.GameId = gameId;
                            g.ESPNId = 0;
                            g.SeasonWeekId = sweek;
                            g.HomeTeamId = game.Attribute("h").Value.ToLower();
                            g.AwayTeamId = game.Attribute("v").Value.ToLower();
                            g.GameDtm = new DateTime(gameYear, gameMonth, gameDay, gameHour, gameMinute, 0);
                            context.Games.InsertOnSubmit(g);
                        }
                    }

                    context.SubmitChanges(); 
                    #endregion

                    #region Update Start & End Dtm
                    var firstGame = seasonWeekExists.Games.OrderBy(g => g.GameDtm).FirstOrDefault();
                    var lastGame = seasonWeekExists.Games.OrderByDescending(g => g.GameDtm).FirstOrDefault();
                    var dt = firstGame.GameDtm;
                    while (dt.DayOfWeek != DayOfWeek.Wednesday) dt = dt.AddDays(-1);
                    seasonWeekExists.StartDtm = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
                    dt = lastGame.GameDtm;
                    while (dt.DayOfWeek != DayOfWeek.Tuesday) dt = dt.AddDays(1);
                    seasonWeekExists.EndDtm = new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59);
                    context.SubmitChanges(); 
                    #endregion
                }
            }

            return success;
        }
Esempio n. 2
0
 partial void UpdateGame(Game instance);
Esempio n. 3
0
 partial void DeleteGame(Game instance);
Esempio n. 4
0
 partial void InsertGame(Game instance);
Esempio n. 5
0
		private void detach_Games1(Game entity)
		{
			this.SendPropertyChanging();
			entity.HomeTeam = null;
		}
Esempio n. 6
0
		private void attach_Games1(Game entity)
		{
			this.SendPropertyChanging();
			entity.HomeTeam = this;
		}
Esempio n. 7
0
		private void detach_Games(Game entity)
		{
			this.SendPropertyChanging();
			entity.SeasonWeek = null;
		}
Esempio n. 8
0
		private void attach_Games(Game entity)
		{
			this.SendPropertyChanging();
			entity.SeasonWeek = this;
		}