public ActionResult DeleteConfirmed(long id)
        {
            BookingExtra bookingextra = db.BookingExtras.Find(id);

            db.BookingExtras.Remove(bookingextra);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //
        // GET: /BookingExtra/Details/5

        public ActionResult Details(long id = 0)
        {
            BookingExtra bookingextra = db.BookingExtras.Find(id);

            if (bookingextra == null)
            {
                return(HttpNotFound());
            }
            return(View(bookingextra));
        }
        //
        // GET: /BookingExtra/Edit/5

        public ActionResult Edit(long id = 0)
        {
            BookingExtra bookingextra = db.BookingExtras.Find(id);

            if (bookingextra == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
            return(View(bookingextra));
        }
        public string GenerateBESReference(BookingExtraSelection bes, BookingExtra extra)
        {
            string reference = "";


            reference += extra.LegacyReference;
            reference += "/" + bes.BookingExtraSelectionID;
            reference += "/" + ((DateTime)bes.ExtraRentalDate).ToString("ddMMyyyy").Replace("/", "").Replace("-", "");


            return(reference);
        }
        public ActionResult Create(BookingExtra bookingextra)
        {
            bookingextra.WhenCreated = DateTime.Now;

            if (ModelState.IsValid)
            {
                db.BookingExtras.Add(bookingextra);
                db.SaveChanges();
                ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
                return(RedirectToAction("SingleBookingExtraIndex", "BookingExtra", new { bookingextraID = bookingextra.BookingExtraID }));
            }

            ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
            return(View(bookingextra));
        }
Ejemplo n.º 6
0
 public void ExtraServicesProcess()
 {
     foreach (RepeaterItem item in rptExtraServices.Items)
     {
         HiddenField       hiddenId   = (HiddenField)item.FindControl("hiddenId");
         HtmlInputCheckBox chkService = (HtmlInputCheckBox)item.FindControl("chkService");
         ExtraOption       option     = Module.ExtraOptionGetById(Convert.ToInt32(hiddenId.Value));
         BookingExtra      extra      = Module.BookingExtraGet(Booking, option);
         if (extra.Id <= 0 && chkService.Checked)
         {
             Module.SaveOrUpdate(extra);
         }
         if (extra.Id > 0 && !chkService.Checked)
         {
             Module.Delete(extra);
         }
     }
 }
Ejemplo n.º 7
0
        public ActionResult BookCarRental()
        {
            //NB - need a method to get all
            //pull back from db the correct extra and pass to viewbag
            List <BookingExtra> CarBookingExtras = BookingExtra.GetBookingExtrasOfType();

            foreach (var cbe in CarBookingExtras)
            {
                cbe.GetAllBookingExtraAttributes();
            }

            //get all the images for all the extras
            List <ExtrasImage> allTheExtraImages = new List <ExtrasImage>();

            ViewBag.CarBookingExtras = CarBookingExtras;

            //list of airports for  transfers

            //drop down lists
            using (var _db = new PortugalVillasContext())
            {
                var listOfAllTypes = _db.BookingExtraTypes.ToSafeReadOnlyCollection();
                //create list and put in viewbag
                List <SelectListItem> selectListOfAllTypes = new List <SelectListItem>();
                selectListOfAllTypes.Add(new SelectListItem {
                    Text = "Show All", Value = "0"
                });

                foreach (var type in listOfAllTypes)
                {
                    selectListOfAllTypes.Add(new SelectListItem {
                        Text = type.ExtraTypeName, Value = type.BookingExtraTypeID.ToString()
                    });
                }
                //add a default


                ViewBag.ExtraTypes = selectListOfAllTypes;
            }

            ViewBag.Keywords = "Portugal Villas, portugal rental cottages, cheap holidays to portugal, silver coast villas,cheap portugal holidays,villa hotel rental portugal";
            ViewBag.Title    = "A quality selection of cars that includes the Hyundai I20,Mitsubishi Colt, Mitsubishi Colt Diesel, Mitsubishi Lancer, Mitsubishi Grandis, you can also book direct airport transfers here to drop you from the airport directly to your villas and add package and sightseeing tours for you and the family, to well loved destinations like Alcobaça, Batalha and Fatima, the Sintra Palace or Obidos and Nazare. See the EXPO 98 & Ocenarium or stay in Salir do Porto, sunny Formigal or the beautiful A-da-Gorda. With cheap seasonal holiday rentals in Sao Martinho do Porto, Barrantes, Capeleira and Sancheira Pequena you can get quality Portugese accommodation the entire year round.";
            return(View());
        }
        public ActionResult Edit(BookingExtra bookingextra)
        {
            var oldExtra = db.BookingExtras.Where(x => x.BookingExtraID == bookingextra.BookingExtraID).First();

            bookingextra.WhenCreated  = oldExtra.WhenCreated;
            bookingextra.WhenModified = oldExtra.WhenModified;

            if (ModelState.IsValid)
            {
                using (var _db = new PortugalVillasContext())
                {
                    _db.BookingExtras.Attach(bookingextra);
                    _db.Entry(bookingextra).State = EntityState.Modified;
                    _db.SaveChanges();
                    ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID",
                                                                "ExtraTypeName", bookingextra.BookingExtraTypeID);
                    return(RedirectToAction("SingleBookingExtraIndex", "BookingExtra",
                                            new { bookingextraID = bookingextra.BookingExtraID }));
                }
            }
            ViewBag.BookingExtraTypeID = new SelectList(db.BookingExtraTypes, "BookingExtraTypeID", "ExtraTypeName", bookingextra.BookingExtraTypeID);
            return(View(bookingextra));
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!CheckAvailable())
            {
                return;
            }

            // Kiểm tra số phòng đã chọn, nếu chưa chọn phòng nào thì thông báo yêu cầu
            if (_bookingRooms.Count <= 0 && !chkCharter.Checked)
            {
                ShowErrors("Hãy chọn ít nhất một phòng");
                return;
            }

            //2. Lưu thông tin phòng như thế nào
            // Dùng vòng lặp lưu thông tin đơn thuần, không có giá trị đi kèm nào cả

            // Phải lưu thông tin booking trước

            #region -- Booking --

            Booking booking  = new Booking();
            var     agencyId = -1;
            try
            {
                agencyId = Int32.Parse(agencySelector.Value);
            }
            catch { }
            booking.Agency       = AddBookingBLL.AgencyGetById(agencyId);
            booking.CreatedBy    = Page.User.Identity as User;
            booking.CreatedDate  = DateTime.Now;
            booking.ModifiedDate = DateTime.Now;
            booking.Partner      = null;
            booking.Sale         = booking.CreatedBy;
            booking.StartDate    = Date.Value;


            if (ApprovedDefault)
            {
                booking.Status = StatusType.Approved;
            }
            else
            {
                booking.Status = StatusType.Pending;
            }

            booking.Status = StatusType.Pending;

            if (TripBased)
            {
                booking.Trip = Module.TripGetById(Convert.ToInt32(ddlTrips.SelectedValue));
            }
            else
            {
                booking.Trip = null;
            }
            var cruise = null as Cruise;
            if (ViewState["cruiseId"] != null)
            {
                var cruiseIdViewState = (int)ViewState["cruiseId"];
                cruise = Module.GetObject <Cruise>(cruiseIdViewState);
            }
            booking.Cruise    = cruise;
            booking.IsCharter = chkCharter.Checked;
            booking.Total     = 0;

            // Xác định custom booking id
            if (UseCustomBookingId)
            {
                int maxId = Module.BookingGenerateCustomId(booking.StartDate);
                booking.Id = maxId;
            }

            //if (booking.Cruise.Name.Contains("Scorpio") && !booking.Cruise.Name.Contains("1"))
            //{
            //    booking.IsCharter = true;
            //}
            Module.Save(booking, UserIdentity);
            #endregion

            // Sau đó mới có thể lưu thông tin phòng
            // Đối với phòng có baby và child theo phân bố từ trước sẽ thêm child, baby

            #region -- Booking Room --
            foreach (BookingRoom room in _bookingRooms)
            {
                room.Book = booking;
                Module.Save(room);

                // Ngoài ra còn phải lưu thông tin khách hàng

                #region -- Thông tin khách hàng, suy ra từ thông tin phòng --

                for (int ii = 1; ii <= room.Booked; ii++)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Adult;
                    if (CustomerPrice)
                    {
                        customer.Total = room.Total / 2;
                    }
                    Module.Save(customer);
                }

                if (room.HasBaby)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Baby;
                    Module.Save(customer);
                }

                if (room.HasChild)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Children;
                    Module.Save(customer);
                }

                #endregion
            }

            #endregion

            #region -- Thông tin dịch vụ đi kèm --

            foreach (RepeaterItem serviceItem in rptExtraServices.Items)
            {
                //HiddenField hiddenValue = (HiddenField)serviceItem.FindControl("hiddenValue");
                HiddenField       hiddenId   = (HiddenField)serviceItem.FindControl("hiddenId");
                HtmlInputCheckBox chkService = (HtmlInputCheckBox)serviceItem.FindControl("chkService");
                if (chkService.Checked)
                {
                    ExtraOption  service = Module.ExtraOptionGetById(Convert.ToInt32(hiddenId.Value));
                    BookingExtra extra   = new BookingExtra();
                    extra.Booking     = booking;
                    extra.ExtraOption = service;
                    Module.Save(extra);
                }
            }

            #endregion

            #region -- Track thêm mới --

            BookingTrack track = new BookingTrack();
            track.Booking      = booking;
            track.ModifiedDate = DateTime.Now;
            track.User         = UserIdentity;
            Module.SaveOrUpdate(track);

            BookingChanged change = new BookingChanged();
            change.Action    = BookingAction.Created;
            change.Parameter = string.Format("{0}", booking.Total);
            change.Track     = track;
            Module.SaveOrUpdate(change);

            #endregion

            if (chkCharter.Checked)
            {
                var locked = new Locked();
                locked.Charter     = booking;
                locked.Cruise      = booking.Cruise;
                locked.Description = "Booking charter";
                locked.Start       = booking.StartDate;
                locked.End         = booking.EndDate;
                Module.SaveOrUpdate(locked);
            }

            //var smtpClient = new SmtpClient("mail.orientalsails.com", 26)
            //{
            //    Credentials = new NetworkCredential("*****@*****.**", "EGGaXBwuEWa+")

            //};

            //var message = new MailMessage
            //{
            //    From = new MailAddress("*****@*****.**"),
            //    IsBodyHtml = true,
            //    BodyEncoding = Encoding.UTF8,
            //    Body = "alooo",
            //    Subject = "CutOff Date Booking Reminder"
            //};

            //message.To.Add(new MailAddress("*****@*****.**"));
            //if (booking.BookingSale != null)
            //{
            //    if (booking.BookingSale.Sale != null)
            //    {
            //        message.To.Add(new MailAddress(booking.BookingSale.Sale.Email));
            //    }
            //}
            //smtpClient.Send(message);

            PageRedirect(string.Format("BookingView.aspx?NodeId={0}&SectionId={1}&bi={2}&Notify=0", Node.Id,
                                       Section.Id, booking.Id));
        }
