Ejemplo n.º 1
0
        public ActionResult SubmitSearch(PackageIndexVM packageData)
        {
            DataLayer dl = new DataLayer();

            packageData.desCode = (from u in dl.locations
                                   where  u.city.ToLower() == packageData.desCity.ToLower()
                                   select u.code).ToList <string>().FirstOrDefault();

            // HOTELS:
            HotelSearch hs = new HotelSearch();

            hs.FillData(packageData.desCode, packageData.sdate, packageData.edate);
            hs.BuildURL();
            string json = hs.GetJson();

            dynamic         results = JsonConvert.DeserializeObject(json); // convert incoming data to json form
            SearchResultsVM sr      = new SearchResultsVM();

            sr.hotelSearchResultsVM = new List <HotelSearchResultsVM>();
            sr.startdDate           = packageData.sdate;
            sr.endDate = packageData.edate;
            sr.nights  = ToolsClass.getNumOfNights(ToolsClass.getDate(sr.startdDate), ToolsClass.getDate(sr.endDate));

            for (int i = 0; i < results.results.Count; ++i)
            {
                ImageSearch image = new ImageSearch();

                try
                {
                    image.SetHotelName(results.results[i].property_name.ToString()); // initialize object by GoogleAPI
                }
                catch (Exception)
                {
                    Thread.Sleep(1000);
                    return(SubmitSearch(packageData));
                }

                int newRating = -1; // initialize to -1
                try
                {
                    if (results.results[i].awards[0].rating != null)
                    {
                        newRating = results.results[i].awards[0].rating;
                    }
                }
                catch (Exception) { }
                if (newRating == -1)
                {
                    newRating = GenerateRating();
                }

                HotelSearchResultsVM temp = new HotelSearchResultsVM()
                {
                    originalLink     = hs.GetSearchURL(), // to fix the api room problem
                    hotelLink        = results.results[i]._links.more_rooms_at_this_hotel.href,
                    hotelName        = results.results[i].property_name,
                    hotelDescription = results.results[i].marketing_text,
                    rating           = newRating,
                    hotelPrice       = results.results[i].total_price.amount,
                    hotelImage       = image.GetImage() // image is an object
                };
                sr.hotelSearchResultsVM.Add(temp);
            }

            // FLIGHTS:
            FlightSearch flightSearch = new FlightSearch();

            flightSearch.FillData("TLV", packageData.desCode, packageData.sdate, packageData.edate, "Israel", "Tel Aviv", packageData.desCountry, packageData.desCity);

            // if no results were found (400: bad request)
            if (flightSearch.GetResponse() != "")
            {
                List <PackageDetails> packages = new List <PackageDetails>();
                packages.Add(new PackageDetails()
                {
                    flight = new FlightInfoVM()
                    {
                        departureDate      = packageData.sdate,
                        returnDate         = packageData.edate,
                        destinationCity    = packageData.desCity,
                        destinationCountry = packageData.desCountry,
                        originCity         = "Tel Aviv",
                        originCountry      = "Israel",
                    }
                });

                PackageDetailsVM newObj = new PackageDetailsVM()
                {
                    composition = packageData.composition,
                    packages    = packages,
                };
                return(View("SearchResults", newObj));
            }

            // for the google map
            string[] loc       = flightSearch.GetLocation().Split(',');
            double   latitude  = Double.Parse(loc[0]);
            double   longitude = Double.Parse(loc[1]);

            // create object to pass to the view
            FlightSearchResultsVM flightSearchResultsVM = new FlightSearchResultsVM()
            {
                departureDate       = flightSearch.GetDepartureDate(),
                destinationCity     = flightSearch.GetDestinationCity(),
                destinationCodeCity = flightSearch.GetDestinationCodeCity(),
                destinationCountry  = flightSearch.GetDestinationCountry(),
                inbound             = flightSearch.GetInbound(),
                originCity          = flightSearch.GetOriginCity(),
                originCodeCity      = flightSearch.GetOriginCodeCity(),
                originCountry       = flightSearch.GetOriginCountry(),
                outbound            = flightSearch.GetOutbound(),
                price          = flightSearch.GetPrice(),
                returnDate     = flightSearch.GetReturnDate(),
                seatsRemaining = flightSearch.GetSeatsRemaining(),
                airline        = flightSearch.GetAirline(),
            };

            PackageDetailsVM pdvm = new PackageDetailsVM();

            pdvm.composition = packageData.composition;
            var rand = new Random();

            foreach (HotelSearchResultsVM h in sr.hotelSearchResultsVM)
            {
                PackageDetails pd = new PackageDetails();
                pd.hotel = h;

                int          n = rand.Next(flightSearchResultsVM.airline.Count());
                FlightInfoVM f = new FlightInfoVM()
                {
                    airline             = flightSearchResultsVM.airline[n],
                    inbound             = flightSearchResultsVM.inbound[n],
                    outbound            = flightSearchResultsVM.outbound[n],
                    departureDate       = flightSearchResultsVM.departureDate,
                    returnDate          = flightSearchResultsVM.returnDate,
                    originCountry       = flightSearchResultsVM.originCountry,
                    originCity          = flightSearchResultsVM.originCity,
                    destinationCountry  = flightSearchResultsVM.destinationCountry,
                    destinationCity     = flightSearchResultsVM.destinationCity,
                    originCodeCity      = flightSearchResultsVM.originCodeCity,
                    destinationCodeCity = flightSearchResultsVM.destinationCodeCity,
                    seatsRemaining      = flightSearchResultsVM.seatsRemaining[n],
                    price = flightSearchResultsVM.price[n].ToString()
                };
                pd.flight = f;

                pd.price = (pd.hotel.hotelPrice + Convert.ToDouble(pd.flight.price)) * Tools.ToolsClass.getPricePercent(pdvm.composition);

                pdvm.packages.Add(pd);
            }

            pdvm.nights = sr.nights;

            pdvm.latitude  = latitude;
            pdvm.longitude = longitude;

            return(View("SearchResults", pdvm));
        }
