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

            string strDtFrom   = Request.Form["dtDaysFrom"];
            string strDtTo     = Request.Form["dtDaysTo"];
            string strTotCrews = Request.Form["ddlCrews"];

            int intDaysToAdd = Convert.ToDateTime(strDtTo).Subtract(Convert.ToDateTime(strDtFrom)).Days;

            try
            {
                svc_schedule_day ssd;
                svc_schedule_day ssd2;

                int count;

                for (count = 0; count < intDaysToAdd; count = count + 1)
                {
                    ssd2 = db.svc_schedule_days.SingleOrDefault(s => s.svc_sched_dt == Convert.ToDateTime(strDtFrom).AddDays(count));
                    if (ssd2 != null)
                    {
                        continue;
                    }
                    ssd = new svc_schedule_day();
                    ssd.svc_sched_dt   = Convert.ToDateTime(strDtFrom).AddDays(count);
                    ssd.tot_crews      = Convert.ToInt32(strTotCrews);
                    ssd.available      = String.Format("{0:ddd}", ssd.svc_sched_dt) == "Sat" || String.Format("{0:ddd}", ssd.svc_sched_dt) == "Sun" ? false : true;
                    ssd.cur_svcs_sched = 0;
                    db.svc_schedule_days.InsertOnSubmit(ssd);
                }

                db.SubmitChanges();

                strRet = "Success";
            }
            catch (Exception ex)
            {
                string msg = ex.Message;

                strRet = msg;
            }
            finally
            {
                db.Dispose();
            }

            return(Content(strRet));
        }
Example #2
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 #3
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();
            }
        }