public async Task <IActionResult> DeleteUserRoles([FromBody] ManageUserRoleDTO model) { if (!ModelState.IsValid) { return(BadRequest("Invalid Request model.")); } var user = await userManager.FindByEmailAsync(model.Email); if (user is null) { return(BadRequest($"No user with '{model.Email}' email exits.")); } var response = await userManager.RemoveFromRolesAsync(user, model.Roles); return(Ok(response)); }
private async Task <List <StatusDTO <int, bool> > > AddRolesToUser(IdentityUser user, ManageUserRoleDTO model) { var response = new List <StatusDTO <int, bool> >(); foreach (var role in model.Roles) { var status = new StatusDTO <int, bool> { Name = role }; if (!await roleManager.RoleExistsAsync(role)) { status.Status = false; status.Error = $"{role} NOT_FOUND"; response.Add(status); continue; } var result = await userManager.AddToRoleAsync(user, role); status.Status = result.Succeeded; status.Error = string.Join('\r', result.Errors.Select(e => e.Description)); response.Add(status); } return(response); }