Exemplo n.º 1
0
        /// <inheritdoc />
        public async Task UpdateAsync(BlockchainSetting settings)
        {
            BlockchainSettingEntity entity = BlockchainSettingEntity.FromDomain(settings);

            string partitionKey = BlockchainSettingEntity.GetPartitionKey(settings.Type);
            string rowKey       = BlockchainSettingEntity.GetRowKey(settings.Type);
            string errorMessage = null;

            bool isUpdated = await _table.InsertOrModifyAsync(partitionKey, rowKey, () => entity, model =>
            {
                if (model.ETag != entity.ETag)
                {
                    errorMessage = $"Entity with type {model.Type} has eTag == {model.ETag}, eTag in update request is {entity.ETag}";

                    return(false);
                }

                model.Type             = entity.Type;
                model.ApiUrl           = entity.ApiUrl;
                model.HotWalletAddress = entity.HotWalletAddress;
                model.SignServiceUrl   = entity.SignServiceUrl;
                model.ETag             = entity.ETag;
                model.PartitionKey     = entity.PartitionKey;
                model.RowKey           = entity.RowKey;

                return(true);
            });

            if (!isUpdated)
            {
                throw new AlreadyUpdatedException(errorMessage);
            }
        }
Exemplo n.º 2
0
        private async Task <BlockchainSettingEntity> GetBlockchainSettingEntity(string type)
        {
            BlockchainSettingEntity entity = await _table.GetDataAsync(BlockchainSettingEntity.GetPartitionKey(type),
                                                                       BlockchainSettingEntity.GetRowKey(type));

            return(entity);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public async Task CreateAsync(BlockchainSetting settings)
        {
            var existing = await GetBlockchainSettingEntity(settings.Type);

            if (existing != null)
            {
                throw new AlreadyExistsException($"Setting with type {settings.Type} is already exists");
            }

            BlockchainSettingEntity entity = BlockchainSettingEntity.FromDomain(settings);

            await _table.InsertAsync(entity);
        }
Exemplo n.º 4
0
        /// <inheritdoc />>
        public async Task RemoveAsync(string type)
        {
            string partitionKey = BlockchainSettingEntity.GetPartitionKey(type);
            string rowKey       = BlockchainSettingEntity.GetRowKey(type);
            BlockchainSettingEntity existing = await GetBlockchainSettingEntity(type);

            if (existing == null)
            {
                throw new DoesNotExistException($"Settings with type {type} does not exist");
            }

            await _table.DeleteIfExistAsync(partitionKey, rowKey);
        }