public IActionResult Submit(PatientsFormViewModel viewModel) { if (ModelState.IsValid) { var age = DateTime.Now.Year - viewModel.Birthday.Value.Year; if (DateTime.Now.DayOfYear < viewModel.Birthday.Value.DayOfYear) { age = age - 1; } var patient = new Patient { Name = viewModel.Name, Age = age, Disease = _diseaseLogic.Read(viewModel.Disease.Value) }; if (_patientLogic.Insert(patient)) { return(View(viewModel)); } return(RedirectToAction("Error", "Home", new ErrorViewModel("The patient could not be registered due to an internal error."))); } return(RedirectToAction("Index", "Form", viewModel)); }
public IActionResult Index(int id) { var model = new DiseasesViewModel(); var disease = _diseaseLogic.Read(id); model.Name = disease.Name; model.Descriptions = disease.Descriptions; foreach (var patient in _patientLogic.GetByDisease(id)) { model.Patients.Add(new PatientViewModel() { Name = patient.Name, Age = patient.Age }); } return(View(model)); }