//public static class DatabaseInitializer // { //public static void Initialize(CaseDBContext dbContext) //{ // dbContext.Database.EnsureCreated(); // if (!dbContext.Cases.Any()) // { // // Write you necessary to code here to insert the User to database and save the the information to file. // } //} //} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CaseDBContext context) { // DatabaseInitializer.Initialize(context); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //app.UseHttpsRedirection(); //app.UseRouting(); //app.UseAuthorization(); //app.UseEndpoints(endpoints => //{ // endpoints.MapControllers(); //}); //context.SeedDataContext(); app.UseMvc(); }
public static void SeedDataContext(this CaseDBContext context) { var data = new List <Case>() { new Case() { Id = 1, FirstName = "John", LastName = "Doe", Type = "Cured", Description = "Description" }, new Case() { Id = 2, FirstName = "Jill", LastName = "Doe", Type = "Cured", Description = "Description" }, new Case() { Id = 3, FirstName = "Amy", LastName = "Doe", Type = "Infected", Description = "Description" }, new Case() { Id = 4, FirstName = "Steve", LastName = "Doe", Type = "Cured", Description = "Description" }, new Case() { Id = 5, FirstName = "Amy", LastName = "House", Type = "Infected", Description = "Description" }, new Case() { Id = 6, FirstName = "Sam", LastName = "Wood", Type = "Deceased", Description = "Description" }, new Case() { Id = 7, FirstName = "Alex", LastName = "Clay", Type = "Deceased", Description = "Description" } }; context.Cases.AddRange(data); context.SaveChanges(); }