Exemple #1
0
        //
        // GET: /Nhl/Draft/

        public ActionResult Index()
        {
            int draftYear = 2008;

            List <NhlPlayerStatsBioSkaterViewModel> viewModel;

            using (SportsDataContext db = new SportsDataContext())
            {
                IEnumerable <NhlPlayerStatsBioSkaterViewModel> queryResult =
                    from player in db.Nhl_Players_Bio_Skater_DbSet
                    where player.NhlSeasonType == NhlSeasonType.RegularSeason
                    group player by new { player.Name, player.DraftYear } into playerGroup
                                                               select new NhlPlayerStatsBioSkaterViewModel
                {
                    Name              = playerGroup.Key.Name,
                    DraftYear         = playerGroup.Key.DraftYear,
                    SeasonsPlayed     = playerGroup.Count(),
                    AvgGamesPerSeason = Math.Round(playerGroup.Average(p => p.GamesPlayed), 1),
                    TotalGamesPlayed  = playerGroup.Sum(p => p.GamesPlayed)
                };

                viewModel = queryResult.ToList();
            }

            return(View(viewModel));
        }
Exemple #2
0
        public static void UpdateSeason([Optional] int year, [Optional] bool forceOverwrite)
        {
            year = NhlModelHelper.SetDefaultYear(year);

            List <Nhl_Games_Rtss> models;

            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_DbSet
                          where
                          m.Year == year
                          select m).ToList();
            }

            // Retrieve the links of the blobs
            Dictionary <Uri, string> summaryItems = new Dictionary <Uri, string>();
            Dictionary <Uri, string> rosterItems  = new Dictionary <Uri, string>();

            foreach (Nhl_Games_Rtss m in models)
            {
                // Game Summary
                if (Uri.IsWellFormedUriString(m.GameLink, UriKind.Absolute))
                {
                    summaryItems.Add(new Uri(m.GameLink), m.Id.ToString());
                }

                // Roster
                if (Uri.IsWellFormedUriString(m.RosterLink, UriKind.Absolute))
                {
                    rosterItems.Add(new Uri(m.RosterLink), m.Id.ToString());
                }
            }
            HtmlBlob.GetAndStoreHtmlBlobs(HtmlBlobType.NhlGame, summaryItems, forceOverwrite);
            HtmlBlob.GetAndStoreHtmlBlobs(HtmlBlobType.NhlRoster, rosterItems, forceOverwrite);
        }
        public ActionResult Index(bool update = false)
        {
            ViewBag.GetLatest = update; // specifies if we should show the update button

            List <FacebookSnapshot> latestSnapshots = new List <FacebookSnapshot>();

            using (SportsDataContext db = new SportsDataContext())
            {
                FacebookSnapshot latestSnapshot = (from d in db.FacebookSnapshot_DbSet
                                                   orderby d.DateOfSnapshot descending
                                                   select d).FirstOrDefault();

                if (null != latestSnapshot)
                {
                    DateTime latestDate = latestSnapshot.DateOfSnapshot;

                    IEnumerable <FacebookSnapshot> results = from s in db.FacebookSnapshot_DbSet.Include(x => x.FacebookAccount)
                                                             where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(latestDate)
                                                             //&& !s.FacebookAccountId.Equals("NhlToSeattle", StringComparison.InvariantCultureIgnoreCase)
                                                             //&& !s.FacebookAccountId.Equals("Nhl", StringComparison.InvariantCultureIgnoreCase)
                                                             orderby s.FacebookAccount.FriendlyName
                                                             select s;

                    latestSnapshots = results.ToList();
                }
            }

            return(Result(latestSnapshots));
        }
Exemple #4
0
        public void FacebookUpdateSnapshotsInDb()
        {
            List <FacebookAccount> accounts = new List <FacebookAccount>();

            accounts.Add(new FacebookAccount {
                Id = "NHLBruins", FriendlyName = "Boston Bruins"
            });
            accounts.Add(new FacebookAccount {
                Id = "torontomapleleafs", FriendlyName = "Toronto Maple Leafs"
            });

            List <FacebookSnapshot> snapshots = FacebookData.UpdateSnapshotsInDb(accounts);

            Assert.AreEqual(2, snapshots.Count, "There are 2 snapshots");

            // Call Update again to make sure dupes are added
            snapshots = FacebookData.UpdateSnapshotsInDb(accounts);

            // Make sure we have the right items in the db
            using (SportsDataContext db = new SportsDataContext())
            {
                List <FacebookSnapshot> snapshotsFromToday = (from s in db.FacebookSnapshot_DbSet.Include(x => x.FacebookAccount)
                                                              where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(DateTime.UtcNow)
                                                              orderby s.FacebookAccount.Id
                                                              select s).ToList();


                Assert.AreEqual(2, snapshotsFromToday.Count, "There are 2 snapshots, not 4");
                Assert.AreEqual(DateTime.UtcNow.Date, snapshotsFromToday[0].DateOfSnapshot.Date, "The snapshots are from today");
                Assert.AreEqual(snapshotsFromToday[0].DateOfSnapshot.Date, snapshotsFromToday[1].DateOfSnapshot.Date, "The snapshots are equal");
                Assert.AreEqual("NHLBruins", snapshotsFromToday[0].FacebookAccount.Id, "The first snapshot is from NHLBruins");
                Assert.AreEqual("torontomapleleafs", snapshotsFromToday[1].FacebookAccount.Id, "The first snapshot is from torontomapleleafs");
            }
        }
        public static List<MlbGameSummaryModel> UpdateSeason(MlbSeasonType mlbSeasonType, int seasonYear)
        {
            // Get latest results
            List<MlbGameSummaryModel> gamesToAdd = MlbAttendanceQuery.GetSeason(mlbSeasonType, seasonYear);

            // Remove existing results from DB and save new ones
            using (SportsDataContext db = new SportsDataContext())
            {
                IEnumerable<MlbGameSummaryModel> gamesToRemove = from g in db.MlbGameSummaryModel_DbSet
                                                            where g.MlbSeasonType == mlbSeasonType && g.Year == seasonYear
                                                            select g;

                foreach (MlbGameSummaryModel gameToRemove in gamesToRemove)
                {
                    db.MlbGameSummaryModel_DbSet.Remove(gameToRemove);
                }

                foreach (MlbGameSummaryModel gameToAdd in gamesToAdd)
                {
                    db.MlbGameSummaryModel_DbSet.Add(gameToAdd);
                }

                db.SaveChanges();
            }

            return gamesToAdd;
        }
