Esempio n. 1
0
        public async Task Handle(SaveClientPropertyCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return;
            }

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

            if (savedClient == null)
            {
                await Bus.RaiseEvent(new DomainNotification("1", "Client not found"));

                return;
            }

            var property = new ClientProperty()
            {
                Client = savedClient,
                Value  = request.Value,
                Key    = request.Key
            };

            _clientPropertyRepository.Add(property);

            if (Commit())
            {
                await Bus.RaiseEvent(new NewClientPropertyEvent(request.Id, request.ClientId, property.Key, property.Value));
            }
        }
Esempio n. 2
0
        public async Task <bool> Handle(SaveClientPropertyCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

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

            if (savedClient == null)
            {
                await Bus.RaiseEvent(new DomainNotification("Client", "Client not found"));

                return(false);
            }
            var property = request.ToEntiyTy(savedClient);


            _clientPropertyRepository.Add(property);

            if (await Commit())
            {
                await Bus.RaiseEvent(new NewClientPropertyEvent(request.Id, request.ClientId, property.Key, property.Value));

                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        public async Task <bool> Handle(SaveClientPropertyCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var client = await _clientRepository.FindByClientIdAsync(request.ClientId);

            if (client == null)
            {
                await _bus.RaiseEvent(new DomainNotification("key_not_found", $"Client named {request.ClientId} not found"));

                return(false);
            }

            var property = new ClientProperty
            {
                Client = client,
                Key    = request.Key,
                Value  = request.Value
            };

            await _clientPropertyRepository.AddAsync(property);

            if (Commit())
            {
                await _bus.RaiseEvent(new ClientPropertyAddedEvent(request.ClientId, property.Id, request.Key, request.Value));

                return(true);
            }

            return(false);
        }