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 Main(PatientViewModel model, string submit)
        {
            Patient patient = null;

            switch (submit)
            {
            case "Find Patient":
                patient = SortPatientByName(model);
                break;

            case "Select Patient":
                patient = repository.GetPatientById(model.Id);
                break;
            }

            if (patient != null)
            {
                //AdminViewModel aModel = FillAdminModel();
                //aModel.Patient = mapper.Map<Patient, PatientViewModel>(patient);
                //return View("PatientInfo", aModel);
                return(RedirectToAction("PatientInfo", new { id = patient.Id }));
            }

            TempData["FormError"] = "There was an issue getting the patient data";
            return(RedirectToAction("Main"));
        }