Ejemplo n.º 10
0
        public BookingExtraSelection CreateBookingExtraSelection(BookingExtraSelection bookingExtraSelection, BookingExtra extra, Customer theCustomer, PortugalVillasContext db)
        {
            bookingExtraSelection.BESCurrencyConversionSymbol = theCustomer.PreferredCurrencySymbol;
            bookingExtraSelection.BESPreferredCurrency        = theCustomer.PreferredCurrency;

            var cc = new CurrencyConverterController();


            long?currentBookingTypeID = bookingExtraSelection.GetBookingExtraTypeIDFromBookingExtraSelection();

            bookingExtraSelection.CustomerID = theCustomer.CustomerID;

            //the price already needs to be assigned
            bookingExtraSelection.BESPrice = BookingExtraSelection.GetBookingExtraPrice(bookingExtraSelection, db);
            bookingExtraSelection.BESExtraServicesPrice = BookingExtraSelection.CalculateBookingExtraAdditionalCostsAndAssignToThisBooking(bookingExtraSelection, db);

            bookingExtraSelection.BESTotalServicesPrice = BookingExtraSelection.GetBookingExtraTotalServicesPrice(bookingExtraSelection, db);


            bookingExtraSelection.WhenCreated = DateTime.Now;

            //calc number of guests
            if (bookingExtraSelection.NumberOfGuests == null || bookingExtraSelection.NumberOfGuests == 0)
            {
                bookingExtraSelection.CalculateNoOfGuests();
            }

            //if not UK need to do currency conversion
            if (theCustomer.Country.ToLower() != "united kingdom" && ConfigurationManager.AppSettings["defaultCurrency"] == "GBP")
            {
                var baseCurrency = "GBP";
                var newCurrency  = "EUR";

                var exchangeRateFromDB =
                    db.CurrencyExchanges.First(x => x.CurrencyExchangeName == "GBP-EUR");

                try
                {
                    bookingExtraSelection.BESPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESPrice);
                    bookingExtraSelection.BESCurrencyConversionPrice = bookingExtraSelection.BESPrice;
                    bookingExtraSelection.BESExtraServicesPrice      = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESExtraServicesPrice);
                    bookingExtraSelection.BESTotalServicesPrice      = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESTotalServicesPrice);



                    //set exchange rate
                    bookingExtraSelection.BESCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    bookingExtraSelection.BESCurrencyExchangeRate     = exchangeRateFromDB.CurrencyExchangeRate;
                    bookingExtraSelection.BESPreferredCurrency        = "EUR";
                }
                catch (Exception)
                {
                    throw;
                }
            }

            else if (ConfigurationManager.AppSettings["defaultCurrency"] == "USD")
            {
                var baseCurrency = "GBP";
                var newCurrency  = "USD";

                var exchangeRateFromDB =
                    db.CurrencyExchanges.First(x => x.CurrencyExchangeName == "GBP-USD");

                try
                {
                    bookingExtraSelection.BESPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESPrice);
                    bookingExtraSelection.BESCurrencyConversionPrice = bookingExtraSelection.BESPrice;
                    bookingExtraSelection.BESExtraServicesPrice      = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESExtraServicesPrice);
                    bookingExtraSelection.BESTotalServicesPrice      = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)bookingExtraSelection.BESTotalServicesPrice);


                    //set exchange rate
                    bookingExtraSelection.BESCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol;
                    bookingExtraSelection.BESCurrencyExchangeRate     = exchangeRateFromDB.CurrencyExchangeRate;
                    bookingExtraSelection.BESPreferredCurrency        = "USD";
                }
                catch (Exception)
                {
                    throw;
                }
            }

            //generate reference
            var refGenService = new ReferenceGenerationService();

            bookingExtraSelection.BookingExtraPRCReference = refGenService.GenerateBESReference(bookingExtraSelection, extra);


            if (ModelState.IsValid)
            {
                db.BookingExtraSelections.Add(bookingExtraSelection);
                if (db.SaveChanges() > 0)
                {
                    //generate reference with ID
                    bookingExtraSelection.BookingExtraPRCReference = refGenService.GenerateBESReference(bookingExtraSelection, extra);

                    db.Entry(bookingExtraSelection).State = EntityState.Modified;
                    db.SaveChanges();
                    return(bookingExtraSelection);
                }
            }
            throw new Exception();
        }
        public void AddExtraFormBookingToSession(BookingExtraSelection theExtraSelection)
        {
            if (theExtraSelection.BookingExtraID == 0)
            {
                //get the value from the session instead
                if (Session["theCurrentExtraID"].ToString() != "")
                {
                    theExtraSelection.BookingExtraID = (int)Session["theCurrentExtraID"];
                }
            }


            //take the ExtraBooking and put it in the session
            try
            {
                //get the booking extra and extra type from the PRC Ref / Type

                /*var test = theExtraSelectionForm["ExtraRentalDate"].ToString();
                 *
                 * ///////////////////
                 * //// GENERAL ATTRIBUTES - COMMON
                 * ///////////////////
                 *
                 * //all
                 *
                 * theExtraSelection.ExtraRentalDate = DateTime.ParseExact(theExtraSelectionForm["ExtraRentalDate"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
                 * theExtraSelection.ExtraReturnDate = DateTime.ParseExact(theExtraSelectionForm["ExtraReturnDate"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
                 *
                 * theExtraSelection.NumberOfChildseats = Convert.ToInt16(theExtraSelectionForm["SpecialRequests"]);
                 *
                 *
                 * //cars
                 * theExtraSelection.SpecialRequests = theExtraSelectionForm["NumberOfChildseats"];
                 *
                 *
                 * //wine tourcs
                 * //theExtraSelection.
                 *
                 * //airport transfers
                 */

                //tours


                //get any remaining fields
                BookingExtra theExtraType = db.BookingExtras.Find(theExtraSelection.BookingExtraID);
                theExtraSelection.BookingExtra = theExtraType;
                //need to get PRCRef

                //calculate main and addition pricings and bes setup
                try
                {
                    theExtraSelection.BESPrice = BookingExtraSelection.GetBookingExtraPrice(theExtraSelection, db);


                    if (theExtraSelection.ExtraReturnDate != null)
                    {
                        theExtraSelection.NumberOfDays =
                            GeneralStaticHelperMethods.CalculateNoofDays(theExtraSelection.ExtraRentalDate,
                                                                         theExtraSelection.ExtraReturnDate);
                    }
                    else
                    {
                        theExtraSelection.NumberOfDays = 1;
                    }

                    //this happens AFTER number of days has been calculated
                    theExtraSelection.BESExtraServicesPrice =
                        BookingExtraSelection.CalculateBookingExtraAdditionalCostsAndAssignToThisBooking(
                            theExtraSelection, db);
                }
                catch (Exception)
                {
                }

                //assign a guid for cart deletion
                theExtraSelection.BookingGuid = new Guid();
                theExtraSelection.BookingGuid = System.Guid.NewGuid();


                //1. Test if there are any bookings in the viewbag currently.
                if (AreThereAnyExtraBookingsInTheSession() > 0)
                {
                    //there are bookings in the viewbag, take the list, add another, put back in the bag
                    List <BookingExtraSelection> theSessionBookings = (List <BookingExtraSelection>)Session["Cart_ExtraBookings"];
                    theSessionBookings.Add(theExtraSelection);
                    Session["Cart_ExtraBookings"] = theSessionBookings;
                }
                else
                {
                    //there are no bookings in the viewbag - add a list of bookings with this CartBooking as the first booking
                    List <BookingExtraSelection> theSessionBookings = new List <BookingExtraSelection>();
                    theSessionBookings.Add(theExtraSelection);
                    Session["Cart_ExtraBookings"] = theSessionBookings;
                }



                string RootURL = Request.Url.Authority;
                RootURL += "/Home/BookCarRental";

                Response.Redirect("http://" + RootURL);



                /////////////
                //then put the extra selection into the ViewBag for later
                /////////////
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //2. Lưu thông tin phòng như thế nào
            // Dùng vòng lặp lưu thông tin đơn thuần, không có giá trị đi kèm nào cả

            // Phải lưu thông tin booking trước

            #region -- Booking --
            var     series  = Module.GetById <Series>(Convert.ToInt32(Request["si"]));
            Booking booking = new Booking();

            booking.CreatedBy      = Page.User.Identity as User;
            booking.CreatedDate    = DateTime.Now;
            booking.ModifiedDate   = DateTime.Now;
            booking.Partner        = null;
            booking.Sale           = booking.CreatedBy;
            booking.StartDate      = Date.Value;
            booking.SpecialRequest = txtSpecialRequest.Text;
            booking.AgencyCode     = txtAgencyCode.Text;
            booking.Agency         = series.Agency;
            booking.Booker         = series.Booker;
            //booking.Status = StatusType.Pending;
            booking.Total         = 0;
            booking.Series        = series;
            booking.PickupAddress = "N/A";
            booking.Deadline      = booking.StartDate.Subtract(new TimeSpan(series.CutoffDate, 0, 0, 0));

            if (TripBased)
            {
                booking.Trip = Module.TripGetById(Convert.ToInt32(ddlTrips.SelectedValue));
            }
            else
            {
                booking.Trip = null;
            }
            if (booking.Trip != null)
            {
                booking.EndDate = booking.StartDate.AddDays(booking.Trip.NumberOfDay - 1);
            }

            var cruise = null as Cruise;
            if (ViewState["cruiseId"] != null)
            {
                var cruiseIdViewState = (int)ViewState["cruiseId"];
                cruise = Module.GetObject <Cruise>(cruiseIdViewState);
            }
            booking.Cruise    = cruise;
            booking.IsCharter = chkCharter.Checked;
            booking.Total     = 0;

            // Xác định custom booking id
            if (UseCustomBookingId)
            {
                int maxId = Module.BookingGenerateCustomId(booking.StartDate);
                booking.Id = maxId;
            }

            //if (booking.Cruise.Name.Contains("Scorpio") && !booking.Cruise.Name.Contains("1"))
            //{
            //    booking.IsCharter = true;
            //}

            var statusType = (StatusType)Enum.Parse(typeof(StatusType), ddlStatusType.SelectedValue);
            booking.Status = statusType;
            if (statusType == StatusType.CutOff)
            {
                if (!string.IsNullOrWhiteSpace(txtCutOffDays.Text))
                {
                    booking.CutOffDays = Int32.Parse(txtCutOffDays.Text.Trim());
                }
            }
            if (statusType == StatusType.Pending)
            {
                //booking.Status = StatusType.Pending;
                if (!string.IsNullOrWhiteSpace(txtDeadline.Text))
                {
                    booking.Deadline = DateTime.ParseExact(txtDeadline.Text, "dd/MM/yyyy HH:mm",
                                                           CultureInfo.InvariantCulture);
                }
            }

            Module.Save(booking, UserIdentity);
            #endregion

            // Sau đó mới có thể lưu thông tin phòng
            // Đối với phòng có baby và child theo phân bố từ trước sẽ thêm child, baby
            GetBookingRoom();
            #region -- Booking Room --
            foreach (BookingRoom room in _bookingRooms)
            {
                room.Book = booking;
                Module.Save(room);

                // Ngoài ra còn phải lưu thông tin khách hàng

                #region -- Thông tin khách hàng, suy ra từ thông tin phòng --

                for (int ii = 1; ii <= room.Booked; ii++)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Adult;
                    if (CustomerPrice)
                    {
                        customer.Total = room.Total / 2;
                    }
                    Module.Save(customer);
                    room.Customers.Add(customer);
                }

                if (room.HasBaby)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Baby;
                    Module.Save(customer);
                    room.Customers.Add(customer);
                }

                if (room.HasChild)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Children;
                    Module.Save(customer);
                    room.Customers.Add(customer);
                }
                Module.Save(room);
                #endregion
            }

            #endregion

            #region -- Thông tin dịch vụ đi kèm --

            foreach (RepeaterItem serviceItem in rptExtraServices.Items)
            {
                //HiddenField hiddenValue = (HiddenField)serviceItem.FindControl("hiddenValue");
                HiddenField       hiddenId   = (HiddenField)serviceItem.FindControl("hiddenId");
                HtmlInputCheckBox chkService = (HtmlInputCheckBox)serviceItem.FindControl("chkService");
                if (chkService.Checked)
                {
                    ExtraOption  service = Module.ExtraOptionGetById(Convert.ToInt32(hiddenId.Value));
                    BookingExtra extra   = new BookingExtra();
                    extra.Booking     = booking;
                    extra.ExtraOption = service;
                    Module.Save(extra);
                }
            }

            #endregion

            #region -- Track thêm mới --

            BookingTrack track = new BookingTrack();
            track.Booking      = booking;
            track.ModifiedDate = DateTime.Now;
            track.User         = UserIdentity;
            Module.SaveOrUpdate(track);

            BookingChanged change = new BookingChanged();
            change.Action    = BookingAction.Created;
            change.Parameter = string.Format("{0}", booking.Total);
            change.Track     = track;
            Module.SaveOrUpdate(change);

            #endregion

            if (chkCharter.Checked)
            {
                var locked = new Locked();
                locked.Charter     = booking;
                locked.Cruise      = booking.Cruise;
                locked.Description = "Booking charter";
                locked.Start       = booking.StartDate;
                locked.End         = booking.EndDate;
                Module.SaveOrUpdate(locked);
            }
            Page.ClientScript.RegisterStartupScript(this.GetType(), "RefreshParentPage", "RefreshParentPage();", true);
        }
Ejemplo n.º 13
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                // Kiểm tra thêm về phòng và thông tin đối tác
                if (!AllowNoAgency && agencySelector.SelectedAgency == null)
                {
                    ShowError("Chưa có thông tin đối tác");
                    return;
                }

                if (!Date.HasValue)
                {
                    ShowError("Phải có ngày khởi hành");
                    return;
                }

                //2. Lưu thông tin phòng như thế nào
                // Dùng vòng lặp lưu thông tin đơn thuần, không có giá trị đi kèm nào cả

                // Phải lưu thông tin booking trước
                #region -- Booking --
                Booking booking = new Booking();
                if (agencySelector.SelectedAgency != null)
                {
                    booking.Agency = agencySelector.SelectedAgency;
                }
                booking.CreatedBy    = Page.User.Identity as User;
                booking.CreatedDate  = DateTime.Now;
                booking.ModifiedDate = DateTime.Now;
                booking.Partner      = null;
                booking.Sale         = booking.CreatedBy;
                booking.StartDate    = Date.Value;
                if (ApprovedDefault)
                {
                    booking.Status = StatusType.Approved;
                }
                else
                {
                    booking.Status = StatusType.Pending;
                }
                if (TripBased)
                {
                    booking.Trip = Module.TripGetById(Convert.ToInt32(ddlTrips.SelectedValue));
                }
                else
                {
                    booking.Trip = null;
                }
                booking.Total = 0;

                Module.Save(booking, UserIdentity);

                #region -- Track thêm mới --
                BookingTrack track = new BookingTrack();
                track.Booking      = booking;
                track.ModifiedDate = DateTime.Now;
                track.User         = UserIdentity;
                Module.SaveOrUpdate(track);

                BookingChanged change = new BookingChanged();
                change.Action    = BookingAction.Created;
                change.Parameter = string.Format("{0}", booking.Total);
                change.Track     = track;
                Module.SaveOrUpdate(change);
                #endregion

                #region -- Thông tin dịch vụ đi kèm --
                foreach (RepeaterItem serviceItem in rptExtraServices.Items)
                {
                    //HiddenField hiddenValue = (HiddenField)serviceItem.FindControl("hiddenValue");
                    HiddenField hiddenId   = (HiddenField)serviceItem.FindControl("hiddenId");
                    CheckBox    chkService = (CheckBox)serviceItem.FindControl("chkService");
                    if (chkService.Checked)
                    {
                        ExtraOption  service = Module.ExtraOptionGetById(Convert.ToInt32(hiddenId.Value));
                        BookingExtra extra   = new BookingExtra();
                        extra.Booking     = booking;
                        extra.ExtraOption = service;
                        Module.Save(extra);
                    }
                }
                #endregion

                #endregion

                // Tạo danh sách khách theo booking
                int adult = 0;
                int child = 0;
                int baby  = 0;

                int totalAdult = ddlAdult.SelectedIndex;
                int totalChild = ddlChild.SelectedIndex;
                int totalBaby  = ddlBaby.SelectedIndex;

                while (adult < totalAdult)
                {
                    Customer customer = new Customer();
                    customer.Type    = CustomerType.Adult;
                    customer.Booking = booking;
                    Module.SaveOrUpdate(customer);
                    adult++;
                }

                while (child < totalChild)
                {
                    Customer customer = new Customer();
                    customer.Type    = CustomerType.Children;
                    customer.Booking = booking;
                    Module.SaveOrUpdate(customer);
                    child++;
                }

                while (baby < totalBaby)
                {
                    Customer customer = new Customer();
                    customer.Type    = CustomerType.Baby;
                    customer.Booking = booking;
                    Module.SaveOrUpdate(customer);
                    baby++;
                }

                PageRedirect(string.Format("BookingView.aspx?NodeId={0}&SectionId={1}&bi={2}&Notify=0", Node.Id, Section.Id, booking.Id));
            }
            catch (Exception ex)
            {
                ShowError("Error :" + ex.Message);
                _logger.Error(ex.Message, ex);
            }
        }
