Ejemplo n.º 1
0
        public async Task <bool> CanInsertRoleAsync(RoleIdentity role)
        {
            var existsWithSameName =
                await _roleManager.Roles.Where(x => x.Name == role.Name).SingleOrDefaultAsync();

            return(existsWithSameName == null);
        }
Ejemplo n.º 2
0
        public async Task <IdentityResult> UpdateRoleAsync(RoleIdentity role)
        {
            var thisRole = await _roleManager.FindByIdAsync(role.Id.ToString());

            thisRole.Name = role.Name;
            return(await _roleManager.UpdateAsync(thisRole));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generate default admin user / role
        /// </summary>
        private static async Task EnsureSeedIdentityData(
            UserManager <UserIdentity> userManager,
            RoleManager <RoleIdentity> roleManager,
            IConfiguration configuration)
        {
            // Create admin role
            if (!await roleManager.RoleExistsAsync("Administrator"))
            {
                var role = new RoleIdentity {
                    Name = "Administrator"
                };

                await roleManager.CreateAsync(role);
            }

            // Create admin user
            if (await userManager.FindByNameAsync(Users.GetUser(configuration)) != null)
            {
                return;
            }

            var user = new UserIdentity
            {
                UserName       = Users.GetUser(configuration),
                Email          = Users.GetEmail(configuration),
                EmailConfirmed = true,
                LockoutEnd     = null
            };

            var result = await userManager.CreateAsync(user, Users.GetPassword(configuration));

            if (result.Succeeded)
            {
                await userManager.AddClaimAsync(user, new Claim("is4-rights", "manager"));

                await userManager.AddClaimAsync(user, new Claim("admin-rights", "manager"));

                await userManager.AddClaimAsync(user, new Claim("username", Users.GetUser(configuration)));

                await userManager.AddClaimAsync(user, new Claim("email", Users.GetEmail(configuration)));

                await userManager.AddToRoleAsync(user, "Administrator");
            }
        }
Ejemplo n.º 4
0
        public async Task <(IdentityResult identityResult, Guid?roleId)> CreateRoleAsync(RoleIdentity role)
        {
            var identityResult = await _roleManager.CreateAsync(role);

            return(identityResult, role.Id);
        }
Ejemplo n.º 5
0
 public static RoleDto ToModel(this RoleIdentity role)
 {
     return(role == null ? null : Mapper.Map <RoleDto>(role));
 }