Example #1
0
        public async Task <bool> Handle(DeleteUserRoleCommand request, CancellationToken cancellationToken)
        {
            var user = await _userRepository.GetUserByIdIncludeRolesAsync(request.UserId);

            if (user == null)
            {
                await _bus.RaiseEvent(
                    new DomainNotification(request.UserId.ToString(), "未找到对应的数据", StatusCodes.Status404NotFound),
                    cancellationToken);

                return(false);
            }

            user.Roles.RemoveAll(x => request.RoleIds.Contains(x.Id));

            if (await Commit())
            {
                var key = GirvsEntityCacheDefaults <User> .ByIdCacheKey.Create(user.Id.ToString());

                _bus.RaiseEvent(new RemoveCacheEvent(key), cancellationToken);
                _bus.RaiseEvent(new RemoveCacheListEvent(GirvsEntityCacheDefaults <User> .ListCacheKey.Create()),
                                cancellationToken);
                _bus.RaiseEvent(new RemoveServiceCacheEvent(), cancellationToken);
            }

            return(true);
        }
Example #2
0
        public async Task <IActionResult> DeleteUserRole(int roleId)
        {
            var deleteUserRoleCommand = new DeleteUserRoleCommand(roleId);
            var result = await mediator.Send(deleteUserRoleCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
Example #3
0
        public async Task DeleteUserRole(Guid userId, [FromForm] EditUserRoleViewModel model)
        {
            var command = new DeleteUserRoleCommand(
                userId,
                model.RoleIds
                );

            await _bus.SendCommand(command);

            if (_notifications.HasNotifications())
            {
                var errorMessage = _notifications.GetNotificationMessage();
                throw new GirvsException(StatusCodes.Status400BadRequest, errorMessage);
            }
        }
        public async Task <IActionResult> DeleteUserRoleAsync(DeleteUserRoleCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }