public ActionResult RequestAppointment(AppointmentViewModel appointmentViewModel, FormCollection formCollection) { bool isError = false; var appointmentSlots = new string[11]; AppointementRepository appointmentRepository = new AppointementRepository(); if (formCollection["assignChkBx"] == null) { isError = true; ModelState.AddModelError("", "You need to select the time of appointment"); } else appointmentSlots = formCollection["assignChkBx"].Split(','); var appointmentModel = new AppointmentViewModel(); appointmentModel.Providers = new DrodownItemsViewModel(); appointmentModel.Providers.Items = GetProvidersForAppointment(); appointmentModel.AppointmentDate = appointmentViewModel.AppointmentDate; appointmentModel.ProviderId = appointmentViewModel.ProviderId; appointmentModel.ReasonForVisit = appointmentViewModel.ReasonForVisit; appointmentModel.AppointmentViewModelList = appointmentRepository.GetAppointmentsByPatientID(int.Parse(Session["PatientId"].ToString()), appointmentViewModel.AppointmentDate); if (isError == false) { try { var appointementList = new List<Appointment>(); foreach (string time in appointmentSlots) { appointementList.Add(new Appointment { AppointmentId= 0, AppointmentDate = DateTime.Parse(appointmentViewModel.AppointmentDate), ProviderId = appointmentViewModel.ProviderId, ReasonForVisit = appointmentViewModel.ReasonForVisit, Status = "Booked", Time = time, PatientId = int.Parse(Session["PatientId"].ToString()) }); } appointmentRepository.AddAppointments(appointementList); appointmentModel.AppointmentViewModelList = appointmentRepository.GetAppointmentsByPatientID(int.Parse(Session["PatientId"].ToString()), appointmentViewModel.AppointmentDate); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } return View(appointmentModel); }
public ActionResult RequestAppointment() { if (Session["PatientId"] == null || Session["PatientId"].ToString() == "") { return RedirectToAction("Login", "Account"); } DateTime dt = DateTime.Now.Date; var appointmentModel = new AppointmentViewModel(); appointmentModel.AppointmentDate = dt.ToString("yyyy-MM-dd"); appointmentModel.Providers = new DrodownItemsViewModel(); appointmentModel.Providers.Items = GetProvidersForAppointment(); appointmentModel.AppointmentViewModelList = new AppointementRepository().GetAppointmentsByPatientID(int.Parse(Session["PatientId"].ToString()), appointmentModel.AppointmentDate); return View(appointmentModel); }