Ejemplo n.º 2
0
        public ActionResult SubmitSearch(HotelIndexVM hotelsData)
        {
            DataLayer dl = new DataLayer();

            hotelsData.code = (from u in dl.locations
                               where u.city.ToLower() == hotelsData.city.ToLower()
                               select u.code).ToList <string>().FirstOrDefault();

            HotelSearch hs = new HotelSearch();

            hs.FillData(hotelsData.code, hotelsData.sdate, hotelsData.edate);
            hs.BuildURL();
            string json = hs.GetJson();

            dynamic         results = JsonConvert.DeserializeObject(json); // convert incoming data to json form
            SearchResultsVM sr      = new SearchResultsVM();

            sr.hotelSearchResultsVM = new List <HotelSearchResultsVM>();
            sr.startdDate           = hotelsData.sdate;
            sr.endDate      = hotelsData.edate;
            sr.originalLink = hs.GetSearchURL(); // to fix the api room problem
            sr.destination  = hotelsData.city + ", " + hotelsData.country;

            if (results.results.Count != 0)
            { // for the google map
                string   realCode = hs.GetLocation(hotelsData.code, "firstStage");
                string[] loc      = hs.GetLocation(realCode, "secondStage").Split(',');
                sr.latitude  = Double.Parse(loc[0]);
                sr.longitude = Double.Parse(loc[1]);
            }

            sr.nights = ToolsClass.getNumOfNights(ToolsClass.getDate(sr.startdDate), ToolsClass.getDate(sr.endDate));

            for (int i = 0; i < results.results.Count; ++i)
            {
                ImageSearch image = new ImageSearch();

                try
                {
                    image.SetHotelName(results.results[i].property_name.ToString()); // initialize object by GoogleAPI
                }
                catch (Exception)
                {
                    Thread.Sleep(1000);
                    return(SubmitSearch(hotelsData));
                }

                int newRating = -1; // initialize to -1
                try
                {
                    if (results.results[i].awards[0].rating != null)
                    {
                        newRating = results.results[i].awards[0].rating;
                    }
                }
                catch (Exception) { }
                if (newRating == -1)
                {
                    newRating = GenerateRating();
                }

                HotelSearchResultsVM temp = new HotelSearchResultsVM()
                {
                    hotelLink        = results.results[i]._links.more_rooms_at_this_hotel.href,
                    hotelName        = results.results[i].property_name,
                    hotelDescription = results.results[i].marketing_text,
                    rating           = newRating,
                    hotelPrice       = results.results[i].total_price.amount,
                    hotelImage       = image.GetImage() // image is an object
                };
                sr.hotelSearchResultsVM.Add(temp);
            }
            return(View("SearchResults", sr));
        }
