public async Task <bool> UpdateRole(string id, string role) { var user = await _userManager.FindByIdAsync(id); var higherRoles = RolePriority.HigherRoles(role); var lowerRoles = RolePriority.LowerRoles(role); await _userManager.AddToRolesAsync(user, lowerRoles); await _userManager.RemoveFromRolesAsync(user, higherRoles); await _context.SaveChangesAsync(); return(true); }
protected async Task Save(User user, string role) { var succeeded = await MegaService.HttpClient.PostJsonAsync <bool>("/api/Identity/UpdateRole", JsonConvert.SerializeObject(new { user.Id, Role = role })); if (succeeded) { MegaService.Toastr.Success("Successfully updated."); var lowerRoles = RolePriority.LowerRoles(role); user.Roles = lowerRoles; } else { MegaService.Toastr.Warning("Update failed. Please try again"); } StateHasChanged(); }