Exemplo n.º 1
0
        private async void createSuperAdmin()
        {
            var user = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**", TenantId = 0, EmailConfirmed = true
            };
            ApplicationDbContext <ApplicationUser> context   = new ApplicationDbContext <ApplicationUser>();
            ApplicationUserStore <ApplicationUser> userStore = new ApplicationUserStore <ApplicationUser>(context);

            ApplicationUserManager aUM = new ApplicationUserManager(userStore);
            var roleStore = new RoleStore <IdentityRole>(context);
            var roleMngr  = new RoleManager <IdentityRole>(roleStore);

            List <IdentityRole> roles       = roleMngr.Roles.ToList();
            List <string>       roleStrings = new List <string>();

            foreach (IdentityRole ir in roles)
            {
                roleStrings.Add(ir.Name.ToString());
            }
            if (aUM.FindByEmail("*****@*****.**") == null)
            {
                var result = await aUM.CreateAsync(user, "Admin123");

                await aUM.AddToRoleAsync(user.Id.ToString(), "Admin");

                await aUM.AddToRoleAsync(user.Id.ToString(), "SuperAdmin");
            }
        }
Exemplo n.º 2
0
        public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options, IOwinContext context)
        {
            cont = context;
            opt  = options;
            ApplicationDbContext <ApplicationUser> pp        = new ApplicationDbContext <ApplicationUser>();
            ApplicationUserStore <ApplicationUser> userStore = new ApplicationUserStore <ApplicationUser>(pp);

            return(new ApplicationUserManager(userStore));
        }