public bool AddApple(Apple apple) { // Retrieve storage account from connection-string var storageAccount = CloudStorageAccount.Parse( (StorageConnectionString)); // Create the table client var tableClient = storageAccount.CreateCloudTableClient(); // Create the table if it doesn't exist tableClient.CreateTableIfNotExist(AppleTableName); // Get the data service context var serviceContext = tableClient.GetDataServiceContext(); // Add the new person to the people table serviceContext.AddObject(AppleTableName, apple); // Submit the operation to the table service serviceContext.SaveChangesWithRetries(); SendToastMessage("New apples", apple.Applecount.ToString() + " apples added"); return true; }
public bool ReserveApple(Apple apple) { // Retrieve storage account from connection-string var storageAccount = CloudStorageAccount.Parse( (StorageConnectionString)); // Create the table client var tableClient = storageAccount.CreateCloudTableClient(); // Create the table if it doesn't exist tableClient.CreateTableIfNotExist(AppleTableName); // Get the data service context var serviceContext = tableClient.GetDataServiceContext(); var selectedApple = serviceContext.CreateQuery<Apple>(AppleTableName).Where(e => e.RowKey == apple.RowKey).First(); if (selectedApple != null) { selectedApple.Reserved = true; SendToastMessage("Your apple was reserved", "Tap to check details"); } // Add the new person to the people table //var alls = GetApples(); //var theOne = alls.Where(e => e.RowKey == apple.RowKey).First(); // Submit the operation to the table service serviceContext.SaveChangesWithRetries(); SendToastMessage("New apples", apple.Applecount.ToString() + " apples added"); return true; }