public ActionResult EditAppointment(int id, string cancelRedirectUrl) { ViewBag.MenuItem = CurrentMenuItem; TempData["cancelRedirectUrl"] = cancelRedirectUrl; var appointment = unitOfWork.Repository <Appointment>() .Queryable() .Include(p => p.Patient) .SingleOrDefault(e => e.Id == id); if (appointment == null) { ViewBag.Entity = "Appointment"; return(View("NotFound")); } string patientName = appointment.Patient.FullName; var appointmentEditModel = new AppointmentEditModel { AppointmentId = appointment.Id, PatientFullName = appointment.Patient.FullName, AppointmentDate = appointment.AppointmentDate, Reason = appointment.Reason, Cancelled = appointment.Cancelled ? "Yes" : "No", CancellationReason = appointment.CancellationReason, Created = appointment.GetCreatedStamp(), Updated = appointment.GetLastUpdatedStamp() }; // Prepare drop downs ViewBag.Cancellations = new[] { new SelectListItem { Value = "No", Text = "No", Selected = true }, new SelectListItem { Value = "Yes", Text = "Yes" } }; ViewBag.CancelRedirectUrl = cancelRedirectUrl; ViewBag.PatientName = patientName; return(View(appointmentEditModel)); }
public ActionResult EditAppointment(AppointmentEditModel model) { ViewBag.MenuItem = CurrentMenuItem; var cancelRedirectUrl = (TempData["cancelRedirectUrl"] ?? string.Empty).ToString(); ViewBag.cancelRedirectUrl = cancelRedirectUrl; var appointmentRepository = unitOfWork.Repository <Appointment>(); var appointment = appointmentRepository.Queryable().Include("Patient").Single(a => a.Id == model.AppointmentId); if (appointment == null) { ViewBag.Entity = "Appointment"; return(View("NotFound")); } // If user has changed appointment date - then complete duplication check if (appointment.AppointmentDate != model.AppointmentDate) { var tempAppointment = unitOfWork.Repository <Appointment>() .Queryable() .Include(p => p.Patient) .SingleOrDefault(a => a.Patient.Id == appointment.Patient.Id && a.AppointmentDate == model.AppointmentDate); if (tempAppointment != null) { ModelState.AddModelError("AppointmentDate", "Patient already has an appointment for this date"); } } if (model.AppointmentDate > DateTime.Today.AddYears(2)) { ModelState.AddModelError("AppointmentDate", "Appointment Date should be within 2 years"); } if (model.AppointmentDate < DateTime.Today) { ModelState.AddModelError("AppointmentDate", "Appointment Date should be after current date"); } if (ModelState.IsValid) { appointment.AppointmentDate = model.AppointmentDate; appointment.Reason = model.Reason; appointment.Cancelled = model.Cancelled == "Yes" ? true : false; appointment.CancellationReason = model.CancellationReason; appointmentRepository.Update(appointment); unitOfWork.Complete(); HttpCookie cookie = new HttpCookie("PopUpMessage"); cookie.Value = "Appointment record updated successfully"; Response.Cookies.Add(cookie); return(Redirect("/Patient/PatientView.aspx?pid=" + appointment.Patient.Id.ToString())); } string patientName = appointment.Patient.FullName; ViewBag.Cancellations = new[] { new SelectListItem { Value = "No", Text = "No", Selected = true }, new SelectListItem { Value = "Yes", Text = "Yes" } }; ViewBag.PatientName = patientName; return(View(model)); }
public ProductCalendarModel() { AppointmentEditModel = new AppointmentEditModel(); }