public static async Task <TableStorageResponse <TResult> > DoTableInsertOrReplaceAsync <TResult, TInput>(TInput incomingEntity, Func <TInput, TResult> tableEntityToModelConverter, string storageAccountConnectionString, string tableName) where TInput : TableEntity { var table = await AzureTableStorageHelper.GetTableAsync(storageAccountConnectionString, tableName); // Simply doing an InsertOrReplace will not do any concurrency checking, according to // http://azure.microsoft.com/en-us/blog/managing-concurrency-in-microsoft-azure-storage-2/ // So we will not use InsertOrReplace. Instead we will look to see if we have a rule like this // If so, then we'll do a concurrency-safe update, otherwise simply insert TableOperation retrieveOperation = TableOperation.Retrieve <TInput>(incomingEntity.PartitionKey, incomingEntity.RowKey); TableResult retrievedEntity = await table.ExecuteAsync(retrieveOperation); TableOperation operation = null; if (retrievedEntity.Result != null) { operation = TableOperation.Replace(incomingEntity); } else { operation = TableOperation.Insert(incomingEntity); } return(await PerformTableOperation <TResult, TInput>(table, operation, incomingEntity, tableEntityToModelConverter)); }
public static async Task <TableStorageResponse <TResult> > DoDeleteAsync <TResult, TInput>(TInput incomingEntity, Func <TInput, TResult> tableEntityToModelConverter, string storageAccountConnectionString, string tableName) where TInput : TableEntity { var azureTable = await AzureTableStorageHelper.GetTableAsync(storageAccountConnectionString, tableName); TableOperation operation = TableOperation.Delete(incomingEntity); return(await PerformTableOperation <TResult, TInput>(azureTable, operation, incomingEntity, tableEntityToModelConverter)); }