Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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();
        }