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