Пример #1
0
        public async Task <IResult> UpdateRolesAsync(UpdateUserRolesRequest request)
        {
            var user = await _userManager.FindByIdAsync(request.UserId);

            if (user.Email == "*****@*****.**")
            {
                return(await Result.FailAsync(_localizer["Not Allowed."]));
            }

            var roles = await _userManager.GetRolesAsync(user);

            var selectedRoles = request.UserRoles.Where(x => x.Selected).ToList();

            var currentUser = await _userManager.FindByIdAsync(_currentUserService.UserId);

            if (!await _userManager.IsInRoleAsync(currentUser, RoleConstants.AdministratorRole))
            {
                var tryToAddAdministratorRole = selectedRoles
                                                .Any(x => x.RoleName == RoleConstants.AdministratorRole);
                var userHasAdministratorRole = roles.Any(x => x == RoleConstants.AdministratorRole);
                if (tryToAddAdministratorRole && !userHasAdministratorRole || !tryToAddAdministratorRole && userHasAdministratorRole)
                {
                    return(await Result.FailAsync(_localizer["Not Allowed to add or delete Administrator Role if you have not this role."]));
                }
            }

            var result = await _userManager.RemoveFromRolesAsync(user, roles);

            result = await _userManager.AddToRolesAsync(user, selectedRoles.Select(y => y.RoleName));

            return(await Result.SuccessAsync(_localizer["Roles Updated"]));
        }
Пример #2
0
 public override Task <BooleanObject> UpdateUserRoles(UpdateUserRolesRequest request, ServerCallContext context)
 {
     _userDao.UpdateUserRoles(request.UserId, request.Roles.ToList());
     return(Task.FromResult(new BooleanObject {
         Body = true
     }));
 }
Пример #3
0
        public Response <bool> UpdateRoles(UpdateRolesModel model)
        {
            var request = new UpdateUserRolesRequest();

            request.UserId = model.UserId;
            request.Roles.AddRange(model.RoleIdList);

            var response = _client.UpdateUserRoles(request);

            return(response.Body);
        }
Пример #4
0
        public async Task <IResult> UpdateRolesAsync(UpdateUserRolesRequest request)
        {
            var user = await _userManager.FindByIdAsync(request.UserId);

            if (user.Email == "*****@*****.**")
            {
                return(Result.Fail("Not Allowed."));
            }
            var roles = await _userManager.GetRolesAsync(user);

            var result = await _userManager.RemoveFromRolesAsync(user, roles);

            result = await _userManager.AddToRolesAsync(user, request.UserRoles.Where(x => x.Selected).Select(y => y.RoleName));

            return(Result.Success("Roles Updated"));
        }
Пример #5
0
        //TODO check if this is email reason for authenitcation
        public async Task <IResult> UpdateRolesAsync(UpdateUserRolesRequest request)
        {
            var user = await _userManager.FindByIdAsync(request.UserId);

            if (user.Email == "*****@*****.**")
            {
                return(await Result.FailAsync(_localizer["Not Allowed."]));
            }
            var roles = await _userManager.GetRolesAsync(user);

            var result = await _userManager.RemoveFromRolesAsync(user, roles);

            result = await _userManager.AddToRolesAsync(user, request.UserRoles.Where(x => x.Selected).Select(y => y.RoleName));

            return(await Result.SuccessAsync(_localizer["Roles Updated"]));
        }
Пример #6
0
        private async Task SaveAsync()
        {
            var request = new UpdateUserRolesRequest()
            {
                UserId    = Id,
                UserRoles = UserRolesList
            };
            var result = await _userManager.UpdateRolesAsync(request);

            if (result.Succeeded)
            {
                _snackBar.Add(localizer[result.Messages[0]], Severity.Success);
                _navigationManager.NavigateTo("/identity/users");
            }
            else
            {
                foreach (var error in result.Messages)
                {
                    _snackBar.Add(localizer[error], Severity.Error);
                }
            }
        }
Пример #7
0
        private async Task SaveAsync()
        {
            var request = new UpdateUserRolesRequest()
            {
                UserId    = Id,
                UserRoles = UserRolesList
            };
            var result = await _userManager.UpdateRolesAsync(request);

            if (result.Succeeded)
            {
                _navigationManager.NavigateTo($"/identity/user-roles/{Id}");
                await _message.Success(result.Messages[0]);
            }
            else
            {
                foreach (var error in result.Messages)
                {
                    await _message.Error(error);
                }
            }
        }
        public async Task <UpdateUserRolesResponse> UpdateUserRolesAsync(
            long customerId,
            long userId,
            int?newRoleId,
            IList <long> newAccountIds,
            IList <long> newCustomerIds,
            int?deleteRoleId,
            IList <long> deleteAccountIds,
            IList <long> deleteCustomerIds)
        {
            var request = new UpdateUserRolesRequest
            {
                CustomerId        = customerId,
                UserId            = userId,
                NewRoleId         = newRoleId,
                NewAccountIds     = newAccountIds,
                NewCustomerIds    = newCustomerIds,
                DeleteRoleId      = deleteRoleId,
                DeleteAccountIds  = deleteAccountIds,
                DeleteCustomerIds = deleteCustomerIds
            };

            return(await CustomerManagementService.CallAsync((s, r) => s.UpdateUserRolesAsync(r), request));
        }
 public async Task <IActionResult> UpdateRolesAsync(UpdateUserRolesRequest request)
 {
     return(Ok(await _userService.UpdateRolesAsync(request)));
 }
        public async Task <IResult> UpdateRolesAsync(UpdateUserRolesRequest request)
        {
            var response = await _httpClient.PutAsJsonAsync(Routes.UserEndpoint.GetUserRoles(request.UserId), request);

            return(await response.ToResult <UserRolesResponse>());
        }