Esempio n. 1
0
        public async Task Disable(Guid userId)
        {
            var command = new ChangeUserStateCommand(userId, DataState.Disable);
            await _bus.SendCommand(command);

            if (_notifications.HasNotifications())
            {
                var errorMessage = _notifications.GetNotificationMessage();
                throw new GirvsException(StatusCodes.Status400BadRequest, errorMessage);
            }
        }
Esempio n. 2
0
        public async Task <bool> Handle(ChangeUserStateCommand request, CancellationToken cancellationToken)
        {
            var user = await _userRepository.GetByIdAsync(request.Id);

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

                return(false);
            }

            if (user.UserType is UserType.AdminUser or UserType.TenantAdminUser)
            {
                await _bus.RaiseEvent(
                    new DomainNotification(request.Id.ToString(), "当前用户禁止修改", 568),
                    cancellationToken);

                return(false);
            }

            user.State = request.State;

            await _userRepository.UpdateAsync(user, nameof(User.State));

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

                await _bus.RaiseEvent(new RemoveCacheEvent(key), cancellationToken);

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

            return(true);
        }