public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "JobApplications/JobApplicationAdd")] HttpRequest req, ILogger log) { Core.Entities.JobApplication jobApplicationFromDb = null; try { var jobApplication = JsonConvert.DeserializeObject <Core.Entities.JobApplication>(await new StreamReader(req.Body).ReadToEndAsync()); if (jobApplication.Company != null) { jobApplication.Company.Id = Guid.NewGuid().ToString(); } if (jobApplication.ApplicantTasks.Any()) { foreach (var applicantTask in jobApplication.ApplicantTasks) { applicantTask.ApplicantId = jobApplication.ApplicantId; applicantTask.Id = Guid.NewGuid().ToString(); } } if (jobApplication.Recruiters.Any()) { foreach (var recruiter in jobApplication.Recruiters) { recruiter.Id = Guid.NewGuid().ToString(); } } if (jobApplication.FirstMeeting != null) { jobApplication.FirstMeeting.ApplicantId = jobApplication.ApplicantId; jobApplication.FirstMeeting.Id = Guid.NewGuid().ToString(); } jobApplication.CreatedOnDate = DateTime.UtcNow; var jobApplicationId = await _jobApplicationRepository.AddItemAsync(jobApplication); jobApplicationFromDb = await _jobApplicationRepository.GetItemAsync(new Guid(jobApplicationId)); } catch (Exception ex) { // TODO send 400 errors if it's the case, otherwise send 500. return(new StatusCodeResult(500)); // TO DO (add logger) throw ex; } return(new OkObjectResult(jobApplicationFromDb)); }