Exemple #6
0
        public static List<TwitterSnapshot> UpdateSnapshotsInDb(List<TwitterAccount> accounts)
        {
            // Get latest results
            List<TwitterSnapshot> snapshots = TwitterQuery.GetTwitterSnapshots(accounts);

            // Remove existing results from DB from today and save new ones
            using (SportsDataContext db = new SportsDataContext())
            {
                IEnumerable<TwitterSnapshot> snapshotsToRemove = from s in db.TwitterSnapshot_DbSet
                                                                 where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(DateTime.UtcNow)
                                                            select s;

                foreach (TwitterSnapshot snapshotToRemove in snapshotsToRemove)
                {
                    db.TwitterSnapshot_DbSet.Remove(snapshotToRemove);
                }

                //db.SaveChanges();

                foreach (TwitterSnapshot snapshotToAdd in snapshots)
                {
                    db.TwitterSnapshot_DbSet.Add(snapshotToAdd);
                }

                db.SaveChanges();
            }

            return snapshots;
        }
Exemple #7
0
        public void TwitterUpdateSnapshotsInDb()
        {
            List<TwitterAccount> twitterAccounts = new List<TwitterAccount>();
            twitterAccounts.Add(new TwitterAccount { Id = "MapleLeafs", FriendlyName = "Toronto Maple Leafs" });
            twitterAccounts.Add(new TwitterAccount { Id = "phoenixcoyotes", FriendlyName = "Phoenix Coyotes" });

            List<TwitterSnapshot> twitterAccountSnapshots = TwitterData.UpdateSnapshotsInDb(twitterAccounts);
            Assert.AreEqual(2, twitterAccountSnapshots.Count, "There are 2 snapshots");

            // Call Update again to make sure dupes are added
            twitterAccountSnapshots = TwitterData.UpdateSnapshotsInDb(twitterAccounts);

            // Make sure we have the right items in the db
            using (SportsDataContext db = new SportsDataContext())
            {
                List<TwitterSnapshot> snapshotsFromToday = (from s in db.TwitterSnapshot_DbSet.Include(x => x.TwitterAccount)
                                                            where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(DateTime.UtcNow)
                                                                  orderby s.TwitterAccount.Id
                                                                  select s).ToList();

                Assert.AreEqual(2, snapshotsFromToday.Count, "There are 2 snapshots, not 4");
                Assert.AreEqual(DateTime.UtcNow.Date, snapshotsFromToday[0].DateOfSnapshot.Date, "The snapshots are from today");
                Assert.AreEqual(snapshotsFromToday[0].DateOfSnapshot.Date, snapshotsFromToday[1].DateOfSnapshot.Date, "The snapshots are equal");
                Assert.AreEqual("MapleLeafs", snapshotsFromToday[0].TwitterAccount.Id, "The first snapshot is from MapleLeafs");
                Assert.AreEqual("phoenixcoyotes", snapshotsFromToday[1].TwitterAccount.Id, "The first snapshot is from phoenixcoyotes");
            }
        }
        public static List<MlbGameSummaryModel> UpdateSeasonForTeam(MlbSeasonType mlbSeasonType, MlbTeamShortName mlbTeam, int seasonYear)
        {
            // Get latest results
            List<MlbGameSummaryModel> gamesToAdd = MlbAttendanceQuery.GetSeasonForTeam(mlbSeasonType, mlbTeam, seasonYear);

            // Remove existing results from DB and save new ones
            using (SportsDataContext db = new SportsDataContext())
            {
                string mlbTeamString = mlbTeam.ToString(); // http://stackoverflow.com/questions/5899683/linq-to-entities-does-not-recognize-the-method-system-string-tostring-method
                var gamesToRemove = from g in db.MlbGameSummaryModel_DbSet
                                    where g.MlbSeasonType == mlbSeasonType &&
                                          g.Year == seasonYear &&
                                          g.Home.Equals(mlbTeamString, StringComparison.InvariantCultureIgnoreCase)
                                    select g;

                foreach (MlbGameSummaryModel gameToRemove in gamesToRemove)
                {
                    db.MlbGameSummaryModel_DbSet.Remove(gameToRemove);
                }

                if (null != gamesToAdd)
                {
                    foreach (MlbGameSummaryModel gameToAdd in gamesToAdd)
                    {
                        db.MlbGameSummaryModel_DbSet.Add(gameToAdd);
                    }
                }

                db.SaveChanges();
            }

            return gamesToAdd;
        }
Exemple #9
0
        public void TwitterUpdateSnapshotsInDb()
        {
            List <TwitterAccount> twitterAccounts = new List <TwitterAccount>();

            twitterAccounts.Add(new TwitterAccount {
                Id = "MapleLeafs", FriendlyName = "Toronto Maple Leafs"
            });
            twitterAccounts.Add(new TwitterAccount {
                Id = "phoenixcoyotes", FriendlyName = "Phoenix Coyotes"
            });

            List <TwitterSnapshot> twitterAccountSnapshots = TwitterData.UpdateSnapshotsInDb(twitterAccounts);

            Assert.AreEqual(2, twitterAccountSnapshots.Count, "There are 2 snapshots");

            // Call Update again to make sure dupes are added
            twitterAccountSnapshots = TwitterData.UpdateSnapshotsInDb(twitterAccounts);

            // Make sure we have the right items in the db
            using (SportsDataContext db = new SportsDataContext())
            {
                List <TwitterSnapshot> snapshotsFromToday = (from s in db.TwitterSnapshot_DbSet.Include(x => x.TwitterAccount)
                                                             where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(DateTime.UtcNow)
                                                             orderby s.TwitterAccount.Id
                                                             select s).ToList();


                Assert.AreEqual(2, snapshotsFromToday.Count, "There are 2 snapshots, not 4");
                Assert.AreEqual(DateTime.UtcNow.Date, snapshotsFromToday[0].DateOfSnapshot.Date, "The snapshots are from today");
                Assert.AreEqual(snapshotsFromToday[0].DateOfSnapshot.Date, snapshotsFromToday[1].DateOfSnapshot.Date, "The snapshots are equal");
                Assert.AreEqual("MapleLeafs", snapshotsFromToday[0].TwitterAccount.Id, "The first snapshot is from MapleLeafs");
                Assert.AreEqual("phoenixcoyotes", snapshotsFromToday[1].TwitterAccount.Id, "The first snapshot is from phoenixcoyotes");
            }
        }
