public async Task<TableStorageResponse<UserSetting>> SetUserSettingValueAsync(UserSetting setting) { var incomingEntity = new UserSettingTableEntity() { PartitionKey = _settingsTablePartitionKey, RowKey = setting.Key, SettingValue = setting.Value }; if (!string.IsNullOrWhiteSpace(setting.Etag)) { incomingEntity.ETag = setting.Etag; } TableStorageResponse<UserSetting> result = await AzureTableStorageHelper.DoTableInsertOrReplaceAsync<UserSetting, UserSettingTableEntity>(incomingEntity, (tableEntity) => { if (tableEntity == null) { return null; } var updatedSetting = new UserSetting() { Key = tableEntity.RowKey, Value = tableEntity.SettingValue, Etag = tableEntity.ETag }; return updatedSetting; }, _storageAccountConnectionString, _settingsTableName); return result; }
public async Task<UserSetting> GetUserSettingValueAsync(string settingKey) { TableOperation query = TableOperation.Retrieve<UserSettingTableEntity>(_settingsTablePartitionKey, settingKey); TableResult response = await Task.Run(() => _azureTableStorageClient.Execute(query) ); UserSetting result = null; if(response.Result != null && response.Result.GetType() == typeof(UserSettingTableEntity)) { result = new UserSetting { Etag = ((UserSettingTableEntity)response.Result).ETag, Key = ((UserSettingTableEntity)response.Result).RowKey, Value = ((UserSettingTableEntity)response.Result).SettingValue }; } return result; }