public static void EnsureSeedDataForContext(this DoormanContext context) { if (!context.Rooms.Any()) { var rooms = new List <Room> { new Room { Description = "Computer Science Hall" }, new Room { Description = "Software Engineering Hall" } }; context.Rooms.AddRange(rooms); } context.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, DoormanContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } context.EnsureSeedDataForContext(); Mapper.Initialize(cfg => cfg.AddProfiles(Assembly.GetExecutingAssembly())); app.UseCors("CorsPolicy"); app.UseWebSockets(); app.UseSignalR(routes => { routes.MapHub <DoormanHub>("doorman"); }); app.UseMvc(); }