public static async Task EnsureSeedData(this BollywoodDbContext db) { if (!db.Movies.Any()) { db.Movies.AddRange(new DbUtility().GetMovies()); await db.SaveChangesAsync().ConfigureAwait(false); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, BollywoodDbContext db) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors("CorsPolicy"); app.UseMvc(); db.EnsureSeedData().GetAwaiter().GetResult(); }
public MovieRepository(BollywoodDbContext bollywoodDbContext) { _bollywoodDbContext = bollywoodDbContext; }