public static void Initialize(BeekeepersDBContext context) { context.Database.EnsureCreated(); // Look for any beekeepers, add if there are none in table. if (!context.Beekeepers.Any()) { var beekeepers = new Beekeeper[] { new Beekeeper { FirstName = "Lee", LastName = "Mullen", Address = "5822 Pioneer Rd S", City = "Saint Paul Park", State = "MN", Zipcode = "55071", Phone = "123-123-1234", Email = "*****@*****.**" }, new Beekeeper { FirstName = "John", LastName = "Doe", Address = "Any St", City = "Town", State = "MN", Zipcode = "55555", Phone = "", Email = "" } }; foreach (Beekeeper b in beekeepers) { context.Beekeepers.Add(b); } context.SaveChanges(); } // Look for any beehives, add if there are none in table. if (!context.Beehives.Any()) { var beehives = new Beehive[] { new Beehive { BeekeeperIDFK = 1, HiveName = "No 1", InstallDate = Convert.ToDateTime("2016-4-15"), Notes = "Not a good hive.", HoneyProduction = 25 }, new Beehive { BeekeeperIDFK = 2, HiveName = "Big Hive", InstallDate = Convert.ToDateTime("2016-4-15"), Notes = "My best hive.", HoneyProduction = 100 } }; foreach (Beehive b in beehives) { context.Beehives.Add(b); } context.SaveChanges(); } return; // DB has been seeded }
public BeehivesController(BeekeepersDBContext context) { _context = context; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, BeekeepersDBContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // IMPORTANT: This session call MUST go before UseMvc() app.UseSession(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "beekeepers", template: "{controller=Beekeepers}/{action=Beekeepers}/{id?}"); routes.MapRoute( name: "beehives", template: "{controller=Beehives}/{action=Beehives}/{id}"); routes.MapRoute( name: "one", template: "{controller=HomeAJ}/{action=One}"); routes.MapRoute( name: "two", template: "{controller=HomeAJ}/{action=Two}"); routes.MapRoute( name: "three", template: "{controller=HomeAJ}/{action=Three}"); routes.MapRoute( name: "index", template: "{controller=HomeAJ}/{action=Index}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }