public async Task <CheeseReviewEntity> GetCheeseReview(string emailAddress, Guid rowKey) { CheeseReviewEntity returnCheese = null; try { if (client == null) { await InitializeCloudClientAsync(); } // Define a table operation that grabs the exact partition & row key var op = TableOperation.Retrieve <CheeseReviewEntity> (emailAddress, rowKey.ToString()); // Get a table reference var table = client.GetTableReference(reviewTable); // Execute the table operation var result = await table.ExecuteAsync(op); // Parse the return - will need to cast it if (result.Result != null) { returnCheese = (CheeseReviewEntity)result.Result; } } catch (Exception ex) { returnCheese = null; } return(returnCheese); }
async Task AddTableEntityAsync() { var rowKey = Guid.NewGuid(); var entityToSave = new CheeseReviewEntity(this.Email, rowKey); entityToSave.CheeseType = CheeseType; entityToSave.Comments = Comments; entityToSave.DairyName = DairyName; entityToSave.EmailAddress = Email; entityToSave.ReviewDate = DateTime.Now; // First add to Akavache (ideally in Akavache we would also keep track of whether it uploaded successfully or not await BlobCache.LocalMachine.InsertObject <CheeseReviewEntity> ( $"{entityToSave.PartitionKey}|{entityToSave.RowKey}", entityToSave ); // Get the table service var tableService = new CheeseTableService(); bool success = await tableService.SaveReviewAsync(entityToSave); if (success) { // Could display a success or failure message // We should also keep track of whether the entity has been uploaded yet or not for offline access // Pop the modal off the stack await Navigation.PopModalAsync(); } }
public async Task <bool> SaveReviewAsync(CheeseReviewEntity entity) { try { if (client == null) { await InitializeCloudClientAsync(); } // Define the insert operation var operation = TableOperation.InsertOrReplace(entity); // Get a reference to the review table var table = client.GetTableReference(reviewTable); // Execute the insert against the table var result = await table.ExecuteAsync(operation); return(true); } catch (Exception ex) { return(false); } }