public static AppointmentViewModel CreateTestAppointmentViewModel()
        {
            AppointmentViewModel apptVm = new AppointmentViewModel();

            apptVm.Date = "22/04/2013";
            apptVm.SelectedDoctorId = 1;
            apptVm.Reason = "sample reason";
            apptVm.SelectedHourID = "1";
            apptVm.SelectedMinuteId = "1";
                return apptVm;
        }
        public ActionResult BookAppointment(string btnSubmit, AppointmentViewModel apVM)
        {
            if (btnSubmit == "Book Now")
            {
                if ( apVM.Date == null) {
                    ModelState.AddModelError("", "Please ensure that you have entered the date");
                    return View(apVM);

                }

                return RedirectToAction("BookAppointmentComplete", apVM );
            }

            if (btnSubmit == "Find Availability")
               {
                    if (ModelState.IsValid)
                 {
                    //check doctor's availability
                    DateTime fromDateTime = Ultilities.GetDateTimeFromString(apVM.fromDate, apVM.SelectedFromTime.ToString());
                    DateTime toDateTime = Ultilities.GetDateTimeFromString(apVM.toDate);

                    IQueryable<Appointment> conflictedAppts = appointmentRepository.GetConflictedDates(apVM.SelectedDoctorId, fromDateTime, toDateTime);

                    if (conflictedAppts.Count() > 0)
                    {
                        apVM.NotAvailableTimes = new List<NotAvailableTime>();
                        foreach (Appointment ap in conflictedAppts)
                        {
                            apVM.NotAvailableTimes.Add(new NotAvailableTime(ap.Appointmentid, ap.FromTime, ap.ToTime));
                        }

                    }
                    ViewBag.FindAvailabilityClicked = true;
                    return View(apVM);
                }

                else
                {
                    ModelState.AddModelError("", "Please ensure that you have entered the dates");

                }
               }
            return View(new AppointmentViewModel());
        }
        public ViewResult BookAppointmentComplete(AppointmentViewModel apVM)
        {
            int patientID = appointmentRepository.GetPatientByUserName(User.Identity.Name);

            Appointment appt = new Appointment();
            appt.Patientid = patientID;
            appt.DoctorID = apVM.SelectedDoctorId;
            appt.Reason = apVM.Reason;

            DateTime fromDateTime = Ultilities.GetDateTimeFromString(apVM.Date);
            fromDateTime.AddHours(Convert.ToInt32(apVM.SelectedHourID));
            fromDateTime.AddMinutes(Convert.ToInt32(apVM.SelectedMinuteId));
            appt.FromTime = fromDateTime;
            appt.ToTime = fromDateTime.AddMinutes(45);

            appointmentRepository.Add(appt);

            //send email alert to Doctor
            apVM.Email.SendEmail();

            apVM.FeedBack = "Appointment booked successfully";

            return View(apVM);
        }