// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ProductCrudRPContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); ProductCrudRpSeedData.Seed(context); }
public static void Seed(ProductCrudRPContext context) { context.Database.EnsureCreated(); if (context.Products.Count() == 0 && context.Categories.Count() == 0) { Category c1 = new Category { Name = "Mens Footwear" }; Category c2 = new Category { Name = "Womens Footwear" }; context.Products.AddRange( new Product { Name = "Leather Saddle Loafers, Tan", Price = 34.00M, Category = c1 }, new Product { Name = "Flip Flops, Red", Price = 19.50M, Category = c1 }, new Product { Name = "Almond Toe Court Shoes, Black", Price = 99.00M, Category = c2 }, new Product { Name = "Suede Shoes, Blue", Price = 52.99M, Category = c2 } ); context.SaveChanges(); } }
public ProductRepository(ProductCrudRPContext context) { _context = context; }
public CategoryRepository(ProductCrudRPContext context) { _context = context; }