Example #1
0
        public ActionResult DeleteService(string id)
        {
            uls_dbDataContext db = new uls_dbDataContext();
            string            strRet;

            try
            {
                svc_appointment svc = db.svc_appointments.Single(s => s.svc_id == Convert.ToInt32(id));

                svc_schedule_day svcd = db.svc_schedule_days.Single(d => d.svc_sched_dt == Convert.ToDateTime(svc.svc_date));

                svcd.cur_svcs_sched = svcd.cur_svcs_sched > 0 ? svcd.cur_svcs_sched - 1 : 0;

                db.svc_appointments.DeleteOnSubmit(svc);
                db.SubmitChanges();
                strRet = "Success";
            }
            catch (Exception ex)
            {
                strRet = "Failure: " + ex.Message;
            }

            return(Content(strRet));
        }
Example #2
0
        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();
            }
        }
Example #3
0
        public ActionResult ReSchedPhoneSave()
        {
            uls_dbDataContext db = new uls_dbDataContext();
            string            strDay;
            string            strDate;
            string            strSpaces = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            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"));
            }
        }