public static async Task <IActionResult> Update( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest request, [Table("todos")] CloudTable todoTable, ILogger log) { log.LogInformation("Request to update Record"); string requestBody = await new StreamReader(request.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <TodoDto>(requestBody); var rowKeyToUpdate = request.Query[nameof(TableEntity.RowKey)]; var partitionKeyToUpdate = request.Query[nameof(TableEntity.PartitionKey)]; var tableEntity = new TodoTableEntity { RowKey = rowKeyToUpdate, PartitionKey = partitionKeyToUpdate, Title = data.Title, Description = data.Description, IsCompleted = data.IsCompletd, ETag = "*" }; var updateOperation = TableOperation.Replace(tableEntity); var result = await todoTable.ExecuteAsync(updateOperation); return(new OkObjectResult(result)); }
public static async Task <IActionResult> TodoGetOneBinding1( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "TodoGetOneBinding/{partition}/{id}")] HttpRequest req, [Table("todos", "{partition}", "{id}")] TodoTableEntity todo, ILogger log) { return(new OkObjectResult(todo)); }
public static async Task <IActionResult> DeleteEntity( [HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "DeleteRecord/{partitionKey}/{rowKey}")] HttpRequest request, [Table("todos", "{partitionKey}", "{rowKey}")] TodoTableEntity tableEntity, [Table("todos")] CloudTable todoTable, ILogger log) { log.LogInformation("Request to delete the record"); var deleteOperation = TableOperation.Delete(tableEntity); var result = await todoTable.ExecuteAsync(deleteOperation); return(new OkObjectResult(result)); }
public static async Task <IActionResult> Add( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [Table("todos", "Key", "Key", Take = 1)] TodoKey keyGen, [Table("todos")] CloudTable todoTable, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <TodoDto>(requestBody); if (keyGen == null) { keyGen = new TodoKey { Key = 1000, PartitionKey = "Key", RowKey = "Key" }; var addKeyOperation = TableOperation.Insert(keyGen); await todoTable.ExecuteAsync(addKeyOperation); } var rowKey = keyGen.Key; var dataToInsert = new TodoTableEntity { Title = data.Title, Description = data.Description, IsCompleted = data.IsCompletd, PartitionKey = data.Title[0].ToString(), RowKey = keyGen.Key.ToString() }; keyGen.Key += 1; var updateKeyOperation = TableOperation.Replace(keyGen); await todoTable.ExecuteAsync(updateKeyOperation); var addEntryOperation = TableOperation.Insert(dataToInsert); todoTable.CreateIfNotExists(); await todoTable.ExecuteAsync(addEntryOperation); return(new OkObjectResult(keyGen.Key)); }
public static async Task <IActionResult> UpdateUsingBinding( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "UpdateUsingBinding/{partitionKey}/{rowKey}")] HttpRequest request, [Table("todos", "{partitionKey}", "{rowKey}")] TodoTableEntity tableEntity, [Table("todos")] CloudTable todoTable, ILogger log) { log.LogInformation("Request to update Record"); string requestBody = await new StreamReader(request.Body).ReadToEndAsync(); var data = JsonConvert.DeserializeObject <TodoDto>(requestBody); tableEntity.Title = data.Title; tableEntity.Description = data.Description; tableEntity.IsCompleted = data.IsCompletd; var updateOperation = TableOperation.Replace(tableEntity); var result = await todoTable.ExecuteAsync(updateOperation); return(new OkObjectResult(result)); }