示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DemoContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //app.UseHttpsRedirection();

            app.UseRouting();
            app.UseCors("AllowAllOrigins");
            //app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            DbInitializer.Initialize(db);
        }
        public static void Initialize(DemoContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Forecasts.Any())
            {
                return;   // DB has been seeded
            }
            var rng       = new Random();
            var forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date         = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)]
            });

            foreach (WeatherForecast forecast in forecasts)
            {
                context.Forecasts.Add(forecast);
            }
            context.SaveChanges();
        }