Ejemplo n.º 14
0
        protected void buttonSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                //Biến để đếm tổng số customer

                // Tạo đối tượng booking mới
                Booking     booking     = new Booking();
                CultureInfo cultureInfo = new CultureInfo("vi-VN");

                #region -- Các thông tin cơ bản --
                if (PageEngine.User.Identity is User)
                {
                    booking.CreatedBy  = (User)Page.User.Identity;
                    booking.ModifiedBy = (User)Page.User.Identity;
                    booking.Partner    = (User)Page.User.Identity;
                    //booking.Sale = (User)Page.User.Identity;
                }

                booking.CreatedDate  = DateTime.Now;
                booking.ModifiedDate = DateTime.Now;
                DateTime startDate = DateTime.ParseExact(Session["StartDate"].ToString(), "dd/MM/yyyy",
                                                         cultureInfo.DateTimeFormat);
                booking.StartDate = startDate;
                booking.Status    = StatusType.Cancelled;
                #endregion

                #region - Lấy trip và trip option đã book từ biến session -

                SailsTrip trip = Module.TripGetById(Convert.ToInt32(Session["TripId"]));
                booking.Trip = trip;

                TripOption tripOption = TripOption.Option1;
                if (!string.IsNullOrEmpty(Session["TripOption"].ToString()))
                {
                    tripOption = (TripOption)Convert.ToInt32(Session["TripOption"]);
                }

                booking.TripOption = tripOption;
                #endregion

                // Save booking lại
                if (panelCustomer.Visible)
                {
                    booking.Note = fckCustomers.Value;
                }

                if (liAnonymous.Visible)
                {
                    booking.Name  = txtYourName.Text;
                    booking.Email = txtEmail.Text;
                }

                booking.PickupAddress  = txtPickupAddress.Text;
                booking.SpecialRequest = txtSpecialRequest.Text;
                Module.Save(booking, null);

                #region -- Lấy thông tin về extra services từ session --
                // Mặc dù extra service đã được chọn từ form trước, tuy nhiên tại form này mới lưu lại thông tin booking
                // Do đó đến form này mới lấy lại thông tin extra service
                if (Session["ExtraService"] != null)
                {
                    string[] services = Session["ExtraService"].ToString().Split(',');
                    foreach (string serviceId in services)
                    {
                        ExtraOption  service        = Module.ExtraOptionGetById(Convert.ToInt32(serviceId));
                        BookingExtra bookingService = new BookingExtra();
                        bookingService.Booking     = booking;
                        bookingService.ExtraOption = service;
                        Module.Save(bookingService);
                    }
                }
                #endregion

                #region -- Lưu thông tin khách hàng --
                foreach (RepeaterItem item in rptRoomList.Items)
                {
                    // Đối với mỗi đối tượng trong room list
                    Label label_RoomId = (Label)item.FindControl("label_RoomId");

                    #region -- Thông tin về phòng --
                    HiddenField hiddenRoomClassId = (HiddenField)item.FindControl("hiddenRoomClassId");
                    HiddenField hiddenRoomTypeId  = (HiddenField)item.FindControl("hiddenRoomTypeId");

                    // Lấy về room id theo label Room id đã bound trước đó
                    int roomId = 0;
                    // Lấy ID của phòng nếu đã có phòng chọn (prefer room)
                    if (!string.IsNullOrEmpty(label_RoomId.Text))
                    {
                        roomId = Convert.ToInt32(label_RoomId.Text);
                    }
                    Room room = null;
                    if (roomId > 0)
                    {
                        room = Module.RoomGetById(roomId);
                    }
                    #endregion

                    #region -- Lấy thông tin khách hàng --
                    CheckBox checkBoxAddChild = (CheckBox)item.FindControl("checkBoxAddChild");
                    CheckBox checkBoxAddBaby  = (CheckBox)item.FindControl("checkBoxAddBaby");
                    CheckBox checkBoxSingle   = (CheckBox)item.FindControl("checkBoxSingle");

                    //TODO: CHECK THIS
                    //BookingType bookingType = (BookingType) Enum.Parse(typeof(BookingType),ddlRoomType.SelectedValue);
                    const BookingType bookingType   = BookingType.Double;
                    CustomerInfoInput customerInfo1 = (CustomerInfoInput)item.FindControl("customer1");
                    CustomerInfoInput customerInfo2 = (CustomerInfoInput)item.FindControl("customer2");

                    BookingRoom bookingRoom;
                    if (room != null)
                    {
                        bookingRoom = new BookingRoom(booking, room, room.RoomClass, room.RoomType);
                    }
                    else
                    {
                        RoomClass roomClass = Module.RoomClassGetById(Convert.ToInt32(hiddenRoomClassId.Value));
                        RoomTypex roomType  = Module.RoomTypexGetById(Convert.ToInt32(hiddenRoomTypeId.Value));
                        bookingRoom = new BookingRoom(booking, null, roomClass, roomType);
                    }
                    bookingRoom.BookingType = bookingType;
                    bookingRoom.HasBaby     = checkBoxAddBaby.Checked;
                    bookingRoom.HasChild    = checkBoxAddChild.Checked;
                    bookingRoom.IsSingle    = checkBoxSingle.Checked;
                    Module.Save(bookingRoom);
                    #endregion

                    #region -- Khách hàng --
                    Customer customer1;
                    Customer customer2;

                    Control trCustomer2 = item.FindControl("trCustomer2");

                    customer1             = customerInfo1.NewCustomer(Module);
                    customer1.BookingRoom = bookingRoom;
                    customer1.Booking     = booking;
                    customer1.Type        = CustomerType.Adult;
                    Module.Save(customer1);

                    if (bookingRoom.RoomType.Id != SailsModule.TWIN || trCustomer2.Visible)
                    {
                        customer2             = customerInfo2.NewCustomer(Module);
                        customer2.BookingRoom = bookingRoom;
                        customer2.Booking     = booking;
                        customer2.Type        = CustomerType.Adult;
                        Module.Save(customer2);
                    }

                    if (checkBoxAddChild.Checked)
                    {
                        CustomerInfoInput customerChild = (CustomerInfoInput)item.FindControl("customerChild");
                        Customer          child         = customerChild.NewCustomer(Module);
                        child.BookingRoom = bookingRoom;
                        child.Booking     = booking;
                        child.Type        = CustomerType.Children;
                        Module.Save(child);
                    }

                    if (checkBoxAddBaby.Checked)
                    {
                        CustomerInfoInput customerBaby = (CustomerInfoInput)item.FindControl("customerBaby");
                        Customer          baby         = customerBaby.NewCustomer(Module);
                        baby.BookingRoom = bookingRoom;
                        baby.Booking     = booking;
                        baby.Type        = CustomerType.Baby;
                        Module.Save(baby);
                    }

                    #endregion
                }
                #endregion

                Session.Add("Finish", booking.Id);

                // Chuyển sang trang kết thúc (trang confirm lại lần cuối booking)
                PageEngine.PageRedirect(string.Format("{0}/{1}{2}", UrlHelper.GetUrlFromSection(Module.Section),
                                                      SailsModule.ACTION_BOOKING_FINISH_PARAM,
                                                      UrlHelper.EXTENSION));
            }
            catch (Exception ex)
            {
                _logger.Error("Error when buttonSubmit_Click inCustomersInfo control", ex);
                throw;
            }
        }
