public async Task SetConfigAsync(IOspSession systemSession, string key, object value) { var document = await _configurationCollection.DocumentAsync(systemSession, key); if (document == null) { document = new OspConfiguration { Key = key, Value = value }; await _configurationCollection.InsertAsync(systemSession, document); } else { document.Value = value; await _configurationCollection.ReplaceByIdAsync(systemSession, key, document); } }
public async Task StoreAsync(OspIdentityProvider identityProvider) { var session = await _repository.StartSessionAsync(); session.StartTransaction(); var persistentProvider = await GetAsync(identityProvider.Alias); if (persistentProvider == null) { await _providerCollection.InsertAsync(session, identityProvider); } else { await _providerCollection.ReplaceByIdAsync(session, identityProvider.Id, identityProvider); } await session.CommitTransactionAsync(); }
public async Task UpdateAsync(string clientId, OspClient client) { ArgumentValidation.ValidateString(nameof(clientId), clientId); ArgumentValidation.Validate(nameof(client), client); var session = await _repository.StartSessionAsync(); session.StartTransaction(); var dbClient = await GetClientByClientId(session, clientId); if (dbClient == null) { throw new EntityNotFoundException($"Client id '{clientId}' does not exist."); } await _clientCollection.ReplaceByIdAsync(session, dbClient.Id, client); await session.CommitTransactionAsync(); }
public async Task StorePermissionAsync(OspPermission ospPermission) { ArgumentValidation.Validate(nameof(ospPermission), ospPermission); var session = await _repository.StartSessionAsync(); session.StartTransaction(); var persistentPermission = await GetPermissionById(ospPermission.PermissionId); if (persistentPermission == null) { await _permissionCollection.InsertAsync(session, ospPermission); } else { await _permissionCollection.ReplaceByIdAsync(session, persistentPermission.Id, ospPermission); } await session.CommitTransactionAsync(); }
public async Task StoreAsync(PersistedGrant grant) { var session = await _repository.StartSessionAsync(); session.StartTransaction(); var persistedGrant = (OspPersistedGrant) await GetAsync(session, grant.Key); if (persistedGrant == null) { var appGrant = GetApplicationPersistedGrant(grant); await _persistentGrantCollection.InsertAsync(session, appGrant); } else { var appGrant = GetApplicationPersistedGrant(grant); await _persistentGrantCollection.ReplaceByIdAsync(session, persistedGrant.Id, appGrant); } await session.CommitTransactionAsync(); }