Beispiel #1
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();


            using (var scope = host.Services.CreateScope())
            {
                var services    = scope.ServiceProvider;
                var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();

                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await IdentityDataSeed.SeedAsync(userManager, roleManager);

                    var context = services.GetRequiredService <ApplicationDbContext>();
                    await ApplicationDbContextSeed.SeedAsync(context);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the database.");
                }
            }

            host.Run();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            IWebHost host = CreateWebHostBuilder(args).Build();

            Task.Run(async() => await IdentityDataSeed.Seed(host.Services, "admin", "Password1!")).Wait();

            host.Run();
        }
Beispiel #3
0
        public static void SeedIdentityData(IHost host)
        {
            using var scope = host.Services.CreateScope();

            var services = scope.ServiceProvider;

            try
            {
                var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();

                var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();

                IdentityDataSeed.SeedData(userManager, roleManager);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "Ocorreu um erro a criar dados do identity.");
            }
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                SeedDataBase.SeedData();
            }

            app.UseRouting();
            app.UseStaticFiles();
            app.UseNpmStaticFiles();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(name: "orders", pattern: "orders", defaults: new { controller = "Cart", action = "GetOrders" });

                endpoints.MapControllerRoute(name: "checkout", pattern: "checkout", defaults: new { controller = "cart", action = "checkout" });
                endpoints.MapControllerRoute(name: "Cart", pattern: "cart", defaults: new { controller = "cart", action = "index" });
                endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action}/{id?}", defaults: new { controller = "home", action = "index" });
            });

            IdentityDataSeed.SeedIdentityData(userManager, roleManager, Configuration).Wait();
        }
Beispiel #5
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 <IdentityRole> roleManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/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.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();

            app.ApplicationServices
            .UseBootstrapProviders()
            .UseFontAwesomeIcons();

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

            app.UseSession();

            IdentityDataSeed.SeedData(userManager, roleManager);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
        }