Ejemplo n.º 1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseStatusCodePages();
                app.UseDeveloperExceptionPage();
            }
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
            app.UseStaticFiles();
            app.UseAuthentication();

            //Change
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "pagination",
                    template: "Dogs/List/Page{dogsPage}",
                    defaults: new { Controller = "Dogs", action = "List" });

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            DbInitializerDogs.Seed(app);
            DbInitializerCats.Seed(app);
            IdentitySeedData.Seed(app);

            RotativaConfiguration.Setup(env);
        }
Ejemplo n.º 2
0
        private static void UpdateDatabase(IApplicationBuilder app)
        {
            using (IServiceScope serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                using (ApplicationDbContext context = serviceScope.ServiceProvider.GetService <ApplicationDbContext>())
                    using (ApplicationIdentityDbContext identityContext = serviceScope.ServiceProvider.GetService <ApplicationIdentityDbContext>())
                    {
                        identityContext.Database.Migrate();
                        context.Database.Migrate();

                        // Seeding identity
                        UserManager <ApplicationUser> userMgr =
                            serviceScope.ServiceProvider.GetService <UserManager <ApplicationUser> >();
                        RoleManager <IdentityRole> roleMgr =
                            serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >();

                        IdentitySeedData identitySeeder = new IdentitySeedData(identityContext, userMgr, roleMgr);
                        identitySeeder.Seed();

                        try
                        {
                            SeedData.EnsurePopulated(context);
                        }
                        catch (Exception ex)
                        {
                            ILogger <Startup> logger = serviceScope.ServiceProvider.GetRequiredService <ILogger <Startup> >();
                            logger.LogError(ex, "An error occured seeding the database.");
                        }
                    }
            }
        }
Ejemplo n.º 3
0
        public AccountController(UserManager <Administrator> userManager, SignInManager <Administrator> signInManager)
        {
            _userManager   = userManager;
            _signInManager = signInManager;

            IdentitySeedData.Seed(userManager).Wait();
        }
Ejemplo n.º 4
0
        public AccountController(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager, RoleManager <IdentityRole <int> > roleManager, AppDbContext context)
        {
            UserManager   = userManager;
            SignInManager = signInManager;
            RoleManager   = roleManager;
            Context       = context;

            IdentitySeedData.Seed(userManager, roleManager).Wait();
        }