Ejemplo n.º 3
0
        //                                               Index page for hotels (include search)
        //-----------------------------------------------------------------------------------------------------------------------------
        public ActionResult Index()
        {
            HotelIndexVM hivm = new HotelIndexVM();
            DataLayer    dl   = new DataLayer();

            List <string> codes = (from u in dl.locations select u.code).ToList <string>();
            var           rand  = new Random();

            while (hivm.hotels.Count < 6)
            {
                string      code = codes.ElementAt(rand.Next(codes.Count()));
                HotelSearch hs   = new HotelSearch();

                hs.FillData(code, "15.07.2018", "18.07.2018");
                hs.BuildURL();
                string json = hs.GetJson();

                dynamic results = JsonConvert.DeserializeObject(json); // convert incoming data to json form
                if (results.results.Count > 0)
                {
                    ImageSearch image = new ImageSearch();

                    try
                    {
                        image.SetHotelName(results.results[0].property_name.ToString()); // initialize object by GoogleAPI
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(1000);
                        return(Index());
                    }

                    int newRating = -1; // initialize to -1
                    try
                    {
                        newRating = results.results[0].awards[0].rating;
                    }
                    catch (Exception) { newRating = GenerateRating(); }
                    if (newRating == -1)
                    {
                        newRating = GenerateRating();
                    }

                    HotelSearchResultsVM temp = new HotelSearchResultsVM()
                    {
                        hotelLink        = results.results[0]._links.more_rooms_at_this_hotel.href,
                        hotelName        = results.results[0].property_name,
                        hotelDescription = results.results[0].marketing_text,
                        rating           = newRating,
                        hotelPrice       = results.results[0].total_price.amount,
                        hotelImage       = image.GetImage() // image is an object
                    };
                    hivm.hotels.Add(temp);
                }
            }
            hivm.countries = (from u in dl.locations
                              select u.country).ToList <string>().GroupBy(p => p)
                             .Select(g => g.First()).OrderBy(q => q)
                             .ToList();

            hivm.cities = (from u in dl.locations
                           where u.country == hivm.countries.FirstOrDefault()
                           select u.city).ToList <string>().GroupBy(p => p)
                          .Select(g => g.First()).OrderBy(q => q)
                          .ToList();
            return(View(hivm));
        }
Ejemplo n.º 4
0
        public ActionResult GetRandomHotelsByJson(List <string> loc)
        {
            HotelIndexVM hivm = new HotelIndexVM();
            DataLayer    dl   = new DataLayer();

            List <Locations> locations = GetLocations(loc);
            var rand = new Random();

            string startDate = "13.08.2018";
            string endDate   = "20.08.2018";

            hivm.nights = ToolsClass.getNumOfNights(ToolsClass.getDate(startDate), ToolsClass.getDate(endDate));

            while (hivm.hotels.Count < 4)
            {
                int         random = rand.Next(0, locations.Count);
                string      code   = locations[random].code;
                HotelSearch hs     = new HotelSearch();


                hs.FillData(code, startDate, endDate);
                hs.BuildURL();
                string json         = hs.GetJson();
                string originalLink = hs.GetSearchURL();

                dynamic results = JsonConvert.DeserializeObject(json); // convert incoming data to json form
                if (results.results.Count > 0)
                {
                    ImageSearch image = new ImageSearch();

                    try
                    {
                        image.SetHotelName(results.results[0].property_name.ToString()); // initialize object by GoogleAPI
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(1000);
                        return(Index());
                    }

                    int newRating = -1; // initialize to -1
                    try
                    {
                        newRating = results.results[0].awards[0].rating;
                    }
                    catch (Exception) { newRating = GenerateRating(); }
                    if (newRating == -1)
                    {
                        newRating = GenerateRating();
                    }

                    HotelSearchResultsVM temp = new HotelSearchResultsVM()
                    {
                        originalLink     = originalLink,
                        startDate        = startDate,
                        endDate          = endDate,
                        location         = locations[random].city + ", " + locations[random].country,
                        hotelLink        = results.results[0]._links.more_rooms_at_this_hotel.href,
                        hotelName        = results.results[0].property_name,
                        hotelDescription = results.results[0].marketing_text,
                        rating           = newRating,
                        hotelPrice       = results.results[0].total_price.amount,
                        hotelImage       = image.GetImage() // image is an object
                    };
                    hivm.hotels.Add(temp);
                    locations.RemoveAt(random);
                }
            }
            return(Json(hivm, JsonRequestBehavior.AllowGet));
        }