public static async Task <IActionResult> SaveUserHealthRadarResult([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("Save Health Radar Result: " + req.Body); string requestBody = String.Empty; using (StreamReader streamReader = new StreamReader(req.Body)) { requestBody = await streamReader.ReadToEndAsync(); } log.LogInformation(requestBody); dynamic data = JsonConvert.DeserializeObject(requestBody); var result = new HealthRadarResult(); string tempId = data.id; if (!string.IsNullOrEmpty(tempId)) { result.Id = new Guid(tempId); } result.Area = data.area; result.Role = data.role; result.Answers = data.answers.ToObject <List <int> >(); result.Posted = DateTime.Now; if (result.Id == Guid.Empty) { log.LogInformation("Create new record"); await CosmosHelper.CreateResultInCosmosDb(result); } else { try { log.LogInformation("Update record: " + result.Id); await CosmosHelper.UpdateResultInCosmosDb(result); }catch (Exception e) { log.LogInformation("Create new record"); await CosmosHelper.CreateResultInCosmosDb(result); } } return(new OkObjectResult(result.Id)); }