Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, StoreCatalogDbContext storeCatalogDbContext)
        {
            if (HostingEnvironment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseMvc();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json",
                                  "StoreCatalog");
            });

            using (var serviceScope = app
                                      .ApplicationServices
                                      .GetService <IServiceScopeFactory>()
                                      .CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <StoreCatalogDbContext>();
                context.Database.EnsureCreated();
            }
        }
        public static void Seed(this StoreCatalogDbContext dbContext)
        {
            if (dbContext.Stores.Any())
            {
                return;
            }

            dbContext.Stores.AddRange(new List <Store> {
                new Store {
                    Name = "California - Pasadena", StoreId = new Guid("8048e9ec-80fe-4bad-bc2a-e4f4a75c834e")
                },
                new Store {
                    Name = "Los Angeles - Beverly Hills", StoreId = new Guid("8d618778-85d7-411e-878b-846a8eef30c0")
                }
            });

            dbContext.SaveChanges();
        }