public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "food/{id}")] HttpRequest req, [Table(Constants.TableName)] CloudTable foodDishTable, [Table(Constants.TableName, Constants.PartitionKey, "{id}")] FoodDishTableEntity foodDishTableEntity, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); if (foodDishTableEntity == null) { return(new NotFoundResult()); } string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); if (!requestBody.IsValidJson <FoodDish>(out IList <string> errorMessages)) { return(new BadRequestObjectResult(errorMessages)); } FoodDish incommingFoodDish = JsonConvert.DeserializeObject <FoodDish>(requestBody); foodDishTableEntity.Replace(incommingFoodDish); var replaceOperation = TableOperation.Replace(foodDishTableEntity); await foodDishTable.ExecuteAsync(replaceOperation); log.LogInformation($"FoodDish:{foodDishTableEntity.RowKey} has been updated."); return(new OkResult()); }
void SwapDishes() { var swap = servingDish; servingDish = waitingDish; waitingDish = swap; }
public async Task <FoodDish> GetFoodDishByIdAsync(string id) { try { FoodDish foodDish = await this.foodDishTable.LookupAsync(id); return(foodDish); } catch (MobileServiceInvalidOperationException msioe) { Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message); } catch (Exception e) { Debug.WriteLine(@"Sync error: {0}", e.Message); } return(null); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "food")] HttpRequest req, [Table(Constants.TableName)] IAsyncCollector <FoodDishTableEntity> foodDishesTable, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); if (!requestBody.IsValidJson <FoodDish>(out IList <string> errorMessages)) { return(new BadRequestObjectResult(errorMessages)); } FoodDish incommingFoodDish = JsonConvert.DeserializeObject <FoodDish>(requestBody); var foodDishTableEntity = FoodDishTableEntity.Convert(incommingFoodDish); await foodDishesTable.AddAsync(foodDishTableEntity); log.LogInformation($"FoodDish:{foodDishTableEntity.RowKey} has been added."); var baseUri = new Uri(req.GetEncodedUrl()); var newDishUri = new Uri(baseUri, $"food/{foodDishTableEntity.RowKey}"); return(new CreatedResult(newDishUri.ToString(), new { location = newDishUri })); }
public async Task InsertTableFoodDish(FoodDish foodDish) { await this.foodDishTable.InsertAsync(foodDish); }