예제 #1
0
        public static async Task <IActionResult> updateTodo(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "todo/{id}")] HttpRequest req,
            [Table("todos", Connection = "AzureWebJobsStorage")] CloudTable todoTable,
            ILogger log, string id
            )
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var updated     = JsonConvert.DeserializeObject <TodoUpdateModel>(requestBody);


            var findOperation = TableOperation.Retrieve <TodoTableEntity>("TODO", id);
            var result        = await todoTable.ExecuteAsync(findOperation);

            if (result.Result == null)
            {
                return(new NotFoundResult());
            }

            TodoTableEntity result1 = (TodoTableEntity)result.Result;

            result1.IsCompleted     = updated.IsCompleted;
            result1.TaskDescription = updated.TaskDescription;

            var repalceOperation = TableOperation.Replace(result1);
            await todoTable.ExecuteAsync(repalceOperation);

            return(new OkObjectResult(result1.ToTodo()));
        }
예제 #2
0
 public static IActionResult GetTodoById(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "todo/{id}")] HttpRequest req,
     [Table("todos", "TODO", "{id}", Connection = "AzureWebJobsStorage")] TodoTableEntity todos,
     ILogger log, string id
     )
 {
     try
     {
         if (todos == null)
         {
             return(new NotFoundResult());
         }
         else
         {
             return(new OkObjectResult(todos.ToTodo()));
         }
     }
     catch (Exception e)
     {
         return(new NotFoundResult());
     }
 }