public static void Initialize(IServiceProvider serviceProvider) { using (var context = new Data.MvcMovieContext( serviceProvider.GetRequiredService < DbContextOptions <Data.MvcMovieContext> >())) { // Look for any movies. if (context.Movie.Any()) { return; // DB has been seeded } context.Movie.AddRange( new Movie { Title = "When Harry Met Sally", ReleaseDate = DateTime.Parse("1989-2-12"), Genre = "Romantic Comedy", Price = 7.99M, Rating = "R" }, new Movie { Title = "Ghostbusters ", ReleaseDate = DateTime.Parse("1984-3-13"), Genre = "Comedy", Price = 8.99M, Rating = "PG" }, new Movie { Title = "Ghostbusters 2", ReleaseDate = DateTime.Parse("1986-2-23"), Genre = "Comedy", Price = 9.99M, Rating = "PG" }, new Movie { Title = "Rio Bravo", ReleaseDate = DateTime.Parse("1959-4-15"), Genre = "Western", Price = 3.99M, Rating = "R" } ); context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new Data.MvcMovieContext(serviceProvider.GetRequiredService <DbContextOptions <MvcMovieContext> >())) { if (context.Movie.Any()) { return; } context.Movie.AddRange( new Movie { Title = "Skyfall", ReleaseDate = DateTime.Parse("2017-11-21"), Genre = "Action", Price = 10 }, new Movie { Title = "Listy do M", ReleaseDate = DateTime.Parse("2015-12-10"), Genre = "Romantic Comedy", Price = 7 }, new Movie { Title = "Untouchables", ReleaseDate = DateTime.Parse("2011-05-13"), Genre = "Comedy Drama", Price = 12 }, new Movie { Title = "Spiderman", ReleaseDate = DateTime.Parse("2019-09-23"), Genre = "Action", Price = 6 } ); context.SaveChanges(); } }
public HomeController(Data.MvcMovieContext context) { _context = context; }