示例#1
0
        public static void SplitCareerSameName(string name, int startCareer2)
        {
            using (var db = new BeaujeauxEntities())
            {
                var skaters = db.Skaters.Where(a => a.Name == name);
                if (skaters.Count() != 1)
                {
                    throw new Exception("too many skaters");
                }
                var skater = skaters.First();

                skater.Name = name + " I";

                var secondSkater = new DataEF.Skater();
                secondSkater.Name = name + " II";
                db.Skaters.Add(secondSkater);

                db.SaveChanges();

                secondSkater = db.Skaters.Where(a => a.Name == name + " II").First();

                foreach (var season in skater.SkaterSeasonStats.Where(a => a.Season.Number >= startCareer2))
                {
                    season.SkaterId = secondSkater.Id;
                }

                db.SaveChanges();
            }
        }
示例#2
0
        public static void RemoveTeamIdForTotal()
        {
            using (var db = new BeaujeauxEntities())
            {
                var stats = db.SkaterSeasonStats
                            .GroupBy(
                    x => new { x.SkaterId, x.SeasonId },
                    (a, b) => b.Where(c => b.Count() > 1)
                    ).Where(a => a.Count() > 1).ToList();

                Console.WriteLine(stats.Count() + " people");
                Console.WriteLine();

                int z = 0;
                List <SkaterSeasonStat> allStats = new List <SkaterSeasonStat>();
                foreach (var season in stats)
                {
                    foreach (var statLine in season)
                    {
                        var stat = db.SkaterSeasonStats.First(a => a.Id == statLine.Id);
                        if (!stat.IsSubtotal)
                        {
                            stat.TeamId = null;
                            allStats.Add(stat);
                            break;
                        }
                    }
                    Console.Write(++z + " ");
                }

                db.SaveChanges();
            }
        }
示例#3
0
        public static void AddRequestTypes()
        {
            BeaujeauxEntities database = new BeaujeauxEntities();

            if (database.RequestTypes.Any())
            {
                return;
            }

            database.RequestTypes.Add(new RequestType()
            {
                Name    = "Bug",
                Display = "Something's Broken",
                Rank    = 1
            });
            database.RequestTypes.Add(new RequestType()
            {
                Name    = "Data",
                Display = "Data is Wrong",
                Rank    = 2
            });
            database.RequestTypes.Add(new RequestType()
            {
                Name    = "Feature",
                Display = "Feature Request",
                Rank    = 3
            });
            database.RequestTypes.Add(new RequestType()
            {
                Name    = "General",
                Display = "Something else",
                Rank    = 4
            });
            database.SaveChanges();
        }
示例#4
0
        public static void MergeIntoExistingSkater(string oldName, string newName)
        {
            using (var db = new BeaujeauxEntities())
            {
                var skaters = db.Skaters.Where(a => a.Name == newName);
                if (skaters.Count() != 1)
                {
                    throw new Exception("too many skaters");
                }
                var newSkater = skaters.First();

                skaters = db.Skaters.Where(a => a.Name == oldName);
                if (skaters.Count() != 1)
                {
                    throw new Exception("too many skaters");
                }
                var oldSkater = skaters.First();

                foreach (var season in oldSkater.SkaterSeasonStats)
                {
                    season.SkaterId = newSkater.Id;
                }

                db.Skaters.Remove(oldSkater);
                db.SaveChanges();
            }
        }
示例#5
0
        public static void RemoveExtraPlayers()
        {
            using (BeaujeauxEntities database = new BeaujeauxEntities())
            {
                var extraSkaters = database.Skaters
                                   .Where(a => !a.SkaterSeasonStats.Any());
                database.Skaters.RemoveRange(extraSkaters);

                var extraGoalies = database.Goalies
                                   .Where(a => !a.GoalieSeasonStats.Any());
                database.Goalies.RemoveRange(extraGoalies);

                database.SaveChanges();
            }
        }
示例#6
0
        public static void ChangeSkaterName(string oldName, string newName)
        {
            using (var db = new BeaujeauxEntities())
            {
                var skaters = db.Skaters.Where(a => a.Name == oldName);
                if (skaters.Count() != 1)
                {
                    throw new Exception("too many skaters");
                }
                var oldSkater = skaters.First();

                oldSkater.Name = newName;

                db.SaveChanges();
            }
        }
示例#7
0
 public static void AddSeasonTypes()
 {
     using (BeaujeauxEntities database = new BeaujeauxEntities())
     {
         if (!database.SeasonTypes.Any())
         {
             database.SeasonTypes.Add(new SeasonType()
             {
                 Name = "Regular Season"
             });
             database.SeasonTypes.Add(new SeasonType()
             {
                 Name = "Playoffs"
             });
             database.SaveChanges();
         }
     }
 }
