public ActionResult Edit([Bind(Include = "Id,Date,Hour,DoctorId,PatientId,RoomId")] AppointmentModel appointment) { try { if (appointment.Date == null) { ModelState.AddModelError("Date", "Debe ingresar una fecha"); } if (appointment.Hour == 0) { ModelState.AddModelError("Hour", "Debe ingresar una hora"); } IEnumerable <Appointment> appointments = appointmentBusiness.GetByFilters(AppointmentModel.FromModel(appointment)); if (appointments.ToList().Count > 0) { var ap = appointments.FirstOrDefault(); if (ap.DoctorId == appointment.DoctorId) { ModelState.AddModelError("Model", "El doctor ya tiene un turno asignado para el día y hora seleccionados"); } else { ModelState.AddModelError("Model", "El paciente ya tiene un turno asignado en el día y horario seleccionados"); } } if (ModelState.IsValid) { appointmentBusiness.Update(AppointmentModel.FromModel(appointment)); return(RedirectToAction("Index")); } ViewBag.DoctorId = new SelectList(doctorBusiness.List(), "Id", "Name"); ViewBag.PatientId = new SelectList(patientBusiness.List(), "Id", "Name"); ViewBag.RoomId = new SelectList(roomBusiness.List(), "Id", "Name"); return(View(appointment)); } catch (Exception ex) { Log.Error(ex.Message, ex); return(View()); } }
/// <summary> /// Save an appointment. /// </summary> protected override void Handle() { this.Status = LoadingStatus.Loading; base.Handle(); var appointmentModel = AppointmentModel.FromModel(this.Model); string validationErrorMessage; var isValid = this.ValidateAppointment(appointmentModel, out validationErrorMessage); if (!isValid) { this.Status = LoadingStatus.Canceled; this.ShowValidationErrorToUser(validationErrorMessage); } else { this.SaveChanges(appointmentModel); this.CloseDialog(); } }