Ejemplo n.º 1
0
        public async Task <bool> Handle(SaveClientClaimCommand 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 claim = request.ToEntity();

            await _clientRepository.AddClaim(request.ClientId, claim);

            if (await Commit())
            {
                await Bus.RaiseEvent(new NewClientClaimEvent(request.ClientId, claim.Type, claim.Value));

                return(true);
            }
            return(false);
        }