Esempio n. 1
0
        public IActionResult ResetData()
        {
            DatabaseSeeder seeder = new DatabaseSeeder(_context, _userManager);

            seeder.SeedData();

            return(Redirect("/"));
        }
Esempio n. 2
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <User> userManager, BudgetTrackerContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseCors(builder => builder
                            .AllowAnyOrigin()
                            .AllowAnyMethod()
                            .AllowAnyHeader());
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseCors(builder => builder
                            .AllowAnyOrigin()
                            .AllowAnyMethod()
                            .AllowAnyHeader());
                app.UseHsts();
                app.UseHttpsRedirection();
            }

            app.UseOpenApi(options =>
            {
                options.DocumentName = "swagger";
                options.Path         = "/swagger/v1/swagger.json";
                options.PostProcess  = (document, _) =>
                {
                    document.Schemes.Add(OpenApiSchema.Https);
                };
            });

            app.UseRouting();

            app.UseSwaggerUi3(options =>
            {
                options.DocumentPath = "/swagger/v1/swagger.json";
            });

            app.UseAuthentication();
            app.UseAuthorization();

            DatabaseSeeder.SeedData(userManager, context);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Esempio n. 3
0
 private static void CreateDbIfNotExists(IWebHost host)
 {
     using (var scope = host.Services.CreateScope())
     {
         var services = scope.ServiceProvider;
         try
         {
             var context     = services.GetRequiredService <DatabaseContext>();
             var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
             var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
             DatabaseSeeder.SeedData(context, roleManager, userManager);
         }
         catch (Exception ex)
         {
             var logger = services.GetRequiredService <ILogger <Program> >();
             logger.LogError(ex, "An error occurred creating the DB.");
         }
     }
 }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // 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.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint(url: "/swagger/v1/swagger.json", name: "Restaurant API v1"));


            //app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();


            DatabaseSeeder.SeedData(userManager, roleManager);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }