예제 #1
0
 // GET: Patient
 public ActionResult Index()
 {
     try
     {
         var patients = patientBusiness.List();
         return(View(PatientModel.ToModelList(patients)));
     }
     catch (Exception ex)
     {
         Log.Error(ex.Message, ex);
         ModelState.AddModelError("Model", "Ha ocurrido un error. Por favor, contacte al administrador");
         return(View());
     }
 }
예제 #2
0
        public ActionResult Edit([Bind(Include = "Id,ClientId,Name,Gender,Age")] PatientModel patient)
        {
            try
            {
                if (patient.Name == null || patient.Name == string.Empty)
                {
                    ModelState.AddModelError("Name", "Debe ingresar un nombre");
                }

                if (patient.ClientId == 0)
                {
                    ModelState.AddModelError("ClientId", "Debe seleccionar un cliente");
                }

                if (patient.Age == 0)
                {
                    ModelState.AddModelError("Age", "Debe ingresar una edad");
                }

                IEnumerable <Patient> patients = patientBusiness.GetByFilters(PatientModel.FromModel(patient));

                if (patients.ToList().Count > 0)
                {
                    ModelState.AddModelError("Model", "Ya existe un paciente con nombre: " +
                                             patient.Name + " y dueño: " + patient.ClientId);
                }

                if (ModelState.IsValid)
                {
                    patientBusiness.Update(PatientModel.FromModel(patient));

                    return(RedirectToAction("Index"));
                }

                var allPatients = patientBusiness.List();
                ViewBag.ClientId = new SelectList(PatientModel.ToModelList(allPatients), "Id", "Name", patient.ClientId);
                return(View(patient));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                return(View());
            }
        }