public async Task <string> Handle(JObject jObj, CancellationToken cancellationToken) { var extractedScope = jObj.ToScopeDomain(); var result = await _oauthScopeRepository.GetOAuthScope(extractedScope.Name, cancellationToken); if (result != null) { _logger.LogError($"the scope '{extractedScope.Name}' already exists"); throw new OAuthException(ErrorCodes.INVALID_REQUEST, string.Format(ErrorMessages.SCOPE_ALREADY_EXISTS, extractedScope.Name)); } var scope = OAuthScope.Create(extractedScope.Name); await _oauthScopeRepository.Add(scope, cancellationToken); await _oauthScopeRepository.SaveChanges(cancellationToken); _logger.LogInformation($"the scope '{extractedScope.Name}' has been added"); return(extractedScope.Name); }