Example #1
0
        //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();
            }
        }
Example #2
0
        // 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?}");
            });
        }
Example #3
0
 public ProductController(BeerStoreDbContext beerStoreDbContext)
 {
     _beerStoreDbContext = beerStoreDbContext;
 }
Example #4
0
 //constructor
 public CartController(BeerStoreDbContext BeerStoreDbContext)
 {
     _beerStoreDbContext = BeerStoreDbContext;
 }
 public ProductsAdminController(BeerStoreDbContext context, IHostingEnvironment env)
 {
     _context = context;
     _env     = env;
 }