private async Task<BlockchainExplorerEntity> GetBlockchainExplorerEntity(string type, string recordId) { BlockchainExplorerEntity entity = await _table.GetDataAsync(BlockchainExplorerEntity.GetPartitionKey(type), BlockchainExplorerEntity.GetRowKey(recordId)); return entity; }
public async Task<IEnumerable<BlockchainExplorer>> GetAllForBlockchainAsync(string blockchainType) { var allExplorers = await _table.GetDataAsync(BlockchainExplorerEntity.GetPartitionKey(blockchainType)); var mapped = allExplorers.Select(entity => entity.ToDomain()); return mapped; }
/// <inheritdoc /> public async Task CreateAsync(BlockchainExplorer explorer) { var existing = await GetBlockchainExplorerEntity(explorer.BlockchainType, explorer.RecordId); if (existing != null) throw new AlreadyExistsException($"Setting with type {explorer.BlockchainType} is already exists"); BlockchainExplorerEntity entity = BlockchainExplorerEntity.FromDomain(explorer); await _table.InsertAsync(entity); }
/// <inheritdoc />> public async Task RemoveAsync(string type, string recordId) { string partitionKey = BlockchainExplorerEntity.GetPartitionKey(type); string rowKey = BlockchainExplorerEntity.GetRowKey(recordId); var existing = await GetBlockchainExplorerEntity(type, recordId); if (existing == null) throw new DoesNotExistException($"Settings with type {type} does not exist"); await _table.DeleteIfExistAsync(partitionKey, rowKey); }
/// <inheritdoc /> public async Task UpdateAsync(BlockchainExplorer explorer) { BlockchainExplorerEntity entity = BlockchainExplorerEntity.FromDomain(explorer); string partitionKey = BlockchainExplorerEntity.GetPartitionKey(explorer.BlockchainType); string rowKey = BlockchainExplorerEntity.GetRowKey(explorer.RecordId); string errorMessage = null; bool isUpdated = false; try { isUpdated = await _table.InsertOrModifyAsync(partitionKey, rowKey, () => entity, model => { if (model.ETag != entity.ETag) { errorMessage = $"Entity with type {model.BlockchainType} has eTag == {model.ETag}, eTag in update request is {entity.ETag}"; return false; } model.BlockchainType = entity.BlockchainType; model.ExplorerUrlTemplate = entity.ExplorerUrlTemplate; model.RecordId = entity.RecordId; model.ETag = entity.ETag; model.PartitionKey = entity.PartitionKey; model.RowKey = entity.RowKey; model.Name = entity.Name; return true; }); } catch (Exception e) { throw new DoesNotExistException(e.Message); } if (!isUpdated) throw new AlreadyUpdatedException(errorMessage); }