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()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "food/{id}")] HttpRequest req, [Table(Constants.TableName, Constants.PartitionKey, "{id}")] FoodDishTableEntity foodDishTableEntity) { if (foodDishTableEntity == null) { return(new NotFoundResult()); } return(new OkObjectResult(foodDishTableEntity)); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "food/{id}")] HttpRequest req, [Table(Constants.TableName)] CloudTable foodDishTable, [Table(Constants.TableName, Constants.PartitionKey, "{id}")] FoodDishTableEntity foodDishTableEntity, ILogger log) { if (foodDishTableEntity == null) { return(new NotFoundResult()); } var deleteOperation = TableOperation.Delete(foodDishTableEntity); await foodDishTable.ExecuteAsync(deleteOperation); log.LogInformation($"FoodDish:{foodDishTableEntity.RowKey} has been deleted."); return(new NoContentResult()); }
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 })); }