Exemple #10
0
 public void TwitterAccountsSeededTest()
 {
     using (SportsDataContext db = new SportsDataContext())
     {
         Assert.IsTrue(db.TwitterAccount_DbSet.Count() > 0, "There more than 0 twitter accounts seeded");
     }
 }
        public static List <MlbGameSummaryModel> UpdateSeasonForTeam(MlbSeasonType mlbSeasonType, MlbTeamShortName mlbTeam, int seasonYear)
        {
            // Get latest results
            List <MlbGameSummaryModel> gamesToAdd = MlbAttendanceQuery.GetSeasonForTeam(mlbSeasonType, mlbTeam, seasonYear);

            // Remove existing results from DB and save new ones
            using (SportsDataContext db = new SportsDataContext())
            {
                string mlbTeamString = mlbTeam.ToString(); // http://stackoverflow.com/questions/5899683/linq-to-entities-does-not-recognize-the-method-system-string-tostring-method
                var    gamesToRemove = from g in db.MlbGameSummaryModel_DbSet
                                       where g.MlbSeasonType == mlbSeasonType &&
                                       g.Year == seasonYear &&
                                       g.Home.Equals(mlbTeamString, StringComparison.InvariantCultureIgnoreCase)
                                       select g;

                foreach (MlbGameSummaryModel gameToRemove in gamesToRemove)
                {
                    db.MlbGameSummaryModel_DbSet.Remove(gameToRemove);
                }

                if (null != gamesToAdd)
                {
                    foreach (MlbGameSummaryModel gameToAdd in gamesToAdd)
                    {
                        db.MlbGameSummaryModel_DbSet.Add(gameToAdd);
                    }
                }

                db.SaveChanges();
            }

            return(gamesToAdd);
        }
        public static List <MlbGameSummaryModel> UpdateSeason(MlbSeasonType mlbSeasonType, int seasonYear)
        {
            // Get latest results
            List <MlbGameSummaryModel> gamesToAdd = MlbAttendanceQuery.GetSeason(mlbSeasonType, seasonYear);

            // Remove existing results from DB and save new ones
            using (SportsDataContext db = new SportsDataContext())
            {
                IEnumerable <MlbGameSummaryModel> gamesToRemove = from g in db.MlbGameSummaryModel_DbSet
                                                                  where g.MlbSeasonType == mlbSeasonType && g.Year == seasonYear
                                                                  select g;

                foreach (MlbGameSummaryModel gameToRemove in gamesToRemove)
                {
                    db.MlbGameSummaryModel_DbSet.Remove(gameToRemove);
                }

                foreach (MlbGameSummaryModel gameToAdd in gamesToAdd)
                {
                    db.MlbGameSummaryModel_DbSet.Add(gameToAdd);
                }

                db.SaveChanges();
            }

            return(gamesToAdd);
        }
Exemple #13
0
 public void FacebookAccountsSeededTest()
 {
     using (SportsDataContext db = new SportsDataContext())
     {
         Assert.IsTrue(db.TwitterAccount_DbSet.Count() > 0, "There are more than 0 accounts seeded");
     }
 }
Exemple #14
0
        public void FacebookUpdateSnapshotsInDb()
        {
            List<FacebookAccount> accounts = new List<FacebookAccount>();
            accounts.Add(new FacebookAccount { Id = "NHLBruins", FriendlyName = "Boston Bruins" });
            accounts.Add(new FacebookAccount { Id = "torontomapleleafs", FriendlyName = "Toronto Maple Leafs" });

            List<FacebookSnapshot> snapshots = FacebookData.UpdateSnapshotsInDb(accounts);
            Assert.AreEqual(2, snapshots.Count, "There are 2 snapshots");

            // Call Update again to make sure dupes are added
            snapshots = FacebookData.UpdateSnapshotsInDb(accounts);

            // Make sure we have the right items in the db
            using (SportsDataContext db = new SportsDataContext())
            {
                List<FacebookSnapshot> snapshotsFromToday = (from s in db.FacebookSnapshot_DbSet.Include(x => x.FacebookAccount)
                                                             where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(DateTime.UtcNow)
                                                                   orderby s.FacebookAccount.Id
                                                                   select s).ToList();

                Assert.AreEqual(2, snapshotsFromToday.Count, "There are 2 snapshots, not 4");
                Assert.AreEqual(DateTime.UtcNow.Date, snapshotsFromToday[0].DateOfSnapshot.Date, "The snapshots are from today");
                Assert.AreEqual(snapshotsFromToday[0].DateOfSnapshot.Date, snapshotsFromToday[1].DateOfSnapshot.Date, "The snapshots are equal");
                Assert.AreEqual("NHLBruins", snapshotsFromToday[0].FacebookAccount.Id, "The first snapshot is from NHLBruins");
                Assert.AreEqual("torontomapleleafs", snapshotsFromToday[1].FacebookAccount.Id, "The first snapshot is from torontomapleleafs");
            }
        }
Exemple #15
0
        public static List <TwitterSnapshot> UpdateSnapshotsInDb(List <TwitterAccount> accounts)
        {
            // Get latest results
            List <TwitterSnapshot> snapshots = TwitterQuery.GetTwitterSnapshots(accounts);

            // Remove existing results from DB from today and save new ones
            using (SportsDataContext db = new SportsDataContext())
            {
                IEnumerable <TwitterSnapshot> snapshotsToRemove = from s in db.TwitterSnapshot_DbSet
                                                                  where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(DateTime.UtcNow)
                                                                  select s;

                foreach (TwitterSnapshot snapshotToRemove in snapshotsToRemove)
                {
                    db.TwitterSnapshot_DbSet.Remove(snapshotToRemove);
                }

                //db.SaveChanges();

                foreach (TwitterSnapshot snapshotToAdd in snapshots)
                {
                    db.TwitterSnapshot_DbSet.Add(snapshotToAdd);
                }

                db.SaveChanges();
            }

            return(snapshots);
        }
        public ActionResult Index(bool update = false)
        {
            ViewBag.GetLatest = update; // specifies if we should show the update button

            List<FacebookSnapshot> latestSnapshots = new List<FacebookSnapshot>();

            using (SportsDataContext db = new SportsDataContext())
            {
                FacebookSnapshot latestSnapshot = (from d in db.FacebookSnapshot_DbSet
                                  orderby d.DateOfSnapshot descending
                                  select d).FirstOrDefault();

                if (null != latestSnapshot)
                {
                    DateTime latestDate = latestSnapshot.DateOfSnapshot;

                    IEnumerable<FacebookSnapshot> results = from s in db.FacebookSnapshot_DbSet.Include(x => x.FacebookAccount)
                                                            where DbFunctions.TruncateTime(s.DateOfSnapshot) == DbFunctions.TruncateTime(latestDate)
                                                                  //&& !s.FacebookAccountId.Equals("NhlToSeattle", StringComparison.InvariantCultureIgnoreCase)
                                                                  //&& !s.FacebookAccountId.Equals("Nhl", StringComparison.InvariantCultureIgnoreCase)
                                                                  orderby s.FacebookAccount.FriendlyName
                                                                  select s;

                    latestSnapshots = results.ToList();
                }
            }

            return Result(latestSnapshots);
        }
Exemple #17
0
 private static void AddOrUpdateDb(List <Nhl_Players_Bio_Goalie> models)
 {
     using (SportsDataContext db = new SportsDataContext())
     {
         db.Nhl_Players_Bio_Goalie_DbSet.AddOrUpdate <Nhl_Players_Bio_Goalie>(p => new { p.NhlSeasonType, p.Name, p.Year, p.Team }, models.ToArray());
         db.SaveChanges();
     }
 }
 private static void AddOrUpdateDb(List<Nhl_Players_Bio_Goalie> models)
 {
     using (SportsDataContext db = new SportsDataContext())
     {
         db.Nhl_Players_Bio_Goalie_DbSet.AddOrUpdate<Nhl_Players_Bio_Goalie>(p => new { p.NhlSeasonType, p.Name, p.Year, p.Team }, models.ToArray());
         db.SaveChanges();
     }
 }
