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; } }