/// <summary> /// this is to create player stats if they do not exist /// </summary> /// <param name="scorecontext"></param> /// <param name="usercontext"></param> /// <param name="userManager"></param> public static void SeedPlayerStats(GameDataContext scorecontext) { // Look for any stats if (scorecontext.PlayerStats.Any()) { return; // DB has been seeded } //Initialize these stats var stats = new PlayerStats[] { new PlayerStats { User = new GameUser { UserName = "******", NickName = "Boi", Email = "*****@*****.**", EmailConfirmed = true }, HighestScore = 7000, GamesPlayed = 1, LastGameDate = DateTime.Today, TotalTimePlayed = TimeSpan.FromMinutes(12), LongestGame = TimeSpan.FromMinutes(12), UserName = "******", }, new PlayerStats { User = new GameUser { UserName = "******", NickName = "Alien", Email = "*****@*****.**", EmailConfirmed = true }, HighestScore = 25, GamesPlayed = 1, LastGameDate = DateTime.Today, TotalTimePlayed = TimeSpan.FromMinutes(4), LongestGame = TimeSpan.FromMinutes(4), UserName = "******", }, //add stats to db }; foreach (PlayerStats s in stats) { scorecontext.PlayerStats.Add(s); } //try to save stats to db try { scorecontext.SaveChanges(); } catch (Exception e) { Debug.WriteLine(e.Message); throw; } }
/// <summary> /// this is to initialize the databases with data /// </summary> /// <param name="scorecontext"></param> /// <param name="usercontext"></param> /// <param name="userManager"></param> public static async Task InitializeAsync(GameDataContext gamedatacontext, UserContext usercontext, UserManager <GameUser> userManager) { //ensure the databases are deleted and the migrate them gamedatacontext.Database.EnsureDeleted(); usercontext.Database.EnsureDeleted(); gamedatacontext.Database.Migrate(); usercontext.Database.Migrate(); //seed the users, scores, stats, and statnotes await SeedUsers(userManager); SeedScores(gamedatacontext); SeedPlayerStats(gamedatacontext); SeedNotes(gamedatacontext); }
/// <summary> /// this is to create player stat's notes if they do not exist /// </summary> /// <param name="scorecontext"></param> /// <param name="usercontext"></param> /// <param name="userManager"></param> public static void SeedNotes(GameDataContext notescontext) { // Look for any stats if (notescontext.StatNotes.Any()) { return; // DB has been seeded } //get these stats that we want to attach notes to PlayerStats firststat = notescontext.PlayerStats.Where(s => s.UserName == "*****@*****.**").ToList()[0]; PlayerStats secondstat = notescontext.PlayerStats.Where(s => s.UserName == "*****@*****.**").ToList()[0]; //Initialize these stat notes var notes = new StatNotes[] { new StatNotes { Note = "Congrats on your great score!", TimeModified = DateTime.Now, Liked = 2, UserName = "******", StatID = firststat.PlayerStatsID, }, new StatNotes { Note = "Go back to space!", TimeModified = DateTime.Now, Liked = 100, UserName = "******", StatID = secondstat.PlayerStatsID, }, }; //add each note to the DB foreach (StatNotes n in notes) { notescontext.StatNotes.Add(n); } //try saving the db try { notescontext.SaveChanges(); } catch (Exception e) { Debug.WriteLine(e.Message); throw; } }
/// <summary> /// this is to create scores if they do not exist /// </summary> /// <param name="scorecontext"></param> /// <param name="usercontext"></param> /// <param name="userManager"></param> public static void SeedScores(GameDataContext scorecontext) { // Look for any scores if (scorecontext.Scores.Any()) { return; // DB has been seeded } //Initialize these scores var scores = new Score[] { new Score { Value = 7000, Nickname = "Boi", UserName = "******", GameMode = GameMode.Single_Player }, new Score { Value = 25, Nickname = "Alien", UserName = "******", GameMode = GameMode.Multi_Player }, }; //add each score to the db foreach (Score s in scores) { scorecontext.Scores.Add(s); } //try to save these to the db try { scorecontext.SaveChanges(); } catch (Exception e) { Debug.WriteLine(e.Message); throw; } }
public ScoresModel(CS4540_tetris.Data.GameDataContext context) { _context = context; }