Exemple #19
0
 private static void AddOrUpdateDb(List <Nhl_Draftbook> models)
 {
     using (SportsDataContext db = new SportsDataContext())
     {
         db.Database.ExecuteSqlCommand("DELETE FROM NhlDraftbookModels");
         db.Nhl_Draftbook_DbSet.AddRange(models);
         db.SaveChanges();
     }
 }
Exemple #20
0
 private static void AddOrUpdateDb(List<Nhl_Draftbook> models)
 {
     using (SportsDataContext db = new SportsDataContext())
     {
         db.Database.ExecuteSqlCommand("DELETE FROM NhlDraftbookModels");
         db.Nhl_Draftbook_DbSet.AddRange(models);
         db.SaveChanges();
     }
 }
Exemple #21
0
        public static List<FacebookSnapshot> UpdateAllSnapshotsInDb()
        {
            List<FacebookAccount> accounts = new List<FacebookAccount>();
            using (SportsDataContext db = new SportsDataContext())
            {
                accounts = db.FacebookAccount_DbSet.ToList();
            }

            return FacebookData.UpdateSnapshotsInDb(accounts);
        }
Exemple #22
0
        public static List<TwitterSnapshot> UpdateAllSnapshotsInDb()
        {
            List<TwitterAccount> accounts = new List<TwitterAccount>();
            using (SportsDataContext db = new SportsDataContext())
            {
                accounts = db.TwitterAccount_DbSet.ToList();
            }

            return TwitterData.UpdateSnapshotsInDb(accounts);
        }
        public void NhlHtmlReport_ParseFrenchRegSeasonAndPersist()
        {
            string path = @"C:\Users\jordanf\Google Drive\Coding\Sportsdata\TestData\FrenchRegSeasonRoster_formatted.htm";
            string html = File.ReadAllText(path);

            Nhl_Games_Rtss_Roster model = NhlGamesRtssRoster.ParseHtmlBlob(-1, html);

            using (SportsDataContext db = new SportsDataContext())
            {
                db.Nhl_Games_Rtss_Roster_DbSet.AddOrUpdate(
                    m => m.Id,
                    model);
                db.SaveChanges();

                model = db.Nhl_Games_Rtss_Roster_DbSet.FirstOrDefault(m => m.Id == model.Id);
                model.VisitorRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "visitor player 1" });
                model.VisitorRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "visitor player 2" });
                model.VisitorScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "visitor scratch 1" });
                model.VisitorScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "visitor scratch 2" });
                model.VisitorHeadCoach.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "visitor head coach 1" });

                model.HomeRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "home player 1" });
                model.HomeRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "home player 2" });
                model.HomeScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "home scratch 1" });
                model.HomeScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "home scratch 2" });
                model.HomeHeadCoach.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "home head coach 1" });

                model.Referees.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "referee 1" });
                model.Referees.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "referee 2" });
                model.Linesman.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "linesman 1" });
                model.Linesman.Add(new Nhl_Games_Rtss_RosterParticipantItem { Name = "linesman 2" });

                db.Nhl_Games_Rtss_Roster_DbSet.AddOrUpdate(
                    m => m.Id,
                    model);

                db.SaveChanges();
            }

            List<Nhl_Games_Rtss_Roster> models;
            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_Roster_DbSet
                              .Include(x => x.VisitorRoster)
                              .Include(x => x.VisitorScratches)
                              .Include(x => x.VisitorHeadCoach)
                              .Include(x => x.HomeRoster)
                              .Include(x => x.HomeScratches)
                              .Include(x => x.HomeHeadCoach)
                              .Include(x => x.Referees)
                              .Include(x => x.Linesman)
                          select m).ToList();

            }
        }
Exemple #24
0
        public static List <FacebookSnapshot> UpdateAllSnapshotsInDb()
        {
            List <FacebookAccount> accounts = new List <FacebookAccount>();

            using (SportsDataContext db = new SportsDataContext())
            {
                accounts = db.FacebookAccount_DbSet.ToList();
            }

            return(FacebookData.UpdateSnapshotsInDb(accounts));
        }
 // GET: Hockey/Penalties/Details/5
 public ActionResult Details(int year)
 {
     List<Nhl_Games_Rtss_Summary> model;
     using (SportsDataContext db = new SportsDataContext())
     {
         model = (from game in db.Nhl_Games_Rtss_Summary_DbSet
                 where game.Date.Year == year
                 select game).ToList();
     }
     return View(model);
 }
Exemple #26
0
        public static List <TwitterSnapshot> UpdateAllSnapshotsInDb()
        {
            List <TwitterAccount> accounts = new List <TwitterAccount>();

            using (SportsDataContext db = new SportsDataContext())
            {
                accounts = db.TwitterAccount_DbSet.ToList();
            }

            return(TwitterData.UpdateSnapshotsInDb(accounts));
        }
        // GET: Hockey/Penalties/Details/5
        public ActionResult Details(int year)
        {
            List <Nhl_Games_Rtss_Summary> model;

            using (SportsDataContext db = new SportsDataContext())
            {
                model = (from game in db.Nhl_Games_Rtss_Summary_DbSet
                         where game.Date.Year == year
                         select game).ToList();
            }
            return(View(model));
        }
        /// <summary>
        /// Get all the results starting from the last date of the data in the db. If a year is specified then only get latest for that year.
        /// </summary>
        /// <param name="year"></param>
        public static List<Nhl_Games_Summary> GetNewResultsOnly([Optional] int year, [Optional] bool saveToDb)
        {
            DateTime latestResultDate;
            using (SportsDataContext db = new SportsDataContext())
            {
                latestResultDate = (from m in db.Nhl_Games_Summary_DbSet
                                    orderby m.Date descending
                                    select m.Date).FirstOrDefault();

            }

            return NhlGamesSummary.GetFullSeason(year, latestResultDate, saveToDb);
        }
