コード例 #1
0
        public async Task <bool> Handle(RemoveClientClaimCommand 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 claim = await _clientClaimRepository.FindByIdAsync(request.Id);

            if (claim != null)
            {
                await _clientClaimRepository.RemoveAsync(claim);

                if (Commit())
                {
                    await _bus.RaiseEvent(new ClientClaimRemovedEvent(request.ClientId, request.Id));

                    return(true);
                }
            }

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

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

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

                return(false);
            }

            if (savedClient.Claims.All(f => f.Id != request.Id))
            {
                await Bus.RaiseEvent(new DomainNotification("Client Claims", "Invalid Claim"));

                return(false);
            }

            _clientClaimRepository.Remove(request.Id);

            if (await Commit())
            {
                await Bus.RaiseEvent(new ClientClaimRemovedEvent(request.Id, request.ClientId));

                return(true);
            }
            return(false);
        }
コード例 #3
0
 public async Task RemoveClaimAsync(string clientId, int id)
 {
     var command = new RemoveClientClaimCommand(clientId, id);
     await _bus.SendCommand(command);
 }