public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetTaskView/{id}")] HttpRequest req, string id, ILogger log) { //CosmosNote - we must retieve the document through code. This is fairly simple, but not as elegant as the function binding in V2. //Use dynamic so we don't need to have a model object. dynamic task = await _cosmosHelper.ReadItemAsync("Tasks", "TaskViews", id, log); //The binding does the lookup for us, minimizing the code. if (task == null) { return(new NotFoundResult()); } return(new JsonResult(task)); }
private async System.Threading.Tasks.Task <dynamic> getTaskView(dynamic id, ILogger log) { dynamic taskView = null; //Use the CosmosHelper to get the task view. dynamic document = await _cosmosHelper.ReadItemAsync("Tasks", "TaskViews", id, log); if (document != null) { taskView = JsonConvert.DeserializeObject <ExpandoObject>(document.ToString(), new ExpandoObjectConverter()); } else { log.LogInformation($"User {id} does not have a TaskItemView. A new document will be created."); taskView = new ExpandoObject(); taskView.id = id; taskView.mytasks = new List <ExpandoObject>(); taskView.approvaltasks = new List <ExpandoObject>(); } return(taskView); }