public ActionResult SelectSvcDate() { string strPastDate = ""; string strDay = ""; string strDate = ""; string strSpaces = " "; List <string> availDts = new List <string>(); uls_dbDataContext ulsdb_dc = new uls_dbDataContext(); if (Session["PastServiceDate"] != null) { strPastDate = Convert.ToString(Session["PastServiceDate"]); DateTime pastDt = Convert.ToDateTime(strPastDate); strDay = String.Format("{0:ddd}", pastDt).ToUpper(); } if (strPastDate.Length > 0) { availDts.Add(strDay + Server.HtmlDecode(strSpaces) + strPastDate); } else { IEnumerable <DateTime> availDates = ulsdb_dc.GetAvailSvcDates(); foreach (DateTime dt in availDates) { strDay = String.Format("{0:ddd}", dt).ToUpper(); strDate = String.Format("{0:MM/dd/yyyy}", dt); availDts.Add(strDay + Server.HtmlDecode(strSpaces) + strDate); } } ViewData["AvailableDates"] = new SelectList(availDts); ViewData["SaveResultMsg"] = Session["SaveResultMsg"]; svc_contact sc = ulsdb_dc.svc_contacts.Single(s => s.contact_id == 1); ViewData["ContactName"] = sc.contact_name; ViewData["ContactPhone"] = sc.contact_number; ViewData["ContactEmail"] = sc.contact_email; ViewData["NotifyEmail1"] = sc.notify1_email; ViewData["NotifyEmail2"] = sc.notify2_email; ViewData["NotifyEmail3"] = sc.notify3_email; return(View()); }
public ActionResult SvcAdmin() { uls_dbDataContext db = new uls_dbDataContext(); svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1); ViewData["ContactName"] = sc.contact_name; ViewData["ContactPhone"] = sc.contact_number; ViewData["ContactEmail"] = sc.contact_email; ViewData["NotifyEmail1"] = sc.notify1_email; ViewData["NotifyEmail2"] = sc.notify2_email; ViewData["NotifyEmail3"] = sc.notify3_email; return(View()); }
public ActionResult SaveContact() { string strRet; uls_dbDataContext db = new uls_dbDataContext(); string strName = Request.Form["txtName"]; string strPhone = Request.Form["txtPhone"]; string strEmail = Request.Form["txtEmail"]; string strEmailNotify1 = Request.Form["txtEmailNotif1"]; string strEmailNotify2 = Request.Form["txtEmailNotif2"]; string strEmailNotify3 = Request.Form["txtEmailNotif3"]; try { svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1); sc.contact_name = strName; sc.contact_number = strPhone; sc.contact_email = strEmail; sc.notify1_email = strEmailNotify1; sc.notify2_email = strEmailNotify2; sc.notify3_email = strEmailNotify3; db.SubmitChanges(); strRet = "Success"; } catch (Exception ex) { string msg = ex.Message; strRet = msg; } finally { db.Dispose(); } return(Content(strRet)); }
// // GET: /Service/ public ActionResult Index() { uls_dbDataContext db = new uls_dbDataContext(); svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1); ViewData["ContactName"] = sc.contact_name; ViewData["ContactPhone"] = sc.contact_number; ViewData["ContactEmail"] = sc.contact_email; Session["SaveResultMsg"] = ""; Session["SaveResultName"] = ""; if (Session["emailVal"] == null) { ViewData["emailVal"] = "Yes"; } else { ViewData["emailVal"] = Session["emailVal"]; } return(View()); }
private void SendEmailNofication(string strSvcDate) { string strSMTPServer = ConfigurationManager.AppSettings["SMTPServer"]; string strSMTPUID = ConfigurationManager.AppSettings["SMTPUserID"]; string strSMTPPWD = ConfigurationManager.AppSettings["SMTPUserPWD"]; string strSMTPFrom = ConfigurationManager.AppSettings["SMTPUserFromAddress"]; SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); MailAddress fromAddress = new MailAddress(strSMTPFrom, "ULS Service Notification"); uls_dbDataContext db = new uls_dbDataContext(); svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1); string strEmail1 = sc.notify1_email; string strEmail2 = sc.notify2_email; string strEmail3 = sc.notify3_email; // You can specify the host name or ipaddress of your server smtpClient.Host = strSMTPServer; //you can also specify mail server IP address here //Default port will be 25 smtpClient.Port = 25; NetworkCredential info = new NetworkCredential(strSMTPUID, strSMTPPWD); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = info; //From address will be given as a MailAddress Object message.From = fromAddress; // To address collection of MailAddress if (strEmail1.Length > 0) { message.To.Add(strEmail1); } if (strEmail2.Length > 0) { message.To.Add(strEmail2); } if (strEmail3.Length > 0) { message.To.Add(strEmail3); } message.Subject = "A new service appointment has been scheduled"; message.IsBodyHtml = false; // Message body content string ss_body = "A service appointment has been scheduled for:\r\n\r\n" + Convert.ToString(Session["LName"]) + "\r\n" + Convert.ToString(Session["txtAddress"]) + "\r\n" + Convert.ToString(Session["txtCity"]) + ", " + Convert.ToString(Session["ddlState"]) + ", " + Convert.ToString(Session["txtZip"]) + "\r\n" + "Phone: " + Convert.ToString(Session["txtHomePhone"]) + "\r\n\r\n" + "on " + strSvcDate; message.Body = ss_body; // Send SMTP mail smtpClient.Send(message); }
public ActionResult SaveDate() { string strRet; uls_dbDataContext db = new uls_dbDataContext(); string strDateForm = Request.Form["AvailableDates"]; string strDate = strDateForm.Substring(4).Trim(); string strDateFormatted = strDateForm.Substring(0, 3) + ", " + strDate; string resched = Convert.ToString(Session["ReSchedule"]); try { svc_schedule_day ssa = db.svc_schedule_days.SingleOrDefault(s => s.svc_sched_dt == Convert.ToDateTime(strDate)); if (ssa.cur_svcs_sched >= ssa.tot_crews) { Session["SaveResultName"] = "Sorry " + Session["FName"] + " " + Session["LName"] + "!"; throw new Exception(strDateFormatted + " is no longer available. Please select another date."); } svc_appointment sa2 = db.svc_appointments.SingleOrDefault(a => a.home_phone == Convert.ToString(Session["txtHomePhone"]) && a.svc_date > DateTime.Now); if (sa2 != null && resched == "No") { svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1); string strName = sc.contact_name; string strPhone = sc.contact_number; string strEmail = sc.contact_email; Session["SaveResultName"] = "Sorry " + Session["FName"] + " " + Session["LName"] + "!"; throw new Exception("You were already scheduled for service. Your service day is currently set for " + String.Format("{0:MM/dd/yyyy}", sa2.svc_date) + ". + If you need to reschedule please call or email " + strName + " (" + strEmail + ")" + " at " + strPhone + " or return to the Save Contact Page and click the Reschedule link."); } if (resched == "Yes") { svc_schedule_day ssa2 = db.svc_schedule_days.SingleOrDefault(s => s.svc_sched_dt == sa2.svc_date); ssa2.cur_svcs_sched = ssa2.cur_svcs_sched - 1; } if (resched == "Yes") { Session["SaveResultName"] = "Sorry " + Session["FName"] + " " + Session["LName"] + "!"; throw new Exception("To reschedule an appointment you must supply ahome telephone number when entering contact info."); } svc_appointment sa = new svc_appointment(); IEnumerable <int> crewNums = db.GetCrewNums(Convert.ToDateTime(strDate)); bool bHit = false; int ourCrew = 0; for (int i = 1; i <= ssa.tot_crews; i++) { foreach (int crew in crewNums) { if (i == crew) { bHit = true; } } if (bHit == false) { ourCrew = i; break; } bHit = false; } sa.city = Convert.ToString(Session["txtCity"]); sa.crew = ourCrew; sa.email = Convert.ToString(Session["txtEmail"]); sa.first_name = Convert.ToString(Session["FName"]); sa.last_name = Convert.ToString(Session["LName"]); sa.home_phone = Convert.ToString(Session["txtHomePhone"]); sa.other_phone = Convert.ToString(Session["txtOtherPhone"]); sa.state = Convert.ToString(Session["ddlState"]); sa.street_address = Convert.ToString(Session["txtAddress"]); sa.svc_date = Convert.ToDateTime(strDate); sa.zip = Convert.ToString(Session["txtZip"]); sa.comments = Convert.ToString(Session["txtNotes"]); int intForemanID = db.GetForemanID(ourCrew); sa.foreman_id = intForemanID; db.svc_appointments.InsertOnSubmit(sa); ssa.cur_svcs_sched = crewNums.Count() + 1; if (resched == "Yes") { db.svc_appointments.DeleteOnSubmit(sa2); sa.reschedule = true; } else { sa.reschedule = false; } db.SubmitChanges(); strRet = "Thanks " + Session["FName"] + " " + Session["LName"] + "!"; Session["SaveResultName"] = strRet; Session["SaveResultMsg"] = "Your service renewal on " + strDateFormatted + " has been successfully scheduled. You will receive an email reminder the day before your service date."; Session["ShowReturnLink"] = "No"; SendEmailNofication(strDate); return(RedirectToAction("SvcDateResult")); } catch (Exception ex) { string msg = ex.Message; Session["SaveResultMsg"] = msg; if (msg.Contains("available")) { return(RedirectToAction("SelectSvcDate")); } else { Session["ShowReturnLink"] = "Yes"; return(RedirectToAction("SvcDateResult")); } } finally { db.Dispose(); } }
public ActionResult ReSchedPhoneSave() { uls_dbDataContext db = new uls_dbDataContext(); string strDay; string strDate; string strSpaces = " "; List <string> availDts = new List <string>(); string strHomePhone = System.Text.RegularExpressions.Regex.Replace(Request.Form["txtHomePhone"], "\\D", ""); try { svc_appointment sa = db.svc_appointments.SingleOrDefault(a => a.home_phone == strHomePhone && a.svc_date > DateTime.Now); if (sa == null) { svc_contact sc = db.svc_contacts.Single(s => s.contact_id == 1); string strName = sc.contact_name; string strPhone = sc.contact_number; string strEmail = sc.contact_email; throw new Exception("The phone number supplied is not on record as having a scheduled service. If you feel this message " + "is in error please call or email " + strName + " (" + strEmail + ")" + " at " + strPhone + "."); } Session["txtHomePhone"] = strHomePhone; Session["txtCity"] = sa.city; Session["txtEmail"] = sa.email; Session["FName"] = sa.first_name; Session["LName"] = sa.last_name; Session["txtHomePhone"] = sa.home_phone; Session["txtOtherPhone"] = sa.other_phone; Session["ddlState"] = sa.state; Session["txtAddress"] = sa.street_address; Session["txtZip"] = sa.zip; Session["txtNotes"] = sa.comments; IEnumerable <DateTime> availDates = db.GetAvailSvcDates(); foreach (DateTime dt in availDates) { if (dt > DateTime.Now.AddDays(3)) { strDay = String.Format("{0:ddd}", dt).ToUpper(); strDate = String.Format("{0:MM/dd/yyyy}", dt); availDts.Add(strDay + Server.HtmlDecode(strSpaces) + strDate); } } Session["ReSchedule"] = "Yes"; ViewData["AvailableDates"] = new SelectList(availDts); return(RedirectToAction("SelectSvcDate")); } catch (Exception ex) { string msg = ex.Message; Session["SaveResultMsg"] = msg; Session["SaveResultName"] = "Sorry!"; Session["ShowReturnLink"] = "Yes"; return(RedirectToAction("SvcDateResult")); } }