//reservation done page public ActionResult thankYouForBooking(thankForBookingData data) { return(View(data)); }
//add reservation record to database public ActionResult reservation(string name, string phone, string appointementDate, string interval, Guid docID) { try { //convert from string to date format var appointDate = DateTime.Parse(appointementDate); //booked doctor var targetDoctor = db.doctors.Find(docID); if (!isValidReservingData(phone, name, targetDoctor.bookingType, interval)) { //reservation data is not valid TempData["error"] = Resource1.invalidBookingData; //show error data on page //redirect to reservation page return(RedirectToAction("doctorReservingsPage", new { id = docID })); } //user is not authenticated if (!isUserAuthenticated()) { return(RedirectToAction("doctorReservingsPage", new { id = docID })); } patient currentPatient = getCurrentpatient(); //number of resrevation that patient already reserved before for the same doctor int numberOfreservingAtTheSameDoctorAtTheSameDate = currentPatient.reservings.Count(r => r.doctorID == docID && r.reservingDate == appointDate.Date); //onlay available for patinet to reserve 2 times at same doctor at same date if (numberOfreservingAtTheSameDoctorAtTheSameDate > 2) { TempData["error"] = Resource1.maxBookingNumber; return(RedirectToAction("doctorReservingsPage", new { id = docID })); } //return if this patient has already booked at this doctor ,with the same date ,with the same patient name bool isHasAnybookingForThatPatient = currentPatient.reservings.Any(r => r.doctorID == docID && r.reservingDate == appointDate.Date && r.patientName == name); //user can not book a reservation at the same doctor with the same time with the same patient name if (isHasAnybookingForThatPatient) { TempData["error"] = Resource1.haveBookingAlready; return(RedirectToAction("doctorReservingsPage", new { id = docID })); } //add new reservation record at database reserving newReservation = new reserving(); newReservation.doctorID = docID; newReservation.patientName = name; newReservation.patientID = currentPatient.id; newReservation.reservingDate = appointDate.Date; newReservation.visitType = true; newReservation.phone = phone; newReservation.interval = interval; newReservation.id = Guid.NewGuid(); currentPatient.reservings.Add(newReservation); db.SaveChanges(); thankForBookingData bookingDoneData = new thankForBookingData(); bookingDoneData.name = name; bookingDoneData.clinicAddress = (currentLanguage == "en") ? targetDoctor.doctorInfo.clinicAddressEng : targetDoctor.doctorInfo.clinicAddressAr; bookingDoneData.appointementDate = appointDate; bookingDoneData.interval = interval; bookingDoneData.bookingType = targetDoctor.bookingType; //go to thank you page(booking is done) return(RedirectToAction("thankYouForBooking", bookingDoneData)); } catch (Exception) { TempData["error"] = Resource1.serverProblem; return(RedirectToAction("doctorReservingsPage")); } }