public async Task <IActionResult> AddUserToRole(int userId, string roleName) { var user = await userManager.FindByIdAsync(userId); var rez = await userManager.AddToRoleAsync(user, roleName); if (!rez.Succeeded) { return(BadRequest()); } await jweBlackListService.AddAllUserTokensToBlackListAsync(userId); return(Ok()); }
public async Task <IActionResult> AddUserToRole(int userId, string roleName) { var user = await userManager.FindByIdAsync(userId); if (User.IsInRole(RoleNames.Admin) && RoleNames.Banned == roleName) { throw new SunException("Impossible to ban admin role"); } var rez = await userManager.AddToRoleAsync(user, roleName); if (!rez.Succeeded) { return(BadRequest()); } await jweBlackListService.AddAllUserTokensToBlackListAsync(userId); return(Ok()); }