示例#1
0
        public virtual async Task <int> UpdateClientAsync(ClientDto client)
        {
            var canInsert = await CanInsertClientAsync(client);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(ClientServiceResources.ClientExistsValue().Description, client.ClientId), ClientServiceResources.ClientExistsKey().Description, client);
            }

            var clientEntity = client.ToEntity();

            var originalClient = await GetClientAsync(client.Id);

            var updated = await ClientRepository.UpdateClientAsync(clientEntity);

            var encryptionKeyEntity = await EncryptionKeyRepository.GetEncryptionKeyByClientIdAsync(clientEntity.Id);

            if (encryptionKeyEntity != null)
            {
                encryptionKeyEntity.Enable = false;
                encryptionKeyEntity        = await EncryptionKeyRepository.UpdateEncryptionKeyAsync(encryptionKeyEntity);
            }

            var encryptionKey = await EncryptionKeyRepository.AddEncryptionKeyAsync(new EncryptionKey { ClientId = clientEntity.Id, EncryptionSecret = client.EncryptionKey, Enable = true });

            await AuditEventLogger.LogEventAsync(new ClientUpdatedEvent(originalClient, client));

            return(updated);
        }