Example #1
0
        public int CurrencyExchange()
        {
            var cc = new CurrencyConverterController();


            Booking book = new Booking();


            book.BookingPreferredCurrency        = "GBP";
            book.BookingCurrencyConversionPrice  = 1M;
            book.BookingCurrencyConversionSymbol = "£";
            book.BookingCurrencyExchangeRate     = 1M;

            var result = cc.ConvertCurrency("GBP", "EUR", 1.00M);


            return(0);
        }
        public ActionResult SearchProperties(FormCollection formCollection, int page = 1, string propertyResultsSort = "", int propertyResultsAmount = 25)
        {

            ViewBag.IdentifyPage = "Property Search";

            Session["CurrentSearchResultsAmount"] = propertyResultsAmount;
            Session["CurrentSearchResultsSort"] = propertyResultsSort;

            //stick values into viewback for DDL update
            ViewBag.propertyResultsSort = propertyResultsSort;
            ViewBag.propertyResultsAmount = propertyResultsAmount;

            //retrive values from post
            //based on whether there are dates create either a booking search or property search
            //create new object and populate - then run dynamic instance query on that object

            int propertyTypeID = 0;
            int vacationTypeID = 0;
            string poolType = null;
            int maxSleeps = 0;
            int noOfAdults = 0;
            int noOfChildren = 0;
            int noOfInfants = 0;

            DateTime? startDate = null;
            DateTime? endDate = null; ;

            try
            {
                //parse dates
                if (formCollection["StartDate"] != "" && formCollection["StartDate"] != null)
                {
                    startDate = DateTime.ParseExact(formCollection["StartDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                if (formCollection["EndDate"] != "" && formCollection["EndDate"] != null)
                {
                    endDate = DateTime.ParseExact(formCollection["EndDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                if (formCollection["StartDate1"] != "" && formCollection["StartDate1"] != null)
                {
                    startDate = DateTime.ParseExact(formCollection["StartDate1"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                if (formCollection["EndDate1"] != "" && formCollection["EndDate1"] != null)
                {
                    endDate = DateTime.ParseExact(formCollection["EndDate1"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }

                //parse property Type ID
                if (Int32.Parse(formCollection["PropertyType"]) != 0)
                {
                    propertyTypeID = Int32.Parse(formCollection["PropertyType"]);
                }
                //parse region type
                if (Int32.Parse(formCollection["RegionType"]) != 0)
                {
                    vacationTypeID = Int32.Parse(formCollection["RegionType"]);
                }
                //parse poolType
                if (formCollection["PoolType"] != "" && formCollection["PoolType"] != null && poolType != "0")
                {
                    poolType = formCollection["PoolType"];
                }
                //parse max sleeps
                if (Int32.Parse(formCollection["MaxSleeps"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["MaxSleeps"]);
                }
                //parse no of adults
                if (Int32.Parse(formCollection["NoOfAdults"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["NoOfAdults"]);
                }
                //parse no of children
                if (Int32.Parse(formCollection["NoOfChildren"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["NoOfChildren"]);
                }
                //parse no of infants
                if (Int32.Parse(formCollection["NoOfInfants"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["NoOfInfants"]);
                }
                //parse price range 

                //jsut to account for if we haven't be passed a price
                String[] splitPrice = "1-5000".Split('-');

                if (formCollection["PriceRange"] != "" && formCollection["PriceRange"] != null)
                {
                    splitPrice = null;
                    splitPrice = formCollection["PriceRange"].Split('-');
                }

                LinkedList<decimal> thePrices = new LinkedList<decimal>();



                foreach (var thePrice in splitPrice)
                {
                    int TryParseResult = 0;
                    //try parse to check it's a number
                    Int32.TryParse(thePrice.Trim().Replace("£", "").Replace("$", "").ToString(), out TryParseResult);


                    var cash = (decimal)TryParseResult;
                    if (TryParseResult != 0)
                    {
                        //IF SYSTEM IS US DOLLARS, NEED TO CONVERT THE NUMBER INTO POUNDS
                        if ((string)ConfigurationManager.AppSettings["defaultCurrency"] != "GBP")
                        {
                           var cc = new CurrencyConverterController();
                            cash = cc.ConvertCurrency((string)ConfigurationManager.AppSettings["defaultCurrency"], "GBP", (decimal)cash);
                        }
                            thePrices.AddLast(cash);
                    }
                }
                //end parse price range


                PriceRange customerQueryPriceRange = null;

                if (thePrices.Count > 0)
                {
                    customerQueryPriceRange = new PriceRange(thePrices.Min(), thePrices.Max());
                }
                else //pass the max range ever
                {
                    customerQueryPriceRange = new PriceRange(0, 100000);
                }

                //END FORM PARSE

                //Now test if there are dates - if yes - create a booking query. If no, create a property query


                //create property query
                PropertySearch newSearch = new PropertySearch()
                {
                    MaxSleeps = maxSleeps,
                    NoOfAdults = noOfAdults,
                    NoOfChildren = noOfChildren,
                    NoOfInfants = noOfInfants,
                    PoolType = poolType,
                    PropertyTypeID = propertyTypeID,
                    TheSearchPriceRange = customerQueryPriceRange,
                    VacationTypeID = vacationTypeID
                };

                //do the search

                var searchResults = newSearch.SearchForMatchingProperties();
                //if there are dates, pass the search results into the BookingSearch

                if (startDate.HasValue && endDate.HasValue)
                {
                    //create booking query                                                                        
                    searchResults = SearchBookingResultsAndReturnPropetiesWithoutAnOverlappingBooking(searchResults, (DateTime)startDate, (DateTime)endDate);


                }



                //for each sort / pager
                Session["LastSearchResults"] = PagedList.PagedListExtensions.ToPagedList(searchResults, page, searchResults.Count);
                //for fresh canvas for 'amount' sort
                Session["InitalCustomerSearchResults"] = PagedList.PagedListExtensions.ToPagedList(searchResults, page, searchResults.Count);
                //which page are we on of the results
                Session["LastPropertyPagerPage"] = page;


                ViewBag.MatchingProperties = PagedList.PagedListExtensions.ToPagedList(searchResults, page, propertyResultsAmount);

                Session["currentPagedPropertySearch"] = PagedList.PagedListExtensions.ToPagedList(searchResults, page, 500000);


                //store the last results set in the viewbag, so we can page it if necessary






            }

            catch (Exception ex)
            {
                Response.Write("Something is wrong in the SearchProperties in the Home Controller when trying to assing the variables " +
                             "from the POST from the search form");
            }








            //return results
            //create a new enquiry
            ViewBag.Keywords = "villa rental portugal, portugal silver coast, portugal cheap holidays, cheap holidays to portugal,silver coast portugal, portugal rental cottages, cheap all inclusive holidays to portugal";
            ViewBag.Title = "Book your villa in Obidos, Nazare, Foz do Arelho or A-dos-Negros for a seaside holiday or rural townhouse with swimming pool and Internet. All types of villa, apartment are catered for in regions like Foz do Arelho, Obidos, Alfeizerao - Sao Martinho and Reguengo Grande. Stay in the lovely Salir do Porto and visit the Mafra Palace & Obidos during your vacation. With Portugal Rental Cottages, you can be up directly from the airport with our rental extras. While you stay, go on wine tasting tours to the beautiful Sanguinhal Estate and get picked up from the airport with our airport to villa transfer and return.";
            return View();
        }
        public int CurrencyExchange()
        {
            var cc = new CurrencyConverterController();


            Booking book = new Booking();


            book.BookingPreferredCurrency = "GBP";
            book.BookingCurrencyConversionPrice = 1M;
            book.BookingCurrencyConversionSymbol = "£";
            book.BookingCurrencyExchangeRate = 1M;

            var result = cc.ConvertCurrency("GBP", "EUR", 1.00M);


            return 0;
        }
Example #4
0
        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);
        }
Example #5
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 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 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 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;
        }
Example #10
0
        public ActionResult SearchProperties(FormCollection formCollection, int page = 1, string propertyResultsSort = "", int propertyResultsAmount = 25)
        {
            ViewBag.IdentifyPage = "Property Search";

            Session["CurrentSearchResultsAmount"] = propertyResultsAmount;
            Session["CurrentSearchResultsSort"]   = propertyResultsSort;

            //stick values into viewback for DDL update
            ViewBag.propertyResultsSort   = propertyResultsSort;
            ViewBag.propertyResultsAmount = propertyResultsAmount;

            //retrive values from post
            //based on whether there are dates create either a booking search or property search
            //create new object and populate - then run dynamic instance query on that object

            int    propertyTypeID = 0;
            int    vacationTypeID = 0;
            string poolType       = null;
            int    maxSleeps      = 0;
            int    noOfAdults     = 0;
            int    noOfChildren   = 0;
            int    noOfInfants    = 0;

            DateTime?startDate = null;
            DateTime?endDate   = null;;

            try
            {
                //parse dates
                if (formCollection["StartDate"] != "" && formCollection["StartDate"] != null)
                {
                    startDate = DateTime.ParseExact(formCollection["StartDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                if (formCollection["EndDate"] != "" && formCollection["EndDate"] != null)
                {
                    endDate = DateTime.ParseExact(formCollection["EndDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                if (formCollection["StartDate1"] != "" && formCollection["StartDate1"] != null)
                {
                    startDate = DateTime.ParseExact(formCollection["StartDate1"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                if (formCollection["EndDate1"] != "" && formCollection["EndDate1"] != null)
                {
                    endDate = DateTime.ParseExact(formCollection["EndDate1"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }

                //parse property Type ID
                if (Int32.Parse(formCollection["PropertyType"]) != 0)
                {
                    propertyTypeID = Int32.Parse(formCollection["PropertyType"]);
                }
                //parse region type
                if (Int32.Parse(formCollection["RegionType"]) != 0)
                {
                    vacationTypeID = Int32.Parse(formCollection["RegionType"]);
                }
                //parse poolType
                if (formCollection["PoolType"] != "" && formCollection["PoolType"] != null && poolType != "0")
                {
                    poolType = formCollection["PoolType"];
                }
                //parse max sleeps
                if (Int32.Parse(formCollection["MaxSleeps"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["MaxSleeps"]);
                }
                //parse no of adults
                if (Int32.Parse(formCollection["NoOfAdults"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["NoOfAdults"]);
                }
                //parse no of children
                if (Int32.Parse(formCollection["NoOfChildren"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["NoOfChildren"]);
                }
                //parse no of infants
                if (Int32.Parse(formCollection["NoOfInfants"]) != 0)
                {
                    maxSleeps = Int32.Parse(formCollection["NoOfInfants"]);
                }
                //parse price range

                //jsut to account for if we haven't be passed a price
                String[] splitPrice = "1-5000".Split('-');

                if (formCollection["PriceRange"] != "" && formCollection["PriceRange"] != null)
                {
                    splitPrice = null;
                    splitPrice = formCollection["PriceRange"].Split('-');
                }

                LinkedList <decimal> thePrices = new LinkedList <decimal>();



                foreach (var thePrice in splitPrice)
                {
                    int TryParseResult = 0;
                    //try parse to check it's a number
                    Int32.TryParse(thePrice.Trim().Replace("£", "").Replace("$", "").ToString(), out TryParseResult);


                    var cash = (decimal)TryParseResult;
                    if (TryParseResult != 0)
                    {
                        //IF SYSTEM IS US DOLLARS, NEED TO CONVERT THE NUMBER INTO POUNDS
                        if ((string)ConfigurationManager.AppSettings["defaultCurrency"] != "GBP")
                        {
                            var cc = new CurrencyConverterController();
                            cash = cc.ConvertCurrency((string)ConfigurationManager.AppSettings["defaultCurrency"], "GBP", (decimal)cash);
                        }
                        thePrices.AddLast(cash);
                    }
                }
                //end parse price range


                PriceRange customerQueryPriceRange = null;

                if (thePrices.Count > 0)
                {
                    customerQueryPriceRange = new PriceRange(thePrices.Min(), thePrices.Max());
                }
                else //pass the max range ever
                {
                    customerQueryPriceRange = new PriceRange(0, 100000);
                }

                //END FORM PARSE

                //Now test if there are dates - if yes - create a booking query. If no, create a property query


                //create property query
                PropertySearch newSearch = new PropertySearch()
                {
                    MaxSleeps           = maxSleeps,
                    NoOfAdults          = noOfAdults,
                    NoOfChildren        = noOfChildren,
                    NoOfInfants         = noOfInfants,
                    PoolType            = poolType,
                    PropertyTypeID      = propertyTypeID,
                    TheSearchPriceRange = customerQueryPriceRange,
                    VacationTypeID      = vacationTypeID
                };

                //do the search

                var searchResults = newSearch.SearchForMatchingProperties();
                //if there are dates, pass the search results into the BookingSearch

                if (startDate.HasValue && endDate.HasValue)
                {
                    //create booking query
                    searchResults = SearchBookingResultsAndReturnPropetiesWithoutAnOverlappingBooking(searchResults, (DateTime)startDate, (DateTime)endDate);
                }



                //for each sort / pager
                Session["LastSearchResults"] = PagedList.PagedListExtensions.ToPagedList(searchResults, page, searchResults.Count);
                //for fresh canvas for 'amount' sort
                Session["InitalCustomerSearchResults"] = PagedList.PagedListExtensions.ToPagedList(searchResults, page, searchResults.Count);
                //which page are we on of the results
                Session["LastPropertyPagerPage"] = page;


                ViewBag.MatchingProperties = PagedList.PagedListExtensions.ToPagedList(searchResults, page, propertyResultsAmount);

                Session["currentPagedPropertySearch"] = PagedList.PagedListExtensions.ToPagedList(searchResults, page, 500000);


                //store the last results set in the viewbag, so we can page it if necessary
            }

            catch (Exception ex)
            {
                Response.Write("Something is wrong in the SearchProperties in the Home Controller when trying to assing the variables " +
                               "from the POST from the search form");
            }



            //return results
            //create a new enquiry
            ViewBag.Keywords = "villa rental portugal, portugal silver coast, portugal cheap holidays, cheap holidays to portugal,silver coast portugal, portugal rental cottages, cheap all inclusive holidays to portugal";
            ViewBag.Title    = "Book your villa in Obidos, Nazare, Foz do Arelho or A-dos-Negros for a seaside holiday or rural townhouse with swimming pool and Internet. All types of villa, apartment are catered for in regions like Foz do Arelho, Obidos, Alfeizerao - Sao Martinho and Reguengo Grande. Stay in the lovely Salir do Porto and visit the Mafra Palace & Obidos during your vacation. With Portugal Rental Cottages, you can be up directly from the airport with our rental extras. While you stay, go on wine tasting tours to the beautiful Sanguinhal Estate and get picked up from the airport with our airport to villa transfer and return.";
            return(View());
        }