Example #1
0
        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);
        }
Example #2
0
        private const string postSeasonFormatString = "/mlb/team/schedule/_/name/{0}/year/{1}/seasontype/3";          // team short name, year

        public static List <MlbGameSummaryModel> GetSeason(MlbSeasonType mlbSeasonType, int seasonYear)
        {
            List <MlbGameSummaryModel> results = new List <MlbGameSummaryModel>();

            foreach (MlbTeamShortName mlbTeam in Enum.GetValues(typeof(MlbTeamShortName)))
            {
                List <MlbGameSummaryModel> teamResults = MlbAttendanceQuery.GetSeasonForTeam(mlbSeasonType, mlbTeam, seasonYear);
                if (null != teamResults)
                {
                    results.AddRange(teamResults);
                }
            }

            return(results);
        }