public async Task <bool> Handle(SaveApiScopeCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var savedApi = await _apiResourceRepository.GetByName(request.ResourceName); if (savedApi == null) { await Bus.RaiseEvent(new DomainNotification("Api", "Api not found")); return(false); } var secret = request.ToEntity(savedApi); _apiScopeRepository.Add(secret); if (await Commit()) { await Bus.RaiseEvent(new ApiSecretSavedEvent(request.Id, request.ResourceName)); return(true); } return(false); }
public async Task <bool> Handle(SaveApiScopeCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var savedClient = await _apiResourceRepository.GetByName(request.ResourceName); if (savedClient == null) { await Bus.RaiseEvent(new DomainNotification("1", "Client not found")); return(false); } var secret = new ApiScope() { ApiResource = savedClient, Description = request.Description, Required = request.Required, DisplayName = request.DisplayName, Emphasize = request.Emphasize, Name = request.Name, ShowInDiscoveryDocument = request.ShowInDiscoveryDocument, UserClaims = request.UserClaims.Select(s => new ApiScopeClaim() { Type = s }).ToList(), }; _apiScopeRepository.Add(secret); if (Commit()) { await Bus.RaiseEvent(new ApiSecretSavedEvent(request.Id, request.ResourceName)); return(true); } return(false); }