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();
        }
Пример #2
0
        public ActionResult SearchProperties(FormCollection formCollection, int page = 1)
        {
            //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["bookingModalStartDatePicker"] != "" && formCollection["bookingModalStartDatePicker"] != null)
                {
                    startDate = DateTime.Parse(formCollection["bookingModalStartDatePicker"]);
                }
                if (formCollection["EndDate"] != "" && formCollection["EndDate"] != null)
                {
                    endDate = DateTime.Parse(formCollection["EndDate"]);
                }
                //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
                 String[] splitPrice = "1-1000".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("£", "").ToString(), out TryParseResult);

                    if (TryParseResult != 0)
                    {
                    thePrices.AddLast(Decimal.Parse(thePrice.Trim().Replace("£", "")));
                    }
                }
                //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
                if (startDate.HasValue && endDate.HasValue)
                {
                    //create booking query

                }
                else
                {

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

                    //store the last results set in the viewbag, so we can page it if necessary
                    Session["LastSearchResults"] = PagedList.PagedListExtensions.ToPagedList(newSearch.SearchForMatchingProperties(), page, 2000);

                    ViewBag.MatchingProperties = PagedList.PagedListExtensions.ToPagedList(newSearch.SearchForMatchingProperties(), page, 25);

                }

            }

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

            foreach (string _formData in formCollection)
            {
                ViewData[_formData] = formCollection[_formData];
            }

            //return results
            //create a new enquiry

            return View();
        }
        //nothing passed - run a search with default values (will bring back all properties) - no PriceRange object
        public ActionResult SearchProperties(string PropertyType = "", string VacationType = "", int page = 1, string propertyResultsSort = "", int propertyResultsAmount = 25)
        {
            ViewBag.IdentifyPage = "Property Search";

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

            ViewBag.propertyResultsSort = propertyResultsSort;
            ViewBag.propertyResultsAmount = propertyResultsAmount;


            PropertySearch newSearch = new PropertySearch()
            {
                MaxSleeps = 0,
                NoOfAdults = 0,
                NoOfChildren = 0,
                NoOfInfants = 0,
                PoolType = null,
                PropertyTypeID = 0,
                VacationTypeID = 0
            };

            if (VacationType != "")
            {
                newSearch.VacationTypeID = Convert.ToInt16(VacationType);
            }
            if (PropertyType != "")
            {
                newSearch.PropertyTypeID = Convert.ToInt16(PropertyType);
            }

            //run the search - then need to display it in the view
            var MatchingProperties = newSearch.SearchForMatchingProperties();

            //before limiting results
            Session["LastSearchResults"] = MatchingProperties;

            //paging here - then pass to viewbag                                       
            Session["LastPropertyPagerPage"] = page;

            //after sort
            Session["currentPagedPropertySearch"] = MatchingProperties;

            ViewBag.MatchingProperties = PagedList.PagedListExtensions.ToPagedList(MatchingProperties, page, propertyResultsAmount);
            Session["currentPagedPropertySearch"] = PagedList.PagedListExtensions.ToPagedList(MatchingProperties, page, 50000000);

            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.";
            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";
            return View();
        }
Пример #4
0
        //////////////////////////////////////
        //Begin main search overloaded views
        ////////////////////////////////////
        ////////////////////////////////////
        //nothing passed - run a search with default values (will bring back all properties) - no PriceRange object
        public ActionResult SearchProperties(int page = 1)
        {
            PropertySearch newSearch = new PropertySearch()
            {
                MaxSleeps = 0,
                NoOfAdults = 0,
                NoOfChildren = 0,
                NoOfInfants = 0,
                PoolType = null,
                PropertyTypeID = 0,
                VacationTypeID = 0
            };

            //run the search - then need to display it in the view
            var MatchingProperties = newSearch.SearchForMatchingProperties();

            //paging here - then pass to viewbag
            ViewBag.MatchingProperties =  PagedList.PagedListExtensions.ToPagedList(MatchingProperties, page, 25);

            return View();
        }