コード例 #1
0
        public Task Handle(CreateUserEvent @event, [FromCap] CapHeader header, CancellationToken cancellationToken)
        {
            //需要重新设置身份认证头
            EngineContext.Current.ClaimManager.CapEventBusReSetClaim(header);

            _logger.LogInformation($"Handling 'CreateUserEvent' eventId:{@event.Id}");

            var cacheConfig = EngineContext.Current.GetAppModuleConfig <CacheConfig>();
            var timeSpan    = TimeSpan.FromSeconds(cacheConfig.CacheBaseConfig.DefaultCacheTime);

            _locker.PerformActionWithLock(@event.Id.ToString(),
                                          timeSpan, () =>
            {
                var command = new EventCreateUserCommand(
                    @event.UserAccount,
                    @event.UserPassword.ToMd5(),
                    @event.UserName,
                    @event.ContactNumber,
                    DataState.Enable,
                    UserType.TenantAdminUser,     //此处创建的为租户管理员
                    @event.TenantId
                    );
                _bus.SendCommand(command, cancellationToken).Wait(cancellationToken);
                if (_notifications.HasNotifications())
                {
                    var errorMessage = _notifications.GetNotificationMessage();
                    _logger.LogError(
                        $"Handling 'CreateUserEvent' event Error Code:{400},Message:{errorMessage}",
                        @event);
                }
            });
            return(Task.CompletedTask);
        }
コード例 #2
0
ファイル: UserCommandHandler.cs プロジェクト: girvs/Girvs
        public async Task <bool> Handle(EventCreateUserCommand request, CancellationToken cancellationToken)
        {
            var existUser = await _userRepository.GetUserByLoginNameAsync(request.UserAccount);

            if (existUser != null)
            {
                await _bus.RaiseEvent(new DomainNotification(nameof(request.UserAccount), "登陆名称已存在"),
                                      cancellationToken);

                return(false);
            }

            var user = new User
            {
                ContactNumber = request.ContactNumber,
                State         = request.State,
                UserAccount   = request.UserAccount,
                UserName      = request.UserName,
                UserPassword  = request.UserPassword,
                UserType      = request.UserType,
                OtherId       = request.OtherId
            };

            user.TenantId = request.TenantId ?? user.TenantId;

            await _userRepository.CreateTenantIdAdmin(user);

            if (!await Commit())
            {
                return(false);
            }

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

            _bus.RaiseEvent(new RemoveCacheEvent(key), cancellationToken);
            _bus.RaiseEvent(new RemoveCacheListEvent(GirvsEntityCacheDefaults <User> .ListCacheKey.Create()),
                            cancellationToken);
            request.Id = user.Id;
            return(true);
        }