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 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")); } }