internal static void Initialize(this OrganicStoreDbContext db) { db.Database.Migrate(); if (db.Products.Count() == 0) { db.Database.Migrate(); db.Products.Add(new Product { Description = "Lorem ipsum ipsum lorem", Name = "Ginger", Image = "/images/ginger-root.png", Price = 7.99m }); db.Products.Add(new Product { Description = "Lorem ipsum ipsum lorem", Name = "Hass Avocado", Image = "/images/HassAvocado.jpg", Price = 5.49m }); db.Products.Add(new Product { Description = "Lorem ipsum ipsum lorem", Name = "Raspberries", Image = "/images/raspberries.jpg", Price = 2.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, OrganicStoreDbContext db) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } //This helps the app to use Cookies for tracking SignIn/SignOut status app.UseAuthentication(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // DbInitializer.Initialize(db); //Because of the static keyword on the dbinitializer class and the this keyowrd on the context we can change this to as below db.Initialize(); }
public CheckOutController(OrganicStoreDbContext context, IConfiguration configuration, BraintreeGateway brainTreeGateway, SignInManager <OrganicStoreUser> signInManager, EmailService emailService, SmartyStreets.USStreetApi.Client usStreetApiClient) { _context = context; _sendGridKey = configuration["SendGridKey"]; _brainTreeGateway = brainTreeGateway; _signInManager = signInManager; _emailService = emailService; _usStreetApiClient = usStreetApiClient; }
public DetailsModel(OrganicStoreDbContext context) { _context = context; }
public EditModel(OrganicStoreDbContext context) { _context = context; }
public CreateModel(OrganicStoreDbContext context) { _context = context; }
public ProductController(OrganicStoreDbContext context) { _context = context; }
public ProductsAdminController(OrganicStoreDbContext context, IHostingEnvironment env) { _context = context; _env = env; }
public IndexModel(OrganicStoreDbContext context) { _context = context; }
public CartController(OrganicStoreDbContext context) { _context = context; }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new OrganicStoreDbContext( serviceProvider.GetRequiredService < DbContextOptions <OrganicStoreDbContext> >())) { // Look for any movies. if (context.User.Any()) { return; // DB has been seeded } context.User.AddRange( new User { Id = 1, Name = "Bryant Omoregie", Email = "j", Password = "******" } ); if (context.Product.Any()) { return; } context.Product.AddRange( new Product { Id = 1, Name = "Organic Honeycrisp Apple", Type = "Produce", Description = "Organic Honeycrisp Apple, a sodium free food", ProductImage = "https://m.media-amazon.com/images/S/assets.wholefoodsmarket.com/PIE/product/5789086c808ed8290ce339ab_produce_honeycrispapple.1._TTD_._SR300,300_.jpg" }, new Product { Id = 2, Name = "Large Hass Avocados", Type = "Produce", Description = "Avocado, a sodium free food", ProductImage = "https://m.media-amazon.com/images/S/assets.wholefoodsmarket.com/PIE/product/56e4a5edf7c6bd1100c9b400_365_-hass-avocado.1._TTD_._SR300,300_.jpg" }, new Product { Id = 3, Name = "Organic Large Hass Avocados", Type = "Produce", Description = "Avocado, a sodium free food", ProductImage = "https://m.media-amazon.com/images/S/assets.wholefoodsmarket.com/PIE/product/575f2594d59d0103e5ac59c2_produce_ogavocados.1._TTD_._SR300,300_.jpg" } ); if (context.Cart.Any()) { return; } context.Cart.AddRange ( new Cart { Id = 1, ClientID = 1, } ); context.SaveChanges(); } }
public DeleteModel(OrganicStoreDbContext context) { _context = context; }