示例#8
0
 public static void AddLeagues()
 {
     using (BeaujeauxEntities database = new BeaujeauxEntities())
     {
         if (!database.Leagues.Any())
         {
             database.Leagues.Add(new League()
             {
                 Acronym = "SHL", Name = "Simulated Hockey League"
             });
             database.Leagues.Add(new League()
             {
                 Acronym = "SMJHL", Name = "Simulated Major Junior Hockey League"
             });
             database.SaveChanges();
         }
     }
 }
示例#9
0
        public void AddToDB()
        {
            bool safeToSave = true;

            if (Description == null && Description.Length < 10)
            {
                ErrorMessage = "Description must be at least 20 characters to help me fully understand what you need.";
                safeToSave   = false;
            }

            using (BeaujeauxEntities database = new BeaujeauxEntities())
            {
                var         id          = int.Parse(SelectedRequestId);
                RequestType requestType = database.RequestTypes.Where(s => s.Id == id).FirstOrDefault();
                if (requestType == null)
                {
                    safeToSave   = false;
                    ErrorMessage = "Please select a request type.";
                }

                if (safeToSave)
                {
                    database.RequestSubmissions.Add(new RequestSubmission()
                    {
                        RequestTypeId   = requestType.Id,
                        Description     = Description,
                        DateSubmitted   = DateTime.Now,
                        CompleteComment = null,
                        DateComplete    = null,
                    });
                    database.SaveChanges();
                }
            }

            Submitted = safeToSave;
        }
示例#10
0
        public static void AddFranchises()
        {
            BeaujeauxEntities database = new BeaujeauxEntities();

            database.Franchises.RemoveRange(database.Franchises);

            string[] latestTeamsShl =
            {
                "Buffalo Stampede",
                "Calgary Dragons",
                "Edmonton Blizzard",
                "Hamilton Steelhawks",
                "Manhattan Rage",
                "Toronto North Stars",
                "West Kendall Platoon",
                "Winnipeg Jets",
                "Los Angeles Panthers",
                "Minnesota Chiefs",
                "Texas Renegades",
                "New England Wolfpack",
                "Seattle Riot",
                "San Francisco Pride"
            };

            string[] latestTeamsSmjhl =
            {
                "Detroit Falcons",
                "Montreal Militia",
                "Prince George Firebirds",
                "Kelowna Knights",
                "St Louis Scarecrows",
                "Vancouver Whalers",
                "Colorado Mammoths",
                "Halifax Raiders",
            };

            League shl   = database.Leagues.Where(a => a.Acronym == "SHL").First();
            League smjhl = database.Leagues.Where(a => a.Acronym == "SMJHL").First();

            foreach (var teamName in latestTeamsShl)
            {
                var team = database.Teams.Where(t => t.Name == teamName).FirstOrDefault();
                if (team == null)
                {
                    continue;
                }

                Franchise franchise = new Franchise()
                {
                    LatestTeam = team,
                    League     = shl,
                };

                team.Franchise = franchise;

                if (team.Acronym == "NEW")
                {
                    var hydras = database.Teams.Where(t => t.Name == "Hartford Hydras").FirstOrDefault();
                    franchise.Teams.Add(hydras);
                }
                if (team.Acronym == "SEA")
                {
                    var nightmare = database.Teams.Where(t => t.Name == "Vancouver Nightmare").FirstOrDefault();
                    var lvkings   = database.Teams.Where(t => t.Name == "Las Vegas Kings").FirstOrDefault();
                    var wolves    = database.Teams.Where(t => t.Name == "Vancouver Ice Wolves").FirstOrDefault();
                    franchise.Teams.Add(nightmare);
                    franchise.Teams.Add(lvkings);
                    franchise.Teams.Add(wolves);
                }
                if (team.Acronym == "SFP")
                {
                    var port = database.Teams.Where(t => t.Name == "Portland Admirals").FirstOrDefault();
                    franchise.Teams.Add(port);
                }
                if (team.Acronym == "EDM")
                {
                    var port = database.Teams.Where(t => t.Name == "Edmonton Comets").FirstOrDefault();
                    franchise.Teams.Add(port);
                }

                database.Franchises.Add(franchise);
            }

            foreach (var teamName in latestTeamsSmjhl)
            {
                var team = database.Teams.Where(t => t.Name == teamName).FirstOrDefault();
                if (team == null)
                {
                    continue;
                }

                Franchise franchise = new Franchise()
                {
                    LatestTeam = team,
                    League     = smjhl,
                };

                team.Franchise = franchise;

                if (team.Acronym == "MTL")
                {
                    var impact = database.Teams.Where(t => t.Name == "Montreal Impact").FirstOrDefault();
                    franchise.Teams.Add(impact);
                }

                if (team.Acronym == "PGF")
                {
                    var regina = database.Teams.Where(t => t.Name == "Regina Force").FirstOrDefault();
                    franchise.Teams.Add(regina);
                }

                database.Franchises.Add(franchise);
            }

            database.SaveChanges();
        }