コード例 #1
0
        public async Task <bool> Handle(SaveClientCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId);

            if (savedClient != null)
            {
                await Bus.RaiseEvent(new DomainNotification("Client", "Client already exists"));

                return(false);
            }

            var client = request.ToEntity();

            _clientRepository.Add(client);

            if (await Commit())
            {
                await Bus.RaiseEvent(new NewClientEvent(request.Client.ClientId, request.ClientType, request.Client.ClientName));

                return(true);
            }

            return(false);
        }
コード例 #2
0
        public async Task Handle(SaveClientCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return;
            }

            var savedClient = await _clientRepository.GetByClientId(request.Client.ClientId);

            if (savedClient != null)
            {
                await Bus.RaiseEvent(new DomainNotification("1", "Client already exists"));

                return;
            }

            PrepareClientTypeForNewClient(request);
            var client = request.Client.ToEntity();

            client.Description = request.Description;

            _clientRepository.Add(client);

            if (Commit())
            {
                await Bus.RaiseEvent(new NewClientEvent(request.Client.ClientId, request.ClientType, request.Client.ClientName));
            }
        }