Exemple #29
0
        /// <summary>
        /// Get all the results starting from the last date of the data in the db. If a year is specified then only get latest for that year.
        /// </summary>
        /// <param name="year"></param>
        public static List <Nhl_Games_Summary> GetNewResultsOnly([Optional] int year, [Optional] bool saveToDb)
        {
            DateTime latestResultDate;

            using (SportsDataContext db = new SportsDataContext())
            {
                latestResultDate = (from m in db.Nhl_Games_Summary_DbSet
                                    orderby m.Date descending
                                    select m.Date).FirstOrDefault();
            }

            return(NhlGamesSummary.GetFullSeason(year, latestResultDate, saveToDb));
        }
        public static void UpdateDatabase(List <DemographicsModel> data)
        {
            Console.WriteLine("Saving {0} records", data.Count);

            using (SportsDataContext db = new SportsDataContext())
            {
                db.Demographic_DbSet.AddOrUpdate(x => x.Zip, data.ToArray());

                db.SaveChanges();
            }

            Console.WriteLine("Done saving {0} records", data.Count);
        }
        public static void UpdateDatabase(List<DemographicsModel> data)
        {
            Console.WriteLine("Saving {0} records", data.Count);

            using (SportsDataContext db = new SportsDataContext())
            {
                db.Demographic_DbSet.AddOrUpdate(x => x.Zip, data.ToArray());

                db.SaveChanges();
            }

            Console.WriteLine("Done saving {0} records", data.Count);
        }
        /// <summary>
        /// Get the RtssReports for the specified year
        /// </summary>
        public static List<Nhl_Games_Rtss> GetRtssReports([Optional] int year, [Optional] DateTime fromDate)
        {
            year = NhlModelHelper.SetDefaultYear(year);

            List<Nhl_Games_Rtss> models;
            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_DbSet
                          where
                             m.Year == year &&
                             m.Date >= fromDate
                          select m).ToList();
            }

            return models;
        }
Exemple #33
0
        private static void AddOrUpdateDb(List <Nhl_Games_Summary> models)
        {
            // Note: downcast for models is not necessary but leave this here in anticipation of moving this method to a base class (and it will be necessary)

            // Special case the FLA/NSH double header on 9/16/2013
            IEnumerable <Nhl_Games_BaseModel> specialCaseModels         = NhlGamesBaseClass.GetSpecialCaseModels(models);
            IEnumerable <Nhl_Games_Summary>   downcastSpecialCaseModels = specialCaseModels.ToList().ConvertAll <Nhl_Games_Summary>(m => (Nhl_Games_Summary)m);
            IEnumerable <Nhl_Games_Summary>   downcastModels            = models.Except(specialCaseModels, new NhlGameStatsBaseModelComparer()).ToList().ConvertAll <Nhl_Games_Summary>(m => (Nhl_Games_Summary)m);

            using (SportsDataContext db = new SportsDataContext())
            {
                db.Nhl_Games_Summary_DbSet.AddOrUpdate <Nhl_Games_Summary>(g => new { g.Date, g.Visitor, g.Home, g.VisitorScore, g.HomeScore }, downcastSpecialCaseModels.ToArray());
                db.Nhl_Games_Summary_DbSet.AddOrUpdate <Nhl_Games_Summary>(g => new { g.Date, g.Visitor, g.Home }, downcastModels.ToArray());
                db.SaveChanges();
            }
        }
        private static void AddOrUpdateDb(List<Nhl_Games_Summary> models)
        {
            // Note: downcast for models is not necessary but leave this here in anticipation of moving this method to a base class (and it will be necessary)

            // Special case the FLA/NSH double header on 9/16/2013
            IEnumerable<Nhl_Games_BaseModel> specialCaseModels = NhlGamesBaseClass.GetSpecialCaseModels(models);
            IEnumerable<Nhl_Games_Summary> downcastSpecialCaseModels = specialCaseModels.ToList().ConvertAll<Nhl_Games_Summary>(m => (Nhl_Games_Summary)m);
            IEnumerable<Nhl_Games_Summary> downcastModels = models.Except(specialCaseModels, new NhlGameStatsBaseModelComparer()).ToList().ConvertAll<Nhl_Games_Summary>(m => (Nhl_Games_Summary)m);

            using (SportsDataContext db = new SportsDataContext())
            {
                db.Nhl_Games_Summary_DbSet.AddOrUpdate<Nhl_Games_Summary>(g => new { g.Date, g.Visitor, g.Home, g.VisitorScore, g.HomeScore }, downcastSpecialCaseModels.ToArray());
                db.Nhl_Games_Summary_DbSet.AddOrUpdate<Nhl_Games_Summary>(g => new { g.Date, g.Visitor, g.Home }, downcastModels.ToArray());
                db.SaveChanges();
            }
        }
Exemple #35
0
        public void Mlb_UpdatePostSeasonForAllTeamsTest()
        {
            MlbSeasonType seasonType = MlbSeasonType.PostSeason;
            int           seasonYear = 2002;

            List <MlbGameSummaryModel> result = MlbAttendanceData.UpdateSeason(seasonType, seasonYear);

            // For some reason, the final game of the world series is not included
            Assert.AreEqual(33, result.Count, "Verify that there were 33 games");

            using (SportsDataContext db = new SportsDataContext())
            {
                Assert.AreEqual(33, db.MlbGameSummaryModel_DbSet.Where(g => g.MlbSeasonType == seasonType &&
                                                                       g.Year == seasonYear).Count(),
                                "Verify that there are 33 games in the db");
            }
        }
Exemple #36
0
        /// <summary>
        /// Get the RtssReports for the specified year
        /// </summary>
        public static List <Nhl_Games_Rtss> GetRtssReports([Optional] int year, [Optional] DateTime fromDate)
        {
            year = NhlModelHelper.SetDefaultYear(year);

            List <Nhl_Games_Rtss> models;

            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_DbSet
                          where
                          m.Year == year &&
                          m.Date >= fromDate
                          select m).ToList();
            }

            return(models);
        }
Exemple #37
0
        /// <summary>
        /// Get the NhlHtmlReportSummaryModels for the specified year
        /// </summary>
        private static List <Nhl_Games_Rtss_Summary> GetHtmlSummaryReports([Optional] int year, [Optional] DateTime fromDate)
        {
            year = NhlModelHelper.SetDefaultYear(year);

            List <Nhl_Games_Rtss_Summary> existingModels = new List <Nhl_Games_Rtss_Summary>();

            using (SportsDataContext db = new SportsDataContext())
            {
                existingModels = (from m in db.Nhl_Games_Rtss_Summary_DbSet
                                  where
                                  m.NhlRtssReportModel.Year == year &&
                                  m.NhlRtssReportModel.Date >= fromDate
                                  select m).ToList();
            }

            return(existingModels);
        }
Exemple #38
0
        public void Mlb_UpdateRegularSeasonForTeamTest()
        {
            MlbSeasonType    seasonType = MlbSeasonType.Regular;
            MlbTeamShortName teamName   = MlbTeamShortName.SD;
            int seasonYear = 2005;

            List <MlbGameSummaryModel> result = MlbAttendanceData.UpdateSeasonForTeam(seasonType, teamName, seasonYear);

            Assert.AreEqual(81, result.Count, "Verify that there are 81 home games returned");

            using (SportsDataContext db = new SportsDataContext())
            {
                string teamNameString = teamName.ToString(); // http://stackoverflow.com/questions/5899683/linq-to-entities-does-not-recognize-the-method-system-string-tostring-method
                Assert.AreEqual(81, db.MlbGameSummaryModel_DbSet.Where(g => g.MlbSeasonType == seasonType &&
                                                                       g.Home.Equals(teamNameString, StringComparison.InvariantCultureIgnoreCase) &&
                                                                       g.Year == seasonYear).Count(),
                                "Verify that there are 81 games in the db");
            }
        }
