//method internal static void Initialize(BeerStoreDbContext db) { db.Database.Migrate(); if (db.Products.Count() == 0) { db.Products.Add(new Product { Name = "IPA", Image = "/Images/beer1.jpg", Description = "California IPA", Price = 3.99m }); db.Products.Add(new Product { Name = "IPA", Image = "/Images/beer2.jpg", Description = "Low Alcohol Session IPA", Price = 4.99m }); db.SaveChanges(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, BeerStoreDbContext db) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseAuthentication(); app.UseStaticFiles(); //seed the database if it's empty DbInitializer.Initialize(db); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public ProductController(BeerStoreDbContext beerStoreDbContext) { _beerStoreDbContext = beerStoreDbContext; }
//constructor public CartController(BeerStoreDbContext BeerStoreDbContext) { _beerStoreDbContext = BeerStoreDbContext; }
public ProductsAdminController(BeerStoreDbContext context, IHostingEnvironment env) { _context = context; _env = env; }