public async Task <bool> Handle(RemoveApiScopeCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var savedClient = await _apiRepository.GetResource(request.ResourceName); if (savedClient == null) { await Bus.RaiseEvent(new DomainNotification("Api", "Api not found")); return(false); } if (savedClient.Scopes.Any(f => f.Name != request.Name)) { await Bus.RaiseEvent(new DomainNotification("Api Scope", "Invalid scope")); return(false); } _apiRepository.RemoveScope(request.ResourceName, request.Name); if (await Commit()) { await Bus.RaiseEvent(new ApiScopeRemovedEvent(request.Name, request.ResourceName)); return(true); } return(false); }
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)); } }