Exemple #39
0
        public ActionResult Index(int seasonYear = 0, bool update = false)
        {
            ViewBag.GetLatest = update;
            ViewBag.SeasonYear = seasonYear;

            List<Nhl_Games_Summary> games = new List<Nhl_Games_Summary>();
            if (seasonYear >= 1998) // check if it is a valid season and if so get the results
            {
                using (SportsDataContext db = new SportsDataContext())
                {
                    IEnumerable<Nhl_Games_Summary> results = from g in db.Nhl_Games_Summary_DbSet
                                                          where g.Year == seasonYear
                                                          orderby g.Date
                                                          select g;
                    games = results.ToList();
                }
            }

            return Result(games);
        }
Exemple #40
0
        private static string LookupShortName(string espnOpponentName)
        {
            MlbTeam mlbTeam = null;

            using (SportsDataContext db = new SportsDataContext())
            {
                mlbTeam = (from t in db.MlbTeam_DbSet.ToList()   // We need to use ToList() so we don't get 'ObjectContext instance has been disposed' error.
                           where t.EspnOpponentName.Equals(espnOpponentName, StringComparison.InvariantCulture)
                           select t).FirstOrDefault();
            }

            if (null == mlbTeam)
            {
                return(null);
            }
            else
            {
                return(mlbTeam.ShortNameId.ToString());
            }
        }
Exemple #41
0
        public ActionResult Index(int seasonYear = 0, bool update = false)
        {
            ViewBag.SeasonYear = seasonYear;
            ViewBag.GetLatest = update; // specifies if we should show the update button

            List<MlbGameSummaryModel> games = new List<MlbGameSummaryModel>();
            if (seasonYear >= 2002) // check if it is a valid season and if so get the results
            {
                using (SportsDataContext db = new SportsDataContext())
                {
                    IEnumerable<MlbGameSummaryModel> results = from g in db.MlbGameSummaryModel_DbSet
                                                          where g.Year == seasonYear
                                                          orderby g.Date
                                                          select g;
                    games = results.ToList();
                }
            }

            return Result(games);
        }
Exemple #42
0
        public ActionResult Index(int seasonYear = 0, bool update = false)
        {
            ViewBag.SeasonYear = seasonYear;
            ViewBag.GetLatest  = update; // specifies if we should show the update button

            List <MlbGameSummaryModel> games = new List <MlbGameSummaryModel>();

            if (seasonYear >= 2002) // check if it is a valid season and if so get the results
            {
                using (SportsDataContext db = new SportsDataContext())
                {
                    IEnumerable <MlbGameSummaryModel> results = from g in db.MlbGameSummaryModel_DbSet
                                                                where g.Year == seasonYear
                                                                orderby g.Date
                                                                select g;
                    games = results.ToList();
                }
            }

            return(Result(games));
        }
Exemple #43
0
        public ActionResult Index(int seasonYear = 0, bool update = false)
        {
            ViewBag.GetLatest  = update;
            ViewBag.SeasonYear = seasonYear;

            List <Nhl_Games_Summary> games = new List <Nhl_Games_Summary>();

            if (seasonYear >= 1998) // check if it is a valid season and if so get the results
            {
                using (SportsDataContext db = new SportsDataContext())
                {
                    IEnumerable <Nhl_Games_Summary> results = from g in db.Nhl_Games_Summary_DbSet
                                                              where g.Year == seasonYear
                                                              orderby g.Date
                                                              select g;
                    games = results.ToList();
                }
            }

            return(Result(games));
        }
Exemple #44
0
        public void HtmlBlob_Test()
        {
            List<Nhl_Games_Rtss> models;
            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_DbSet
                          where
                            (m.Home == "VANCOUVER" || m.Visitor == "VANCOUVER") &&
                            m.Date >= new DateTime(2014,1,29)
                          select m).ToList();
            }

            Dictionary<Uri, string> items = new Dictionary<Uri, string>();
            models.ForEach(m => items.Add(new Uri(m.RosterLink), m.Id.ToString()));
            HtmlBlob.GetAndStoreHtmlBlobs(HtmlBlobType.NhlRoster, items, false);

            foreach (Nhl_Games_Rtss model in models)
            {
                string html = HtmlBlob.RetrieveBlob(HtmlBlobType.NhlRoster, model.Id.ToString(), new Uri(model.RosterLink), true);
            }
        }
Exemple #45
0
        public static void GetDemographics()
        {
            // Try to read zips from app.config
            string zipCsv = ConfigurationManager.AppSettings["zipCodes"];

            List<int> allZipCodes = zipCsv.Replace(" ", String.Empty).Split(',').ToList().ConvertAll<int>(x => Convert.ToInt32(x));
            List<int> missingZipCodes = new List<int>(); //allZipCodes.GetRange(592, 1);
            using (SportsDataContext db = new SportsDataContext())
            {
                missingZipCodes = allZipCodes.Except(db.Demographic_DbSet.Select(z => z.Zip).ToList()).ToList();
            }

            if (missingZipCodes.Count == 0)
            {
                Console.WriteLine("All zip codes have been retrieved and stored in the database. To update existing zip code data, delete it from the database and re-run");
                Console.WriteLine("Zip codes in the list of zip codes to retrieve:");
                Console.WriteLine(allZipCodes);
            }

            List<DemographicsModel> results = DemographicsQuery.GetDemographics(missingZipCodes, false, 0);
            DemographicsData.UpdateDatabase(results);
        }
Exemple #46
0
        public void HtmlBlob_Test()
        {
            List <Nhl_Games_Rtss> models;

            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_DbSet
                          where
                          (m.Home == "VANCOUVER" || m.Visitor == "VANCOUVER") &&
                          m.Date >= new DateTime(2014, 1, 29)
                          select m).ToList();
            }

            Dictionary <Uri, string> items = new Dictionary <Uri, string>();

            models.ForEach(m => items.Add(new Uri(m.RosterLink), m.Id.ToString()));
            HtmlBlob.GetAndStoreHtmlBlobs(HtmlBlobType.NhlRoster, items, false);

            foreach (Nhl_Games_Rtss model in models)
            {
                string html = HtmlBlob.RetrieveBlob(HtmlBlobType.NhlRoster, model.Id.ToString(), new Uri(model.RosterLink), true);
            }
        }