Ejemplo n.º 15
0
        public ActionResult BookAirTransfer()
        {
            ViewBag.AirTransfer = BookingExtra.GetBookingExtrasOfType(3);

            return(View());
        }
Ejemplo n.º 16
0
        public ActionResult BookWineTour()
        {
            ViewBag.WineBookingExtras = BookingExtra.GetBookingExtrasOfType(2);

            return(View());
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!CheckAvailable())
            {
                return;
            }

            // Kiểm tra số phòng đã chọn, nếu chưa chọn phòng nào thì thông báo yêu cầu
            if (_bookingRooms.Count <= 0 && !chkCharter.Checked)
            {
                ShowErrors("Hãy chọn ít nhất một phòng");
                return;
            }

            //2. Lưu thông tin phòng như thế nào
            // Dùng vòng lặp lưu thông tin đơn thuần, không có giá trị đi kèm nào cả

            // Phải lưu thông tin booking trước

            #region -- Booking --

            Booking booking = new Booking();
            booking.CreatedBy    = Page.User.Identity as User;
            booking.CreatedDate  = DateTime.Now;
            booking.ModifiedDate = DateTime.Now;
            booking.Partner      = null;
            booking.Sale         = booking.CreatedBy;
            booking.StartDate    = Date.Value;


            if (ApprovedDefault)
            {
                booking.Status = StatusType.Approved;
            }
            else
            {
                booking.Status = StatusType.Pending;
            }

            booking.Status = StatusType.Pending;

            if (TripBased)
            {
                booking.Trip = Module.TripGetById(Convert.ToInt32(ddlTrips.SelectedValue));
            }
            else
            {
                booking.Trip = null;
            }
            var cruise = null as Cruise;
            if (ViewState["cruiseId"] != null)
            {
                var cruiseIdViewState = (int)ViewState["cruiseId"];
                cruise = Module.GetObject <Cruise>(cruiseIdViewState);
            }
            booking.Cruise    = cruise;
            booking.IsCharter = chkCharter.Checked;
            booking.Total     = 0;

            // Xác định custom booking id
            if (UseCustomBookingId)
            {
                int maxId = Module.BookingGenerateCustomId(booking.StartDate);
                booking.Id = maxId;
            }

            //if (booking.Cruise.Name.Contains("Scorpio") && !booking.Cruise.Name.Contains("1"))
            //{
            //    booking.IsCharter = true;
            //}

            // series
            var series = Module.GetById <Series>(Convert.ToInt32(Request["si"]));
            booking.Agency        = series.Agency;
            booking.Booker        = series.Booker;
            booking.Status        = StatusType.Pending;
            booking.Total         = 0;
            booking.Series        = series;
            booking.PickupAddress = "N/A";
            booking.Deadline      = booking.StartDate.Subtract(new TimeSpan(series.CutoffDate, 0, 0, 0));

            booking.AgencyCode     = txtAgencyCode.Text;
            booking.SpecialRequest = txtSpecialRequest.Text;

            var statusType = (StatusType)Enum.Parse(typeof(StatusType), ddlStatusType.SelectedValue);
            booking.Status = statusType;
            if (statusType == StatusType.CutOff)
            {
                if (!string.IsNullOrWhiteSpace(txtCutOffDays.Text))
                {
                    booking.CutOffDays = Int32.Parse(txtCutOffDays.Text.Trim());
                }
            }
            if (statusType == StatusType.Pending)
            {
                //booking.Status = StatusType.Pending;
                if (!string.IsNullOrWhiteSpace(txtDeadline.Text))
                {
                    booking.Deadline = DateTime.ParseExact(txtDeadline.Text, "dd/MM/yyyy HH:mm",
                                                           CultureInfo.InvariantCulture);
                }
            }

            Module.Save(booking, UserIdentity);
            #endregion

            // Sau đó mới có thể lưu thông tin phòng
            // Đối với phòng có baby và child theo phân bố từ trước sẽ thêm child, baby
            _roomCruises = Module.RoomGetAll2(booking.Cruise);
            var currentDayBookings = Module.GetBookingByDate(booking.StartDate, booking.Cruise);
            var nextDayBookings    = Module.GetBookingByDate(booking.StartDate.AddDays(1), booking.Cruise);

            var listRoomAvailable = new List <Room>();

            foreach (Room room in _roomCruises)
            {
                var bk = FindBooking(room, booking.StartDate, currentDayBookings);
                if (bk == null)
                {
                    if (booking.Trip != null && booking.Trip.NumberOfDay > 2)
                    {
                        var nextBk = FindBooking(room, booking.StartDate.AddDays(1), nextDayBookings);
                        if (nextBk == null)
                        {
                            listRoomAvailable.Add(room);
                        }
                    }
                    else
                    {
                        listRoomAvailable.Add(room);
                    }
                }
            }
            #region -- Booking Room --
            foreach (BookingRoom room in _bookingRooms)
            {
                var getRandomRoom = listRoomAvailable.First(r => r.RoomType.Id == room.RoomType.Id);
                room.Room = getRandomRoom;
                room.Book = booking;
                Module.Save(room);
                listRoomAvailable.Remove(getRandomRoom);
                // Ngoài ra còn phải lưu thông tin khách hàng

                #region -- Thông tin khách hàng, suy ra từ thông tin phòng --

                for (int ii = 1; ii <= room.Booked; ii++)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Adult;
                    if (CustomerPrice)
                    {
                        customer.Total = room.Total / 2;
                    }
                    Module.Save(customer);
                    room.Customers.Add(customer);
                }

                if (room.HasBaby)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Baby;
                    Module.Save(customer);
                    room.Customers.Add(customer);
                }

                if (room.HasChild)
                {
                    Customer customer = new Customer();
                    customer.BookingRoom = room;
                    customer.Type        = CustomerType.Children;
                    Module.Save(customer);
                    room.Customers.Add(customer);
                }
                Module.Save(room);
                #endregion
            }

            #endregion

            #region -- Thông tin dịch vụ đi kèm --

            foreach (RepeaterItem serviceItem in rptExtraServices.Items)
            {
                //HiddenField hiddenValue = (HiddenField)serviceItem.FindControl("hiddenValue");
                HiddenField       hiddenId   = (HiddenField)serviceItem.FindControl("hiddenId");
                HtmlInputCheckBox chkService = (HtmlInputCheckBox)serviceItem.FindControl("chkService");
                if (chkService.Checked)
                {
                    ExtraOption  service = Module.ExtraOptionGetById(Convert.ToInt32(hiddenId.Value));
                    BookingExtra extra   = new BookingExtra();
                    extra.Booking     = booking;
                    extra.ExtraOption = service;
                    Module.Save(extra);
                }
            }

            #endregion

            #region -- Track thêm mới --

            BookingTrack track = new BookingTrack();
            track.Booking      = booking;
            track.ModifiedDate = DateTime.Now;
            track.User         = UserIdentity;
            Module.SaveOrUpdate(track);

            BookingChanged change = new BookingChanged();
            change.Action    = BookingAction.Created;
            change.Parameter = string.Format("{0}", booking.Total);
            change.Track     = track;
            Module.SaveOrUpdate(change);

            #endregion

            if (chkCharter.Checked)
            {
                var locked = new Locked();
                locked.Charter     = booking;
                locked.Cruise      = booking.Cruise;
                locked.Description = "Booking charter";
                locked.Start       = booking.StartDate;
                locked.End         = booking.EndDate;
                Module.SaveOrUpdate(locked);
            }

            //var smtpClient = new SmtpClient("mail.orientalsails.com", 26)
            //{
            //    Credentials = new NetworkCredential("*****@*****.**", "EGGaXBwuEWa+")

            //};

            //var message = new MailMessage
            //{
            //    From = new MailAddress("*****@*****.**"),
            //    IsBodyHtml = true,
            //    BodyEncoding = Encoding.UTF8,
            //    Body = "alooo",
            //    Subject = "CutOff Date Booking Reminder"
            //};

            //message.To.Add(new MailAddress("*****@*****.**"));
            //if (booking.BookingSale != null)
            //{
            //    if (booking.BookingSale.Sale != null)
            //    {
            //        message.To.Add(new MailAddress(booking.BookingSale.Sale.Email));
            //    }
            //}
            //smtpClient.Send(message);

            //            PageRedirect(string.Format("BookingView.aspx?NodeId={0}&SectionId={1}&bi={2}&Notify=0", Node.Id,
            //                Section.Id, booking.Id));
            Page.ClientScript.RegisterStartupScript(this.GetType(), "RefreshParentPage", "RefreshParentPage();", true);
        }
