public async Task <bool> Handle(RemoveUserRoleCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var userDb = await _userService.FindByNameAsync(request.Username);

            if (userDb == null)
            {
                await Bus.RaiseEvent(new DomainNotification("Username", "User not found"));

                return(false);
            }

            var success = await _userService.RemoveRole(userDb.Id, request.Role);

            if (success)
            {
                await Bus.RaiseEvent(new UserRoleRemovedEvent(_user.UserId, request.Username, request.Role));

                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public void RemoveUserRole(Guid userId, Guid roleId)
        {
            userContext.CheckPermission(Permissions.UserMaintenance);

            var command = new RemoveUserRoleCommand(userId, roleId);

            commandBus.Value.Send(Envelope.Create(command));
        }
        /// <summary>
        /// حذف نقش کاربر
        /// </summary>
        /// <param name="command"></param>
        public void RemoveUserRole(RemoveUserRoleCommand command)
        {
            var user = _repository.FindUser(command.UserId).Result;

            if (user == null)
            {
                throw new CustomException("کاربر یافت نشد");
            }
            var identityResult = _repository.RemoveUserRole(user, new IdentityRole
            {
                Name = command.RoleName
            }).Result;

            if (!identityResult.Succeeded)
            {
                throw new CustomException(identityResult.Errors.Aggregate("",
                                                                          (current, error) => current + error + "\n"));
            }
        }
Beispiel #4
0
        private void RemoveRole(Guid userId, Guid roleId)
        {
            var command = new RemoveUserRoleCommand(userId, roleId);

            commandBus.Value.Send(Envelope.Create(command));
        }