Exemple #47
0
        public static void GetDemographics()
        {
            // Try to read zips from app.config
            string zipCsv = ConfigurationManager.AppSettings["zipCodes"];

            List <int> allZipCodes     = zipCsv.Replace(" ", String.Empty).Split(',').ToList().ConvertAll <int>(x => Convert.ToInt32(x));
            List <int> missingZipCodes = new List <int>(); //allZipCodes.GetRange(592, 1);

            using (SportsDataContext db = new SportsDataContext())
            {
                missingZipCodes = allZipCodes.Except(db.Demographic_DbSet.Select(z => z.Zip).ToList()).ToList();
            }

            if (missingZipCodes.Count == 0)
            {
                Console.WriteLine("All zip codes have been retrieved and stored in the database. To update existing zip code data, delete it from the database and re-run");
                Console.WriteLine("Zip codes in the list of zip codes to retrieve:");
                Console.WriteLine(allZipCodes);
            }

            List <DemographicsModel> results = DemographicsQuery.GetDemographics(missingZipCodes, false, 0);

            DemographicsData.UpdateDatabase(results);
        }
        public static void UpdateSeason([Optional] int year, [Optional] DateTime fromDate, [Optional] bool forceOverwrite)
        {
            // Initialize the rtss reports that we are going to read and parse
            List<Nhl_Games_Rtss> models = NhlHtmlReportBase.GetRtssReports(year, fromDate);
            List<Nhl_Games_Rtss_Roster> existingModels = null;
            if (forceOverwrite == false)
            {
                // Only query for existing if we are not going to force overwrite all
                existingModels = NhlGamesRtssRoster.GetHtmlRosterReports(year, fromDate);
            }

            // For each report, get the html blob from blob storage and parse the blob to a report
            List<Nhl_Games_Rtss_Roster> results = new List<Nhl_Games_Rtss_Roster>();
            foreach (Nhl_Games_Rtss model in models)
            {
                if (forceOverwrite == false && existingModels.Exists(m => m.NhlRtssReportModelId == model.Id))
                {
                    // In this case, only get data if it is not already populated
                    continue;
                }

                Nhl_Games_Rtss_Roster report = null;
                if (!model.GameLink.Equals("#"))
                {
                    string htmlBlob = HtmlBlob.RetrieveBlob(HtmlBlobType.NhlRoster, model.Id.ToString(), new Uri(model.RosterLink), true);
                    report = NhlGamesRtssRoster.ParseHtmlBlob(model.Id, htmlBlob);
                }

                if (null != report)
                {
                    results.Add(report);
                }
            }

            // Save the reports to the db 100 records at a time
            using (SportsDataContext db = new SportsDataContext())
            {
                int counter = 0;
                int totalCounter = 0;
                int batchSize = 10;
                foreach (Nhl_Games_Rtss_Roster model in results)
                {
                    Console.WriteLine("Start saving {0} to {1}", results.Count, db.Database.Connection.ConnectionString);

                    db.Configuration.AutoDetectChangesEnabled = false;
                    db.Configuration.ValidateOnSaveEnabled = false;

                    counter++;
                    totalCounter++;

                    if (model.Id != 0)
                    {
                        db.Nhl_Games_Rtss_Roster_DbSet.Attach(model);
                        db.Entry(model).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(model).State = EntityState.Added;
                    }

                    if (counter >= batchSize)
                    {
                        db.SaveChanges();
                        counter = 0;

                        Console.WriteLine("Saved {0} of {1}", totalCounter, results.Count);
                    }
                }

                db.SaveChanges();
                Console.WriteLine("Saved {0} of {1}", totalCounter, results.Count);
            }
        }
Exemple #49
0
        public static void UpdateSeason([Optional] int year, [Optional] DateTime fromDate, [Optional] bool forceOverwrite)
        {
            // Get the RtssReports for the specified year. Exclude recent games that may not be done (UtcNow - 1)
            List <Nhl_Games_Rtss>         models         = NhlHtmlReportBase.GetRtssReports(year, fromDate).Where(m => m.Date < DateTime.UtcNow.AddDays(-1).Date).ToList();
            List <Nhl_Games_Rtss_Summary> existingModels = null;

            if (forceOverwrite == false)
            {
                // Only query for existing if we are not going to force overwrite all
                existingModels = NhlGamesRtssSummary.GetHtmlSummaryReports(year, fromDate);
            }

            // For each report, get the html blob from blob storage and parse the blob to a report
            List <Nhl_Games_Rtss_Summary> results = new List <Nhl_Games_Rtss_Summary>();

            foreach (Nhl_Games_Rtss model in models)
            {
                if (forceOverwrite == false && existingModels.Exists(m => m.NhlRtssReportModelId == model.Id))
                {
                    // In this case, only get data if it is not already populated
                    continue;
                }

                Nhl_Games_Rtss_Summary report = null;
                if (!model.GameLink.Equals("#"))
                {
                    string htmlBlob = HtmlBlob.RetrieveBlob(HtmlBlobType.NhlRoster, model.Id.ToString(), new Uri(model.GameLink), true);
                    report = NhlGamesRtssSummary.ParseHtmlBlob(model.Id, htmlBlob);
                }

                if (null != report)
                {
                    results.Add(report);
                }
            }

            // Save the reports to the db
            using (SportsDataContext db = new SportsDataContext())
            {
                Console.WriteLine("Start saving {0} to {1}", results.Count, db.Database.Connection.ConnectionString);

                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;

                int counter      = 0;
                int totalCounter = 0;
                int batchSize    = 10;
                foreach (var model in results)
                {
                    counter++;
                    totalCounter++;

                    if (model.Id != 0)
                    {
                        db.Nhl_Games_Rtss_Summary_DbSet.Attach(model);
                        db.Entry(model).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(model).State = EntityState.Added;
                    }

                    if (counter >= batchSize)
                    {
                        db.SaveChanges();
                        counter = 0;

                        Console.WriteLine("Saved {0} of {1}", totalCounter, results.Count);
                    }
                }

                db.SaveChanges();
                Console.WriteLine("Saved {0} of {1}", totalCounter, results.Count);
            }
        }
        private static string LookupShortName(string espnOpponentName)
        {
            MlbTeam mlbTeam = null;
            using (SportsDataContext db = new SportsDataContext())
            {
                mlbTeam = (from t in db.MlbTeam_DbSet.ToList()   // We need to use ToList() so we don't get 'ObjectContext instance has been disposed' error.
                           where t.EspnOpponentName.Equals(espnOpponentName, StringComparison.InvariantCulture)
                           select t).FirstOrDefault();
            }

            if (null == mlbTeam)
            {
                return null;
            }
            else
            {
                return mlbTeam.ShortNameId.ToString();
            }
        }