Ejemplo n.º 18
0
        public ActionResult BookCarRental(string ExtraType = "0", string priceSort = "", string noOfResults = "0")
        {
            //save vars so can remember them
            ViewBag.ExtraType   = ExtraType;
            ViewBag.priceSort   = priceSort;
            ViewBag.noOfResults = noOfResults;


            int theType = Int32.Parse(ExtraType);
            List <BookingExtra> CarBookingExtras = new List <BookingExtra>();

            switch (theType)
            {
            case 0:
                CarBookingExtras = BookingExtra.GetBookingExtrasOfType();
                break;

            default:
                CarBookingExtras = BookingExtra.GetBookingExtrasOfType(theType);
                break;
            }


            //do additional sorts depending on vars
            //price
            if (priceSort.Equals("LH"))
            {
                CarBookingExtras = CarBookingExtras.OrderBy(x => x.Price).ToList();
            }
            else if (priceSort.Equals("HL"))
            {
                CarBookingExtras = CarBookingExtras.OrderByDescending(x => x.Price).ToList();
            }

            //no of results
            if (noOfResults != "0")
            {
                //pager
            }


            //assign attributes
            foreach (var cbe in CarBookingExtras)
            {
                cbe.GetAllBookingExtraAttributes();
            }

            //get all the images for all the extras
            //List<ExtrasImage> allTheExtraImages = new List<ExtrasImage>();

            ViewBag.CarBookingExtras = CarBookingExtras;


            using (var _db = new PortugalVillasContext())
            {
                var listOfAllTypes = _db.BookingExtraTypes.Where(x => x.BookingExtraTypeID != 11).ToList();
                listOfAllTypes.Add(new BookingExtraType {
                    BookingExtraTypeID = 0, ExtraTypeName = "Show All"
                });
                listOfAllTypes = listOfAllTypes.OrderBy(x => x.BookingExtraTypeID).ToList();
                //create list and put in viewbag
                ViewBag.ExtraTypes = listOfAllTypes;
            }

            ViewBag.Keywords = "holiday villa portugal, silver coast portugal,portugal rental cottages,silver coast villas,cheap holidays to portugal, tourist attractions in portugal";
            ViewBag.Title    = "A quality selection of cars that includes the Hyundai I20,Mitsubishi Colt, Mitsubishi Colt Diesel, Mitsubishi Lancer, Mitsubishi Grandis, you can also book direct airport transfers here to drop you from the airport directly to your villas and add package and sightseeing tours for you and the family, to well loved destinations like Alcobaça, Batalha and Fatima, the Sintra Palace or Obidos and Nazaré. See the EXPO 98 & Ocenarium or stay in Salir do Porto, sunny Formigal or the beautiful A-da-Gorda. With cheap seasonal holiday rentals in Sao Martinho do Porto, Barrantes, Capeleira and Sancheira Pequena you can get quality Portugese accommodation the entire year round.";
            return(View(CarBookingExtras));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Sends an email for 1*1 bookings or extrabookings
        /// </summary>
        /// <param name="customer"></param>
        /// <param name="booking"></param>
        /// <param name="bookingExtraSelection"></param>
        public StandardEmailTemplate(string toEmailAddress, int EmailTemplateID, Customer customer, Booking booking = null, BookingExtraSelection bookingExtraSelection = null)
        {
            EmailTemplate theTemplate;
            EmailTemplate Header;
            EmailTemplate Footer;

            using (PortugalVillasContext db = new PortugalVillasContext())
            {
                theTemplate = db.EmailTemplates.Find(EmailTemplateID);
                Header      = db.EmailTemplates.Find(1);
                Footer      = db.EmailTemplates.Find(2);
            }
            theAsposeMessage = new MailMessage();
            Property     property     = null;
            BookingExtra bookingExtra = null;

            EmailOutType theMainBody = new EmailOutType();

            //map all passed in object fields
            bool bookingToggle          = false;
            bool bookingExtraToggle     = false;
            bool combinedServicesToggle = false;


            //gets necessary

            //assign body
            if (booking == null)
            {
                bookingExtraToggle = true;
                bookingExtra       = BookingExtra.GetBookingExtraByID(bookingExtraSelection.BookingExtraID);
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingExtraSelectionConfirm);
            }
            else if (booking != null && bookingExtraSelection == null)
            {
                bookingToggle = true;
                long propertyID = (long)booking.PropertyID;
                property = Property.GetPropertyByID(propertyID);
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingConfirm);//
            }
            else if (booking != null && bookingExtraSelection != null)
            {
                long propertyID = (long)booking.PropertyID;
                property               = Property.GetPropertyByID(propertyID);
                bookingExtra           = BookingExtra.GetBookingExtraByID(bookingExtraSelection.BookingExtraID);
                combinedServicesToggle = true;
                //theMainBody = new EmailOutType(EmailOutType.EmailOutEmailType.BookingAndBookingExtraSelectionConfirm);
            }



            //customer
            var customerFullName = customer.FirstName + " " + customer.LastName;

            //bookings and extras

            var prcRef = booking != null ? property.LegacyReference : bookingExtra.LegacyReference;

            string bookingPropertyOrSelectionName = booking != null ? property.PropertyName : bookingExtra.BookingExtraName;
            string bookingStartDate = booking != null?Convert.ToDateTime(booking.StartDate.ToString()).ToString("dd/MM/yyyy") : Convert.ToDateTime(bookingExtraSelection.ExtraRentalDate.ToString()).ToString("dd/MM/yyyy");

            string bookingEndDate = booking != null?Convert.ToDateTime(booking.EndDate.ToString()).ToString("dd/MM/yyyy") : new DateTime(1901, 01, 01).ToString("dd/MM/yyyy");

            string numberOfNights = booking != null?booking.NumberOfNights.ToString() : "0";


            theAsposeMessage.To   = customer.EmailAddress;
            theAsposeMessage.From = "*****@*****.**";

            theSMTPClient.Host         = "smtp.gmail.com";
            theSMTPClient.Username     = LoginEmailAddress;
            theSMTPClient.Password     = EmailPassword;
            theSMTPClient.Port         = 587;
            theSMTPClient.EnableSsl    = true;
            theSMTPClient.SecurityMode = SmtpSslSecurityMode.Explicit;


            //set some email body
            //set the body
            //subject
            //
            theAsposeMessage.Subject  = theTemplate.EmailSubject;
            theAsposeMessage.HtmlBody = "";

            //get correct email according to emailEnumID


            var temp = "";
            //string merges
            var fullName  = customer != null ? customerFullName : "";
            var legacyRef = property != null ? property.LegacyReference : bookingExtra.LegacyReference;
            var bookStart = bookingStartDate != null ? bookingStartDate : "";
            var bookEnd   = bookingEndDate != null ? bookingEndDate : "";
            var NoNights  = numberOfNights != null ? numberOfNights : "";
            var reference = booking != null ? booking.BookingPRCReference : bookingExtraSelection.BookingExtraPRCReference;
            var bID       = booking != null?booking.BookingID.ToString() : "";

            var besID = bookingExtraSelection != null?bookingExtraSelection.BookingExtraSelectionID.ToString() : "";

            var finalRentalPayment = booking != null?booking.BookingPrice.ToString() : "";

            var finalRentalPaymentDate = "";

            if (booking != null)
            {
                finalRentalPaymentDate = booking.FinalRentalPaymentDueDate != null ? ((DateTime)booking.FinalRentalPaymentDueDate).ToString("dd/MM/yyyy") : "";
            }

            var rentalDeposit = booking != null?booking.BreakageDeposit.ToString() : "";

            temp = String.Format(theTemplate.EmailTemplateBodyHTML, fullName, legacyRef, bookStart, bookEnd, NoNights, reference, finalRentalPaymentDate, bID, besID, finalRentalPayment, rentalDeposit);

            //booking request optional
            //if (bookingToggle == true && EmailTemplateID == 17)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, property.LegacyReference, bookingStartDate, bookingEndDate, numberOfNights, bookingExtraSelection.BookingExtraSelectionID);
            //}

            ////booking request forms standard
            //else if (bookingToggle == true // && EmailTemplateID == 3 || EmailTemplateID == 4 || EmailTemplateID == 5 || EmailTemplateID == 6
            //    )
            //{


            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, property.LegacyReference, booking.BookingPRCReference, ((DateTime)booking.FinalRentalPaymentDueDate).ToString("dd/MM/yyyy"));


            //}


            //else if (bookingExtraToggle == true)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, prcRef, bookingExtraSelection.BookingExtraSelectionID);

            //}
            //else if (combinedServicesToggle == true)
            //{
            //    temp = String.Format(theTemplate.EmailTemplateBodyHTML, customerFullName, booking.BookingID);

            //}



            //set the body
            var completeEmail = Header.EmailTemplateBodyHTML + temp + Footer.EmailTemplateBodyHTML;

            theAsposeMessage.HtmlBody = completeEmail;
        }