Exemplo n.º 1
0
        public async Task <Result> FindRoleByNameAsync(string roleName)
        {
            var role = await _roleManager.FindByNameAsync(roleName);

            if (role is null)
            {
                return(Result.Failure(new[] { $"Unable to find role '{roleName}'" }));
            }

            return(IdentityRoleResult.Success(role));
        }
Exemplo n.º 2
0
        public async Task <Result> CreateRoleAsync(string roleName)
        {
            var role   = new IdentityRole(roleName);
            var result = await _roleManager.CreateAsync(role);

            if (result.Succeeded == false)
            {
                var errors = result.Errors.Select(x => x.Description).ToArray();
                return(Result.Failure(errors));
            }

            return(IdentityRoleResult.Success(role));
        }