public static void RemoveRowFromTable(DocumentCategoryPoco value) { CloudStorageAccount storageAccount = GetConnection(); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Retrieve a reference to the table. CloudTable table = tableClient.GetTableReference(CategoryTableName); // Create a retrieve operation that expects a customer entity. TableOperation retrieveOperation = TableOperation.Retrieve <DocumentCategory>(value.CategoryName, value.SearchTerm); // Execute the operation. TableResult retrievedResult = table.Execute(retrieveOperation); // Assign the result to a CustomerEntity. DocumentCategory deleteEntity = (DocumentCategory)retrievedResult.Result; // Create the Delete TableOperation. if (deleteEntity != null) { TableOperation deleteOperation = TableOperation.Delete(deleteEntity); // Execute the operation. table.Execute(deleteOperation); } }
public static void AddRowToTable(DocumentCategoryPoco value) { CloudStorageAccount storageAccount = GetConnection(); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); // Retrieve a reference to the table. CloudTable table = tableClient.GetTableReference(CategoryTableName); // Create the TableOperation object that inserts the customer entity. var insertOperation = TableOperation.Insert(value.GetEntity()); // Execute the insert operation (no duplicates allowed) try { table.Execute(insertOperation); } catch (Exception ex) { if (!ex.Message.Contains("Conflict")) { throw new Exception("Error adding category: " + ex.Message); } } // If we are updating, delete the original if ((!string.IsNullOrEmpty(value.OriginalTerm) && (value.SearchTerm != value.OriginalTerm)) || (!string.IsNullOrEmpty(value.OriginalName) && (value.CategoryName != value.OriginalName))) { RemoveRowFromTable(new DocumentCategoryPoco { CategoryName = value.OriginalName, SearchTerm = value.OriginalTerm }); } }