public IActionResult EditPatient(PatientRecordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var patient = mapper.Map <PatientViewModel, Patient>(model.Patient);

                try
                {
                    repository.UpdatePatient(patient);
                }
                catch (Exception ex)
                {
                    logger.Log(LogLevel.Error, $"Failed to update patient: {ex}");
                }
                try
                {
                    repository.SaveAll();
                }
                catch (Exception ex)
                {
                    logger.Log(LogLevel.Error, $"Failed to save updated patient to db: {ex}");
                }

                var updatedPatient = repository.GetPatientById(patient.Id);
            }
            else
            {
                TempData["FormError"] = "Input data not valid";
            }

            return(RedirectToAction("Record"));
        }
예제 #2
0
        public IActionResult EditPatient(AdminViewModel model, int doctorId)
        {
            if (ModelState.IsValid)
            {
                var doctor  = repository.GetDoctorById(doctorId);
                var patient = mapper.Map <PatientViewModel, Patient>(model.Patient);
                if (doctor != null)
                {
                    patient.Doctor = doctor;
                }

                try
                {
                    repository.UpdatePatient(patient);
                }
                catch (Exception ex)
                {
                    logger.Log(LogLevel.Error, $"Failed to update patient: {ex}");
                }
                try
                {
                    repository.SaveAll();
                }
                catch (Exception ex)
                {
                    logger.Log(LogLevel.Error, $"Failed to save updated patient to db: {ex}");
                }

                var updatedPatient = repository.GetPatientById(patient.Id);

                if (updatedPatient != null)
                {
                    return(RedirectToAction("PatientInfo", new { id = updatedPatient.Id }));
                }
            }
            else
            {
                TempData["FormError"] = "Edit form data not filled correctly.";
            }

            return(RedirectToAction("PatientInfo", new { id = model.Patient.Id }));
        }