public async Task <bool> RemoveRoleToUserAsync(UpdateUserRoleModelRq model) { try { var user = await _userManagement.FindByIdAsync(model.UserId.ToString()); if (user == null) { return(false); } var roles = await _userManagement.GetRolesAsync(user); if (roles.Count > 1) { var rs = await _userManagement.RemoveFromRoleAsync(user, model.RoleName); if (rs.Succeeded) { return(true); } else { return(false); } } else { return(false); } } catch (Exception e) { throw e; } }
public async Task <IActionResult> RemoveRoleToUser(int userId, string roleName) { UpdateUserRoleModelRq model = new UpdateUserRoleModelRq() { UserId = userId, RoleName = roleName }; return(OkValueObject(await _userService.RemoveRoleToUserAsync(model))); }
public async Task <IActionResult> AddRoleToUser([FromBody] UpdateUserRoleModelRq model) { if (!ModelState.IsValid) { Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection(); foreach (var entry in ModelState.Values) { foreach (var error in entry.Errors) { modelErrors.Add(error); } } return(BadRequest(modelErrors)); } return(OkValueObject(await _userService.AddRoleToUserAsync(model))); }
public async Task <bool> AddRoleToUserAsync(UpdateUserRoleModelRq model) { try { var user = await _userManagement.FindByIdAsync(model.UserId.ToString()); if (user == null) { return(false); } var rs = await _userManagement.AddToRoleAsync(user, model.RoleName); if (rs.Succeeded) { return(true); } return(false); } catch (Exception e) { throw e; } }