Exemple #51
0
        public static void UpdateSeason([Optional] int year, [Optional] bool forceOverwrite)
        {
            year = NhlModelHelper.SetDefaultYear(year);

            List<Nhl_Games_Rtss> models;
            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_DbSet
                          where
                            m.Year == year
                          select m).ToList();
            }

            // Retrieve the links of the blobs
            Dictionary<Uri, string> summaryItems = new Dictionary<Uri, string>();
            Dictionary<Uri, string> rosterItems = new Dictionary<Uri, string>();
            foreach (Nhl_Games_Rtss m in models)
            {
                // Game Summary
                if (Uri.IsWellFormedUriString(m.GameLink, UriKind.Absolute))
                {
                    summaryItems.Add(new Uri(m.GameLink), m.Id.ToString());
                }

                // Roster
                if (Uri.IsWellFormedUriString(m.RosterLink, UriKind.Absolute))
                {
                    rosterItems.Add(new Uri(m.RosterLink), m.Id.ToString());
                }
            }
            HtmlBlob.GetAndStoreHtmlBlobs(HtmlBlobType.NhlGame, summaryItems, forceOverwrite);
            HtmlBlob.GetAndStoreHtmlBlobs(HtmlBlobType.NhlRoster, rosterItems, forceOverwrite);
        }
        public void NhlHtmlReport_ParseFrenchRegSeasonAndPersist()
        {
            string path = @"C:\Users\jordanf\Google Drive\Coding\Sportsdata\TestData\FrenchRegSeasonRoster_formatted.htm";
            string html = File.ReadAllText(path);

            Nhl_Games_Rtss_Roster model = NhlGamesRtssRoster.ParseHtmlBlob(-1, html);

            using (SportsDataContext db = new SportsDataContext())
            {
                db.Nhl_Games_Rtss_Roster_DbSet.AddOrUpdate(
                    m => m.Id,
                    model);
                db.SaveChanges();

                model = db.Nhl_Games_Rtss_Roster_DbSet.FirstOrDefault(m => m.Id == model.Id);
                model.VisitorRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "visitor player 1"
                });
                model.VisitorRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "visitor player 2"
                });
                model.VisitorScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "visitor scratch 1"
                });
                model.VisitorScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "visitor scratch 2"
                });
                model.VisitorHeadCoach.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "visitor head coach 1"
                });

                model.HomeRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "home player 1"
                });
                model.HomeRoster.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "home player 2"
                });
                model.HomeScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "home scratch 1"
                });
                model.HomeScratches.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "home scratch 2"
                });
                model.HomeHeadCoach.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "home head coach 1"
                });

                model.Referees.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "referee 1"
                });
                model.Referees.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "referee 2"
                });
                model.Linesman.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "linesman 1"
                });
                model.Linesman.Add(new Nhl_Games_Rtss_RosterParticipantItem {
                    Name = "linesman 2"
                });

                db.Nhl_Games_Rtss_Roster_DbSet.AddOrUpdate(
                    m => m.Id,
                    model);

                db.SaveChanges();
            }

            List <Nhl_Games_Rtss_Roster> models;

            using (SportsDataContext db = new SportsDataContext())
            {
                models = (from m in db.Nhl_Games_Rtss_Roster_DbSet
                          .Include(x => x.VisitorRoster)
                          .Include(x => x.VisitorScratches)
                          .Include(x => x.VisitorHeadCoach)
                          .Include(x => x.HomeRoster)
                          .Include(x => x.HomeScratches)
                          .Include(x => x.HomeHeadCoach)
                          .Include(x => x.Referees)
                          .Include(x => x.Linesman)
                          select m).ToList();
            }
        }
Exemple #53
0
        public void Mlb_UpdatePostSeasonForAllTeamsTest()
        {
            MlbSeasonType seasonType = MlbSeasonType.PostSeason;
            int seasonYear = 2002;

            List<MlbGameSummaryModel> result = MlbAttendanceData.UpdateSeason(seasonType, seasonYear);

            // For some reason, the final game of the world series is not included
            Assert.AreEqual(33, result.Count, "Verify that there were 33 games");

            using (SportsDataContext db = new SportsDataContext())
            {
                Assert.AreEqual(33, db.MlbGameSummaryModel_DbSet.Where(g => g.MlbSeasonType == seasonType &&
                                                                   g.Year == seasonYear).Count(),
                                "Verify that there are 33 games in the db");
            }
        }
Exemple #54
0
        public void Mlb_UpdateSpringSeasonForTeamTest()
        {
            MlbSeasonType seasonType = MlbSeasonType.Spring;
            MlbTeamShortName teamName = MlbTeamShortName.TOR;
            int seasonYear = 2006;

            List<MlbGameSummaryModel> result = MlbAttendanceData.UpdateSeasonForTeam(seasonType, teamName, seasonYear);

            Assert.AreEqual(15, result.Count, "Verify that there are 15 home games returned");

            using (SportsDataContext db = new SportsDataContext())
            {
                string teamNameString = teamName.ToString(); // http://stackoverflow.com/questions/5899683/linq-to-entities-does-not-recognize-the-method-system-string-tostring-method
                Assert.AreEqual(15, db.MlbGameSummaryModel_DbSet.Where(g => g.MlbSeasonType == seasonType &&
                                                                   g.Home.Equals(teamNameString, StringComparison.InvariantCultureIgnoreCase) &&
                                                                   g.Year == seasonYear).Count(),
                                "Verify that there are 15 games in the db");
            }
        }
        /// <summary>
        /// Get the NhlHtmlReportRosterModel for the specified year
        /// </summary>
        private static List<Nhl_Games_Rtss_Roster> GetHtmlRosterReports([Optional] int year, [Optional] DateTime fromDate)
        {
            year = NhlModelHelper.SetDefaultYear(year);

            List<Nhl_Games_Rtss_Roster> existingModels = new List<Nhl_Games_Rtss_Roster>();
            using (SportsDataContext db = new SportsDataContext())
            {
                existingModels = (from m in db.Nhl_Games_Rtss_Roster_DbSet
                                  where
                                      m.NhlRtssReportModel.Year == year &&
                                      m.NhlRtssReportModel.Date >= fromDate
                                  select m).ToList();
            }

            return existingModels;
        }
 public PlayerRepository()
 {
     _db = new SportsDataContext();
 }
        //
        // GET: /Nhl/Draft/
        public ActionResult Index()
        {
            int draftYear = 2008;

            List<NhlPlayerStatsBioSkaterViewModel> viewModel;
            using (SportsDataContext db = new SportsDataContext())
            {
                IEnumerable<NhlPlayerStatsBioSkaterViewModel> queryResult =
                        from player in db.Nhl_Players_Bio_Skater_DbSet
                        where player.NhlSeasonType == NhlSeasonType.RegularSeason
                        group player by new { player.Name, player.DraftYear } into playerGroup
                        select new NhlPlayerStatsBioSkaterViewModel
                        {
                            Name = playerGroup.Key.Name,
                            DraftYear = playerGroup.Key.DraftYear,
                            SeasonsPlayed = playerGroup.Count(),
                            AvgGamesPerSeason = Math.Round(playerGroup.Average(p => p.GamesPlayed), 1),
                            TotalGamesPlayed = playerGroup.Sum(p => p.GamesPlayed)
                        };

                viewModel = queryResult.ToList();
            }

            return View(viewModel);
        }
 public PlayerRepository(SportsDataContext db)
 {
     _db = db;
 }