/// <summary> /// Add new client, this method doesn't save client secrets, client claims, client properties /// </summary> /// <param name="client"></param> /// <returns>This method return new client id</returns> public virtual async Task <int> AddClientAsync(ClientDto client) { var canInsert = await CanInsertClientAsync(client); if (!canInsert) { throw new UserFriendlyViewException(string.Format(ClientServiceResources.ClientExistsValue().Description, client.ClientId), ClientServiceResources.ClientExistsKey().Description, client); } PrepareClientTypeForNewClient(client); var clientEntity = client.ToEntity(); try { var added = await ClientRepository.AddClientAsync(clientEntity); if (client.EncryptionKey?.Length > 0) { var encryptionKey = await EncryptionKeyRepository.AddEncryptionKeyAsync(new EncryptionKey { ClientId = clientEntity.Id, EncryptionSecret = client.EncryptionKey, Enable = true }); } await AuditEventLogger.LogEventAsync(new ClientAddedEvent(client)); return(added); } catch { throw; } }
public virtual async Task <EncryptionKeyDto> AddEncryptionKeyAsync(EncryptionKeyDto encryptionKeyDto) { var encryptionKeyEntity = encryptionKeyDto.ToEntity(); var encryptionKey = await Repository.AddEncryptionKeyAsync(encryptionKeyEntity); encryptionKeyDto = encryptionKey.ToModel(); await AuditEventLogger.LogEventAsync(new EncryptionKeyRequestedEvent()); return(encryptionKeyDto); }