public async Task AssignRole(EditRoleDTO editRole) { var response = await httpService.Post($"{url}/assignRole", editRole); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } }
public async Task RemoveRole(EditRoleDTO editRole) { var response = await httpService.Post($"{baseURL}/removeRole", editRole); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } }
public async Task <ActionResult> RemoverRolUsuario(EditRoleDTO editarRolDTO) { var usuario = await _userManager.FindByIdAsync(editarRolDTO.UserID); await _userManager.RemoveClaimAsync(usuario, new Claim(ClaimTypes.Role, editarRolDTO.RoleName)); await _userManager.RemoveFromRoleAsync(usuario, editarRolDTO.RoleName); return(Ok()); }
public async Task <ActionResult> RemoveRole(EditRoleDTO editRoleDTO) { var user = await _userManager.FindByIdAsync(editRoleDTO.UserId); if (user == null) { return(NotFound()); } await _userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDTO.RoleName)); return(NoContent()); }
public async Task <ActionResult> AssignRole([FromBody] EditRoleDTO editRoleDTO) { var user = await userManager.FindByIdAsync(editRoleDTO.UserId); if (user == null) { return(NotFound()); } await userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDTO.RoleName)); return(NoContent()); }
public async Task <ActionResult> AsignRole(EditRoleDTO editRoleDTO) { var user = await userManager.FindByIdAsync(editRoleDTO.UserId); if (user is null) { return(NotFound()); } await userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDTO.RoleName)); await userManager.AddToRoleAsync(user, editRoleDTO.RoleName); return(Ok()); }
public async Task <ActionResult> DeleteUserRole(EditRoleDTO editRoleDTO) { var user = await userManager.FindByNameAsync(editRoleDTO.userId); if (user == null) { return(NotFound()); } await userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDTO.RoleName)); await userManager.RemoveFromRoleAsync(user, editRoleDTO.RoleName); return(Ok()); }
public async Task <ActionResult> RemoveRole(EditRoleDTO editRoleDTO) { var result = await _accountsService.RemoveUserRoleAsync(editRoleDTO); if (result == -1) { return(NotFound()); } else if (result == 0) { return(BadRequest("Failed to save changes.")); } return(NoContent()); }
public async Task <ActionResult> RemoveRole([FromBody] EditRoleDTO editRole) { //identificar el usuario var user = await userManager.FindByIdAsync(editRole.UserId); if (user == null) { return(NotFound()); } //asignacion del rol await userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, editRole.RoleName)); //await userManager.RemoveToRoleAsync(user, editRole.RoleName); asi tambien se puede return(NoContent()); }
public async Task <ActionResult> RemoveUserRole(EditRoleDTO editRoleDTO) { var user = await _userManager.FindByIdAsync(editRoleDTO.UserId); if (user == null) { return(NotFound()); } // IdentityUser await _userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDTO.RoleName)); // Jwt User await _userManager.RemoveFromRoleAsync(user, editRoleDTO.RoleName); return(Ok()); }
public async Task <ActionResult> RemoveRole(EditRoleDTO editRole) { var user = await _userManager.FindByIdAsync(editRole.UserId); if (user == null) { return(NotFound()); } //1st way of removing role from user: removing claim await _userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, editRole.RoleName)); //2nd way of removing role from user: adding role directly //await _userManager.RemoveFromRoleAsync(user, editRole.RoleName); return(NoContent()); }
public async Task <ActionResult> AssignRole(EditRoleDTO editRole) { var user = await _userManager.FindByIdAsync(editRole.UserId); if (user == null) { return(NotFound()); } //1st way of assigning role to user: adding claim await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, editRole.RoleName)); //2nd way of assigning role to user: adding role directly //await _userManager.AddToRoleAsync(user, editRole.RoleName); return(NoContent()); }
public async Task <int> RemoveUserRoleAsync(EditRoleDTO editRoleDTO) { var user = await _userManager.FindByIdAsync(editRoleDTO.UserId); if (user == null) { _logger.LogWarn($"User {editRoleDTO.UserId} was not found."); return(-1); } try { await _userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDTO.RoleName)); _logger.LogInfo($"Removed user {user.Email} from {editRoleDTO.RoleName} role."); return(1); } catch (Exception ex) { _logger.LogWarn($"Failed to remove user {user.Email} to {editRoleDTO.RoleName} role. Exception: {ex}"); return(0); } }
public async Task <ActionResult> RemoveRole(EditRoleDTO editRoleDTO) { await usersRepository.RemoveRole(editRoleDTO); return(NoContent()); }
public async Task RemoveRole(EditRoleDTO editRoleDto) { var user = await userManager.FindByIdAsync(editRoleDto.UserId); await userManager.RemoveClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDto.RoleName)); }
public async Task AssignRole(EditRoleDTO editRoleDTO) { var user = await userManager.FindByIdAsync(editRoleDTO.UserId); await userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, editRoleDTO.RoleName)); }