public ActionResult Create([Bind(Include = "Id,Name,LastName,DNI,Enrollment,Phone,Email")] DoctorModel doctor) { try { if (doctor.Name == null || doctor.Name == string.Empty) { ModelState.AddModelError("Name", "Debe ingresar un nombre"); } if (doctor.LastName == null || doctor.LastName == string.Empty) { ModelState.AddModelError("LastName", "Debe ingresar un apellido"); } if (doctor.DNI == 0) { ModelState.AddModelError("DNI", "Debe ingresar un DNI"); } if (doctor.Enrollment == null || doctor.Enrollment == string.Empty) { ModelState.AddModelError("Enrollment", "Debe ingresar el enrollment"); } if (doctor.Phone == null || doctor.Phone == string.Empty) { ModelState.AddModelError("Phone", "Debe ingresar un teléfono"); } if (doctor.Email == null || doctor.Email == string.Empty) { ModelState.AddModelError("Email", "Debe ingresar un email"); } IEnumerable <Doctor> doctors = doctorBusiness.GetByFilters(DoctorModel.FromModel(doctor)); if (doctors.ToList().Count > 0) { ModelState.AddModelError("Model", "Ya existe un doctor con DNI: " + doctor.DNI + " y Enrollment: " + doctor.Enrollment); } if (ModelState.IsValid) { doctorBusiness.Insert(DoctorModel.FromModel(doctor)); return(RedirectToAction("Index")); } return(View(doctor)); } catch (Exception ex) { Log.Error(ex.Message, ex); return(View()); } }
public ActionResult Create([Bind(Include = "Id,Name,LastName,Email,PhoneNumber,Address,EntryDate")] Doctor doctor) { if (ModelState.IsValid) { var docBll = new DoctorBLL(); docBll.Insert(doctor); return(RedirectToAction("Index")); } return(View(doctor)); }