예제 #1
0
        public static string BuildRVtoRestaurantHtmlBody(RVConfirmationModel model)
        {
            string pagepath = "~/Content/HTMLPages/ReservationToRestaurant.htm";
            string msgbody  = string.Empty;

            using (StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath(pagepath)))
            {
                msgbody = sr.ReadToEnd();
            }
            msgbody = msgbody.Replace("+bizname+", model.Bizinfo.BizTitle);
            msgbody = msgbody.Replace("+cname+", model.FirstName + " " + model.LastName);
            msgbody = msgbody.Replace("+datetime+", model.RVDate + " " + model.RVTime);
            msgbody = msgbody.Replace("+num+", model.RVNum.ToString());
            msgbody = msgbody.Replace("+cphone+", model.Phone);
            msgbody = msgbody.Replace("+cemail+", model.Email);
            msgbody = msgbody.Replace("+message+", model.Message);
            return(msgbody);
        }
        public ActionResult FindTable(int id, string rvDate, string rvTime, int rvNum) // id=BizInfoId
        {
            BizInfo bi = BizInfoRepository.GetBizInfoById(id);

            ViewBag.biztitle = bi.BizTitle;
            BizRVInfo brv     = bi.GetBizRVInfo;
            int       totalRV = ReservationRepository.GetAllReservationByBizInfoRVDate(id, rvDate).Count;
            bool      seatsOK = (brv.SeatedCapacity - totalRV) > rvNum;

            ViewBag.tableAvailable = (seatsOK && SearchFilter.IsTheDayOpen(bi, DateTime.Parse(rvDate)))? "y" : "n";
            RVConfirmationModel rvc = new RVConfirmationModel();

            rvc.BizInfoId    = id;
            rvc.RVDate       = rvDate;
            rvc.RVTime       = rvTime;
            rvc.RVNum        = rvNum;
            ViewBag.datetime = DateTime.Parse(rvDate).ToLongDateString() + " " + rvTime;
            return(PartialView(rvc));
        }
        public ActionResult Completed(RVConfirmationModel model)
        {
            bool sendSuccess = false;

            if (ModelState.IsValid)
            {
                if (model.Message == "Please note that not all requests can be accommodated.")
                {
                    model.Message = "";
                }
                BizInfo   bi  = BizInfoRepository.GetBizInfoById(model.BizInfoId);
                BizRVInfo brv = bi.GetBizRVInfo;
                model.Bizinfo    = bi;
                ViewBag.biztitle = bi.BizTitle;
                ViewBag.datetime = DateTime.Parse(model.RVDate).ToLongDateString() + " " + model.RVTime;
                Reservation r = ReservationRepository.AddReservation(0, brv.BizRVInfoId, model.FirstName, model.LastName, model.Phone,
                                                                     model.Email, model.RVDate, model.RVTime, model.RVNum, model.Message, DateTime.Now, model.FirstName + model.LastName, DateTime.Now, model.FirstName + model.LastName, true);

                if (r != null)
                {
                    EmailManager  em = new EmailManager();
                    EmailContents ec = new EmailContents("FoodReady.Net", model.Email, Globals.Settings.ContactForm.MailFrom,
                                                         "Restaurant Reservation", EmailManager.BuildRVtoCustomerHtmlBody(model));

                    em.FaxBody = EmailManager.BuildRVtoRestaurantHtmlBody(model);
                    em.SendFax(bi.Fax);
                    em.Send(ec); // send to customer

                    if (em.IsSent == false)
                    {
                        sendSuccess = false;
                        TempData["sentCustomerMsg"] = "Your message has not been sent out for some reasons.";
                    }
                    else
                    {
                        sendSuccess = true;
                        TempData["sentCustomerMsg"] = "Your message has  been sent out successfully.";
                    }
                    ec.FromName         = "FoodReady.Net";
                    ec.To               = bi.ContactInfo.Email; // to restaurant;
                    ec.FromEmailAddress = Globals.Settings.ContactForm.MailFrom;
                    ec.Subject          = "Restaurant Reservation";
                    ec.Body             = EmailManager.BuildRVtoRestaurantHtmlBody(model);
                    em.Send(ec);
                    if (em.IsSent == false)
                    {
                        sendSuccess = false;
                        TempData["sentRestaurantMsg"] = "Your message has not been sent out for some reasons.";
                    }
                    else
                    {
                        sendSuccess = true;
                        TempData["sentRestaurantMsg"] = "Your message has  been sent out successfully.";
                    }
                }
                else
                {
                    sendSuccess            = false;
                    TempData["addToDBMsg"] = "Adding reservation to database failed for some reasons.";
                }
            }
            ViewBag.SendingSuccess = sendSuccess;
            return(View(model));
        }