public static MakeAppointmentViewModel GenerateAppointmentViewModelDropdowns(DentalBaseContext context) { var model = new MakeAppointmentViewModel(); var surgeries = context.Surgeries.DistinctBy(x => x.Name); model.Surgeries.AddRange(surgeries); model.Teeth.AddRange(context.Set <Tooth>()); model.Patients.AddRange(context.Set <AppUser>()); foreach (var item in model.Surgeries) { model.SurgeryChoice.Add(new SelectListItem { Text = item.Name, Value = item.SurgeryId.ToString() }); } foreach (var item in model.Teeth) { model.ToothChoice.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); } foreach (var item in model.Patients) { if (item.FirstName != null && item.LastName != null) { var text = $"{item.FirstName} {item.LastName}"; model.PatientChoice.Add(new SelectListItem { Text = text, Value = item.Id.ToString() }); } } return(model); }
public ActionResult Save(MakeAppointmentViewModel model) { var visit = new Visit(); visit.Date = model.Date.Value; visit.Patient = _context.Set <AppUser>().Where(x => x.Id == model.PatientID.ToString()).FirstOrDefault(); for (int i = 0; i < model.SurgeriesIDs.Count; i++) { var surgeryID = model.SurgeriesIDs[i]; var toothID = model.TeethIDs[i]; var name = _context.Set <Surgery>().Where(x => x.SurgeryId == surgeryID).FirstOrDefault().Name; var estimatedTime = _context.Set <Surgery>().Where(x => x.SurgeryId == surgeryID).FirstOrDefault().EstimatedTime; var price = _context.Set <Surgery>().Where(x => x.SurgeryId == surgeryID).FirstOrDefault().Price; var tooth = _context.Set <Tooth>().Where(x => x.Id == toothID).FirstOrDefault(); if (visit.Surgeries == null) { visit.Surgeries = new List <Surgery>(); } visit.Surgeries.Add(new Surgery { Name = name, EstimatedTime = estimatedTime, Price = price, Tooth = tooth }); } _context.Surgeries.AddRange(visit.Surgeries); _context.Visits.Add(visit); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult MakeAppointment() { var doctorsIDsNames = GetNamesOfDoctors(); var details = GetDoctorDetails(doctorsIDsNames.First().Key); var freeTerms = GetFreeTerms(doctorsIDsNames.First().Key); var viewModel = new MakeAppointmentViewModel { DoctorsIDsNames = doctorsIDsNames, DoctorDetails = details, FreeTerms = freeTerms }; return(View(viewModel)); }
private void SendEmailToHospital(MakeAppointmentViewModel model) { try { var bodyTemplate = Utility.ReadFileToString("~/Template/Appointment.html"); bodyTemplate = bodyTemplate.Replace("[@NAME]", model.Name); bodyTemplate = bodyTemplate.Replace("[@EMAIL]", model.Email); bodyTemplate = bodyTemplate.Replace("[@MESSAGE]", model.Message); bodyTemplate = bodyTemplate.Replace("[@PHONE]", model.PhoneNo ?? "Not provided."); bodyTemplate = model.Date == null ? bodyTemplate.Replace("[@DATE]", "Not provided.") : bodyTemplate.Replace("[@DATE]", Convert.ToDateTime(model.Date).ToShortDateString()); EmailHelper.SendAsyncEmail(ProjectSession.Hospital.Email, "Appointment", bodyTemplate, true); } catch (Exception ex) { _logger.Error(ex); } }
public ActionResult MakeAppointment(MakeAppointmentViewModel model) { try { if (!ModelState.IsValid) { return(Json(new { success = false, message = "The data you provided is invalid." }, JsonRequestBehavior.AllowGet)); } var appointment = model.GetAppointmentEntity(); _appointmentService.Insert(appointment); SendEmailToHospital(model); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); //return RedirectToAction(nameof(AppointmentRequested), new { success = true }); } catch (Exception ex) { _logger.Error(ex); return(Json(new { success = false, message = "There was some problem in requesting your appointment." }, JsonRequestBehavior.AllowGet)); //return RedirectToAction(nameof(AppointmentRequested), new { success = false }); } }
public ActionResult Number(MakeAppointmentViewModel model) { return(RedirectToAction("MakeAppointment", "Home", new { numberOfSurgeries = model.NumberOfSurgeries, visitDate = model.Date })); }