public async Task <ActionResult> appointmentConfirmation(int?appointmentID) { if (appointmentID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblAppointment tblAppointment = await db.tblAppointments.FindAsync(appointmentID); tblEmployee tblEmployee = await db.tblEmployees.FindAsync(tblAppointment.employeeID); tblHaircut tblHaircut = await db.tblHaircuts.FindAsync(tblAppointment.haircutID); tblTimeSlot tblTimeSlot = await db.tblTimeSlots.FindAsync(tblAppointment.timeSlotID); ViewData["employee"] = tblEmployee.FirstName + " " + tblEmployee.LastName; ViewData["haircut"] = tblHaircut.HaircutName; ViewData["timeSlot"] = tblTimeSlot.timeSlot; if (TempData["userInfo"] != null) { TempData.Keep("userInfo"); } if (tblAppointment == null) { return(HttpNotFound()); } return(View(tblAppointment)); }
public JsonResult getTimeSlots(string appointmentDate, tblTimeSlot tblTimeSlot) { DateTime setDate = Convert.ToDateTime(appointmentDate); if ((setDate - DateTime.Today).TotalDays > 0) { List <int> tempTimeSlot = db.tblAppointments.Where(x => x.appointmentDate == setDate).Select(q => q.timeSlotID).ToList(); var getTimeSlotIDs = db.tblTimeSlots.Where(q => !tempTimeSlot.Contains(q.timeSlotID)); return(Json(new SelectList(getTimeSlotIDs, "timeSlotID", "timeSlot"), JsonRequestBehavior.AllowGet)); } else { return(Json(false, JsonRequestBehavior.AllowGet)); } }
public ActionResult DownloadAppointmentCard(int?appointmentID) { tblAppointment tblAppointment = db.tblAppointments.Find(appointmentID); tblEmployee tblEmployee = db.tblEmployees.Find(tblAppointment.employeeID); tblHaircut tblHaircut = db.tblHaircuts.Find(tblAppointment.haircutID); tblTimeSlot tblTimeSlot = db.tblTimeSlots.Find(tblAppointment.timeSlotID); ViewData["employee"] = tblEmployee.FirstName + " " + tblEmployee.LastName; ViewData["haircut"] = tblHaircut.HaircutName; ViewData["timeSlot"] = tblTimeSlot.timeSlot; if (TempData["userInfo"] != null) { TempData.Keep("userInfo"); } return(new Rotativa.ViewAsPdf("appointmentConfirmation", tblAppointment) { FileName = "Mobile Hairdresser : Appointment Card.pdf", PageSize = Size.A4, PageOrientation = Orientation.Portrait, PageMargins = { Left = 0, Right = 0 }, CustomSwitches = "--print-media-type --zoom 1.3" }); }
public ActionResult confirmationEmail(int appointmentID) { string body; if (TempData["userInfo"] != null) { TempData.Keep("userInfo"); } tblAppointment tblAppointment = db.tblAppointments.Find(appointmentID); tblHaircut tblHaircut = db.tblHaircuts.Find(tblAppointment.haircutID); tblEmployee tblEmployee = db.tblEmployees.Find(tblAppointment.employeeID); tblTimeSlot tblTimeSlot = db.tblTimeSlots.Find(tblAppointment.timeSlotID); using (var stream = new StreamReader(Server.MapPath("//App_Data//emailTemplates/" + "appointmentConfirmation.html"))) { body = stream.ReadToEnd(); } try { string appointmentDate = tblAppointment.appointmentDate.DayOfWeek.ToString() + " " + tblAppointment.appointmentDate.Day + " " + tblAppointment.appointmentDate.ToString("MMMM") + " " + tblAppointment.appointmentDate.Year; TimeSpan appointmentTime = tblTimeSlot.timeSlot; string haircutName = tblHaircut.HaircutName; string employeeName = tblEmployee.FirstName + " " + tblEmployee.LastName; string customerName = tblAppointment.tblClient.clientName; string customerPhoneNumber = tblAppointment.tblClient.clientMobile; string customerEmail = tblAppointment.tblClient.clientEmail; string clientPassword = TempData["userInfo"].ToString(); int customerHouseNumber = Convert.ToInt32(tblAppointment.tblClient.clientHouseNumber); string customerAddress = tblAppointment.tblClient.clientPostalCode; string emailFrom = ConfigurationManager.AppSettings["EmailFormAddress"]; MailMessage confirmationMessage = new MailMessage(); confirmationMessage.To.Add(customerEmail); confirmationMessage.From = new MailAddress(emailFrom, "Mobile Hairdresser"); confirmationMessage.ReplyToList.Add(new MailAddress(customerEmail)); confirmationMessage.Subject = @"Mobile Hairdresser : Appointment Confirmation"; confirmationMessage.Body = string.Format(body, customerName, customerPhoneNumber, customerEmail, clientPassword , customerHouseNumber, customerAddress, appointmentID, appointmentDate , appointmentTime, employeeName, haircutName); confirmationMessage.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient()) { smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]); smtp.Host = ConfigurationManager.AppSettings["MailServer"]; smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]); smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["MailAuthUser"], ConfigurationManager.AppSettings["MailAuthPass"]); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.SendCompleted += (s, e) => { smtp.Dispose(); }; smtp.Send(confirmationMessage); } } catch (Exception emailError) { TempData["appointmentConfirmationEmail"] = "An error has occured and your email could not be sent!" + emailError; return(RedirectToAction("appointmentConfirmation", "Appointment", new { appointmentID = tblAppointment.appointmentID })); } TempData["appointmentConfirmationEmail"] = "We have sent you an email confirming your appointment."; return(RedirectToAction("appointmentConfirmation", "Appointment", new { appointmentID = tblAppointment.appointmentID })); }