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

            var savedClient = await _apiResourceRepository.GetResource(request.ResourceName);

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

                return;
            }

            if (savedClient.Scopes.All(f => f.Id != request.Id))
            {
                await Bus.RaiseEvent(new DomainNotification("3", "Invalid scope"));

                return;
            }

            var scopeToremove = savedClient.Scopes.First(f => f.Id == request.Id);

            _apiScopeRepository.Remove(scopeToremove.Id);

            if (Commit())
            {
                await Bus.RaiseEvent(new ApiScopeRemovedEvent(request.Id, request.ResourceName, scopeToremove.Name));
            }
        }