Esempio n. 1
0
        public async Task <IActionResult> DeleteRole(string id)
        {
            Role appRole = await _accountManager.GetRoleByIdAsync(id);

            if (appRole == null)
            {
                return(NotFound(id));
            }

            if (!await _accountManager.TestCanDeleteRoleAsync(id))
            {
                return(BadRequest("Role cannot be deleted. Remove all users from this role and try again"));
            }

            RoleViewModel roleVM = await GetRoleViewModelHelper(appRole.Name);

            (bool Succeeded, string[] Errors)result = await _accountManager.DeleteRoleAsync(appRole);

            if (!result.Succeeded)
            {
                throw new Exception("The following errors occurred whilst deleting role: " + string.Join(", ", result.Errors));
            }

            return(Ok(roleVM));
        }