public async Task <IActionResult> CreateAsync(string patientId, PrimaryTumorState primaryTumor, DistantMetastasisState distantMetastasis, RegionalLymphNodesState regionalLymphNodes) { Patient patient = await _patientService.GetByIdAsync(patientId); Doctor doctor = await _doctorService.GetByUserIdAsync(_userManager.GetUserId(HttpContext.User)); if (patient.ActiveDiagnoseId != 0) { var oldDiagnose = await _diagnoseService.GetByIdAsync(patient.ActiveDiagnoseId); if (oldDiagnose != null && oldDiagnose.Treatment != null) { oldDiagnose.Treatment.End = DateTime.Now; await _diagnoseService.UpdateAsync(); } } Diagnose diagnose = new Diagnose() { Patient = patient, Doctor = doctor, DistantMetastasis = distantMetastasis, PrimaryTumor = primaryTumor, RegionalLymphNodes = regionalLymphNodes, Stage = _diagnoseService.DetermineStage(distantMetastasis, primaryTumor, regionalLymphNodes) }; HealthCheck healthCheck = new HealthCheck() { Diagnose = diagnose, Timestamp = DateTime.Now }; var healthCheckId = await _healthCheckService.CreateAsync(healthCheck); healthCheck = await _healthCheckService.GetByIdAsync(healthCheckId); patient.ActiveDiagnoseId = healthCheck.Diagnose.Id; await _patientService.UpdateAsync(); return(RedirectToAction("", "DoctorDashboard")); }