public void SeedDB(ProductAppLiteContext ctx) { ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); ctx.Products.Add(new Product() { Name = "James Bond", Price = 007, Color = "Red", Type = "Spy", }); ctx.SaveChanges(); }
public void SeedDB(ProductAppLiteContext ctx) { ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); if (ctx.TodoItems.Any()) { return; //ctx.Database.ExecuteSqlRaw("DROP TABLE Pets"); //ctx.Database.ExecuteSqlRaw("DROP Table Owner"); //ctx.Database.ExecuteSqlRaw("DROP Table Todo"); //ctx.Database.ExecuteSqlRaw("DROP Table Token"); //ctx.Database.EnsureCreated(); } ctx.Products.Add(new Product() { Name = "Hulk Hogan", Price = 1500, Color = "Yellow", Type = "Wrestler" }); ctx.Products.Add(new Product() { Name = "John Cena", Price = 1500, Color = "Blue", Type = "Wrestler" }); ctx.Products.Add(new Product() { Name = "Sting", Price = 1500, Color = "Black", Type = "Wrestler" }); List <TodoItem> items = new List <TodoItem> { new TodoItem { IsComplete = true, Name = "Make homework" }, new TodoItem { IsComplete = false, Name = "Sleep" } }; string password = "******"; byte[] passwordHashJoe, passwordSaltJoe, passwordHashAnn, passwordSaltAnn; authenticationHelper.CreatePasswordHash(password, out passwordHashJoe, out passwordSaltJoe); authenticationHelper.CreatePasswordHash(password, out passwordHashAnn, out passwordSaltAnn); List <User> users = new List <User> { new User { Username = "******", PasswordHash = passwordHashJoe, PasswordSalt = passwordSaltJoe, IsAdmin = false }, new User { Username = "******", PasswordHash = passwordHashAnn, PasswordSalt = passwordSaltAnn, IsAdmin = true } }; ctx.TodoItems.AddRange(items); ctx.Users.AddRange(users); ctx.SaveChanges(); }
public void SeedDB(ProductAppLiteContext ctx) { ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); if (ctx.TodoItems.Any()) { return; //ctx.Database.ExecuteSqlRaw("DROP TABLE Pets"); //ctx.Database.ExecuteSqlRaw("DROP Table Owner"); //ctx.Database.ExecuteSqlRaw("DROP Table Todo"); //ctx.Database.ExecuteSqlRaw("DROP Table Token"); //ctx.Database.EnsureCreated(); } ctx.Products.Add(new Product() { Name = "beer1", Price = 50, Type = "dark" }); ctx.Products.Add(new Product() { Name = "beer3", Price = 100, Type = "ale" }); ctx.Products.Add(new Product() { Name = "beer3", Price = 150, Type = "light" }); List <TodoItem> items = new List <TodoItem> { new TodoItem { IsComplete = true, Name = "dosmth" }, new TodoItem { IsComplete = false, Name = "dosmthelse" } }; string password = "******"; byte[] passwordHash, passwordSalt, passwordHash1, passwordSalt1; authenticationHelper.CreatePasswordHash(password, out passwordHash, out passwordSalt); authenticationHelper.CreatePasswordHash(password, out passwordHash1, out passwordSalt1); List <User> users = new List <User> { new User { Username = "******", PasswordHash = passwordHash, PasswordSalt = passwordSalt, IsAdmin = false }, new User { Username = "******", PasswordHash = passwordHash1, PasswordSalt = passwordSalt1, IsAdmin = true } }; ctx.TodoItems.AddRange(items); ctx.Users.AddRange(users); ctx.SaveChanges(); }