public IActionResult Create([Bind("Id, Title, Description, ReleaseDate, Genre, Publisher, Rating, Price, UnitsSold")] Game game) { _context.Database.EnsureCreated(); if (ModelState.IsValid) { _context.Game.Add(game); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(game)); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new MyGameStoreContext(serviceProvider.GetRequiredService <DbContextOptions <MyGameStoreContext> >())) { //look For Games if (context.Game.Any()) { return; // Db has been seeded } context.Game.AddRange( new Game { Title = "World of warcraft", ReleaseDate = DateTime.Parse("2003-1-11"), Genre = "MMO", Publisher = "Blizzard", Price = 60m, Rating = "18", Description = "The adventures of azeroth bla bla bla...", UnitsSold = 1003400, }); context.SaveChanges(); } }