public MovieController(InterviewMvcContext context) { _context = context; if (_context.MovieModel.Count() == 0) { // Create a new TodoItem if collection is empty, // which means you can't delete all MovieItems. _context.MovieModel.Add(new MovieModel { Title = "ItemTest1" }); _context.SaveChanges(); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new InterviewMvcContext( serviceProvider.GetRequiredService <DbContextOptions <InterviewMvcContext> >())) { // Look for any movies. if (context.MovieModel.Any()) { return; // DB has been seeded } context.MovieModel.AddRange( new MovieModel { Title = "When Harry Met Sally", ReleaseDate = DateTime.Parse("1989-1-11"), Genre = "Romantic Comedy", Price = 7.99M }, new MovieModel { Title = "Ghostbusters ", ReleaseDate = DateTime.Parse("1984-3-13"), Genre = "Comedy", Price = 8.99M }, new MovieModel { Title = "Ghostbusters 2", ReleaseDate = DateTime.Parse("1986-2-23"), Genre = "Comedy", Price = 9.99M }, new MovieModel { Title = "Rio Bravo", ReleaseDate = DateTime.Parse("1959-4-15"), Genre = "Western", Price = 3.99M } ); context.SaveChanges(); } }
public MovieController(InterviewMvcContext context) { _context = context; }