public ActionResult CreateBookingExtraParticipant(BookingExtraParticipant bookingExtraParticipant, string submitBookingExtraPart) { PortugalVillasContext db = new PortugalVillasContext(); if (ModelState.IsValid) { GeneralStaticHelperMethods.IsPersonAdultChildOrInfant(bookingExtraParticipant); //need to assign the booking ID BookingExtraSelection currentSelection = (BookingExtraSelection)Session["CurrentBookingExtraDataGathering"]; bookingExtraParticipant.BookingExtraSelectionID = currentSelection.BookingExtraSelectionID; db.BookingExtraParticipants.Add(bookingExtraParticipant); db.SaveChanges(); //check they're under 18 or whatever then make them an infant, or child if they're the corresponsing age //is infant //is child if (submitBookingExtraPart.Equals("Add this participant and add another")) { return(RedirectToAction("CreateBookingExtraParticipant")); } } return(RedirectToAction("DetailGatheringEventChain")); }
public ActionResult AddPropertyBookingToSession(FormCollection theBooking) { //takes a form - puts the dates and the property into a provisional booking object and adds this booking into the list of //bookings try { if (theBooking["bookingModalPropertyID"].ToString() != "0") { var sessionProp = (Property)Session["theCurrentProperty"]; theBooking["bookingModalPropertyID"] = sessionProp.PropertyID.ToString(); } Booking CartBooking = ConvertPropertyFormBookingToCartBooking(theBooking); //get the price Property prop = db.Properties.Find(CartBooking.PropertyID); CartBooking.Property = prop; try { //init currency converter CartBooking.NumberOfNights = GeneralStaticHelperMethods.CalculateNoofNights(CartBooking.StartDate, CartBooking.EndDate); CartBooking.CalculateBookingPricingForAPropertyBooking(db); CartBooking.CalculateExtrasPriceForAPropertyBooking(prop, CartBooking, db); var currencyService = new CurrencyConverterController(); currencyService.InitialiseDefaultCurrencyForObject(CartBooking); } catch (Exception ex) { /*Response.Redirect("http://" + Request.Url.Authority + "/Error/PropertyErrorSelection");*/ //return RedirectToAction("PropertyErrorSelection", "Error", new { propID = CartBooking.PropertyID }); } //1. Test if there are any bookings in the session currently. if (AreThereAnyBookingsInTheSession() > 0) { //there are bookings in the viewbag, take the list, add another, put back in the bag List <Booking> theSessionBookings = (List <Booking>)Session["Cart_PropertyBookings"]; theSessionBookings.Add(CartBooking); Session["Cart_PropertyBookings"] = theSessionBookings; } else { //there are no bookings in the viewbag - add a list of bookings with this CartBooking as the first booking List <Booking> theSessionBookings = new List <Booking>(); theSessionBookings.Add(CartBooking); Session["Cart_PropertyBookings"] = theSessionBookings; } string RootURL = Request.Url.Authority; RootURL += "/Home/BookCarRental"; Response.Redirect("http://" + RootURL); return(RedirectToAction("BookCarRental", "Home")); } catch (Exception ex) { return(RedirectToAction("SearchProperties", "Home")); throw ex; ///production return(RedirectToAction("SearchProperties", "Home")); } }
public Booking CreateBooking(Booking booking, Property property, Customer theCustomer, PortugalVillasContext db) { //set default currency booking.BookingCurrencyConversionSymbol = theCustomer.PreferredCurrencySymbol; booking.BookingPreferredCurrency = theCustomer.PreferredCurrency; var cc = new CurrencyConverterController(); //if the booking is not in GBP convert to EUROS //NEED TO CONVERT THE CURRENCY BASED ON WHETHER IT NEEDS TO BE EU OR UK int adults, kids, infants; adults = booking.NumberOfAdults ?? 0; kids = booking.NumberOfChildren ?? 0; infants = booking.NumberOfInfants ?? 0; booking.NumberOfAdults = adults; booking.NumberOfChildren = kids; booking.NumberOfInfants = infants; booking.CustomerID = theCustomer.CustomerID; booking.BookingTypeID = 1; //always a property booking booking.NumberOfGuests = adults + kids + infants; booking.TotalNumberOfMinors = kids + infants; booking.NumberOfNights = GeneralStaticHelperMethods.CalculateNoofNights(booking.StartDate, booking.EndDate); try { var exchangeRateFromDB = new CurrencyExchange(); var baseCurrency = ""; var newCurrency = ""; booking.NumberOfNights = GeneralStaticHelperMethods.CalculateNoofNights(booking.StartDate, booking.EndDate); booking.CalculateBookingPricingForAPropertyBooking(db); booking.CalculateExtrasPriceForAPropertyBooking(property, booking, db); //set this now because need to convert it booking.SetBreakageDepositDueDate(); //1 month before booking.SetBreakageDepositAmount(); //depends on property booking.BookingCurrencyLongName = "G.B. Pounds Sterling"; //NOW CONVERT CURRENCY IF NECESSARY SO OTHER CALCS ARE CORRECT //CHANGE THIS!!! IT'S USING HIDDEN EXTERNAL DEPENDENY booking.BookingCurrencyConversionSymbol = "£"; booking.BookingCurrencyExchangeRate = 1.00M; booking.BookingPreferredCurrency = "GBP"; if (theCustomer.Country.ToLower() != "united kingdom" && ConfigurationManager.AppSettings["defaultCurrency"] == "GBP") { //euro strategy baseCurrency = "GBP"; newCurrency = "EUR"; //set exchange rate booking.BookingCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate; booking.BookingCurrencyLongName = "Euros"; booking.BookingCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol; booking.BookingCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate; booking.BookingPreferredCurrency = "EUR"; try { booking.BookingPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.BookingPrice); booking.BookingCurrencyConversionPrice = booking.BookingPrice; booking.TowelsPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.TowelsPrice); booking.MidVactionCleaningPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.MidVactionCleaningPrice); booking.SwimmingPoolHeatingPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.SwimmingPoolHeatingPrice); booking.ExtraLininSetPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.ExtraLininSetPrice); booking.BreakageDeposit = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.BreakageDeposit); booking.CleaningPostVisitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.CleaningPostVisitPrice); booking.HeatingPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.HeatingPrice); } catch (Exception) { throw; } } //ALL BOOKINGS FOR US SYSTEM IN USD else if (ConfigurationManager.AppSettings["defaultCurrency"] == "USD") { baseCurrency = "GBP"; newCurrency = "USD"; exchangeRateFromDB = db.CurrencyExchanges.First(x => x.CurrencyExchangeName == "GBP-USD"); //set exchange rate and currencies booking.BookingCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate; booking.BookingCurrencyLongName = "U.S. Dollars"; booking.BookingCurrencyConversionSymbol = exchangeRateFromDB.CurrencyExchangeSymbol; booking.BookingCurrencyExchangeRate = exchangeRateFromDB.CurrencyExchangeRate; booking.BookingPreferredCurrency = "USD"; } //do all cuurency conversions if not a UK booking if (theCustomer.Country.ToLower() != "united kingdom" || !ConfigurationManager.AppSettings["defaultCurrency"].Equals("GBP")) { try { booking.BookingPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.BookingPrice); booking.BookingCurrencyConversionPrice = booking.BookingPrice; booking.TowelsPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.TowelsPrice); booking.MidVactionCleaningPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.MidVactionCleaningPrice); booking.SwimmingPoolHeatingPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.SwimmingPoolHeatingPrice); booking.ExtraLininSetPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.ExtraLininSetPrice); booking.BreakageDeposit = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.BreakageDeposit); booking.CleaningPostVisitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.CleaningPostVisitPrice); booking.HeatingPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.HeatingPrice); booking.HeatingUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.HeatingUnitPrice); booking.CleaningPostVisitUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.CleaningPostVisitUnitPrice); booking.ExtraLininSetUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.ExtraLininSetUnitPrice); booking.MidVactionCleaningUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.MidVactionCleaningUnitPrice); booking.SwimmingPoolHeatingUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.SwimmingPoolHeatingUnitPrice); booking.TowelsUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.TowelsUnitPrice); booking.FirewoodUnitPrice = cc.ConvertCurrency(baseCurrency, newCurrency, (decimal)booking.FirewoodUnitPrice); } catch (Exception) { throw; } } } catch (Exception ex) { /*Response.Redirect("http://" + Request.Url.Authority + "/Error/PropertyErrorSelection");*/ //return RedirectToAction("PropertyErrorSelection", "Error", new { propID = CartBooking.PropertyID }); } //CURRENCY MUST BE CONVERTED BEFORE THESE METHODS ARE CALLED //call meths to set dates booking.SetInitalDepositDate(); booking.SetInitialDepositAmount(); booking.SetRentalBalanceDueDate(); //1 month before booking.CalculateFinalRentalPaymentAmount(); //extrasSummedPrice + price - deposit booking.SetBreakageDepositRemittanceDate(); booking.SetBreakageDepositRemittanceAmount();//1 month after trip end? //booking.SetFinalRentalPayment(); //price - deposit booking.SetHomeownerAndPRCComissionAmount(db); booking.CreationDate = DateTime.Now; booking.Cancelled = false; booking.Confirmed = false; //if they pay by paypal later, we can update; var refGenService = new ReferenceGenerationService(); booking.BookingPRCReference = refGenService.GenerateBookingReference(booking, property); //if (ModelState.IsValid) //{ db.Bookings.Add(booking); if (db.SaveChanges() > 0) { if (booking.BookingID > 0) { booking.BookingPRCReference = refGenService.GenerateBookingReference(booking, property); db.Entry(booking).State = EntityState.Modified; db.SaveChanges(); } } return(booking); }
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; } }