Ejemplo n.º 1
0
        public ActionResult SubmitSearch(FlightIndexVM flightsData)
        {
            // convert origin and destination cities to codes
            DataLayer dl = new DataLayer();

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

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

            // create the api object
            FlightSearch flightSearch = new FlightSearch();

            flightSearch.FillData(flightsData.originCode, flightsData.desCode, flightsData.sdate, flightsData.edate, flightsData.originCountry, flightsData.originCity, flightsData.desCountry, flightsData.desCity);

            // if no results were found (400: bad request)
            if (flightSearch.GetResponse() != "")
            {
                FlightSearchResultsVM newObj = new FlightSearchResultsVM()
                {
                    destinationCity    = flightSearch.GetDestinationCity(),
                    destinationCountry = flightSearch.GetDestinationCountry(),
                    originCity         = flightSearch.GetOriginCity(),
                    originCountry      = flightSearch.GetOriginCountry(),
                    departureDate      = flightsData.sdate,
                    returnDate         = flightsData.edate,
                };
                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(),
                latitude       = latitude,
                longitude      = longitude,
            };

            return(View("SearchResults", flightSearchResultsVM));
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------------------------------------------



        //                                               View flight
        //-----------------------------------------------------------------------------------------------------------------------------
        private FlightInfoVM LoadDataFor_ViewFlightInfo(FlightSearchResultsVM flightSearchResultsVM)
        {
            int          index        = flightSearchResultsVM.selectedFlight;
            FlightInfoVM flightInfoVM = new FlightInfoVM()
            {
                airline             = flightSearchResultsVM.airline[index],
                departureDate       = flightSearchResultsVM.departureDate,
                seatsRemaining      = flightSearchResultsVM.seatsRemaining[index],
                returnDate          = flightSearchResultsVM.returnDate,
                destinationCity     = flightSearchResultsVM.destinationCity,
                destinationCodeCity = flightSearchResultsVM.destinationCodeCity,
                destinationCountry  = flightSearchResultsVM.destinationCountry,
                inbound             = flightSearchResultsVM.inbound[index],
                originCity          = flightSearchResultsVM.originCity,
                originCodeCity      = flightSearchResultsVM.originCodeCity,
                originCountry       = flightSearchResultsVM.originCountry,
                outbound            = flightSearchResultsVM.outbound[index],
                price = flightSearchResultsVM.price[index].ToString(),
                timeDuration_outbound = ToolsClass.TimeDifferences(flightSearchResultsVM.outbound[index].DepartureTime, flightSearchResultsVM.outbound[index].ArrivalTime),
                timeDuration_inbound  = ToolsClass.TimeDifferences(flightSearchResultsVM.inbound[index].DepartureTime, flightSearchResultsVM.inbound[index].ArrivalTime),
            };

            return(flightInfoVM);
        }
Ejemplo n.º 3
0
        // ----------------------------- this view is only for static run (TEMP VIEW)
        public ActionResult ViewFlightInfo()
        {
            List <string> airlineLST = new List <string>();

            airlineLST.Add("LY");
            List <double> priceLST = new List <double>();

            priceLST.Add(2565.42);
            List <string> seatsRemainingLST = new List <string>();

            seatsRemainingLST.Add("9");

            List <FlightRouteVM> outboundLST = new List <FlightRouteVM>();

            outboundLST.Add(new FlightRouteVM()
            {
                ArrivalAirportCode   = "LHR",
                ArrivalDate          = "15.06.2018",
                ArrivalTime          = "13:35",
                DepartureAirportCode = "TLV",
                DepartureDate        = "15.06.2018",
                DepartureTime        = "10:10",
                FlightNumber         = "315",
                ArrivalAirportName   = "London Heathrow Airport",
                DepartureAirportName = "Ben Gurion Airport",
                DepartureDay         = ToolsClass.DayOfTheWeek("15.06.2018"),
                ArrivalDay           = ToolsClass.DayOfTheWeek("15.06.2018"),
            });

            List <FlightRouteVM> inboundLST = new List <FlightRouteVM>();

            inboundLST.Add(new FlightRouteVM()
            {
                ArrivalAirportCode   = "TLV",
                ArrivalDate          = "25.06.2018",
                ArrivalTime          = "15:00",
                DepartureAirportCode = "LHR",
                DepartureDate        = "25.06.2018",
                DepartureTime        = "08:10",
                FlightNumber         = "165",
                ArrivalAirportName   = "Ben Gurion Airport",
                DepartureAirportName = "London Heathrow Airport",
                DepartureDay         = ToolsClass.DayOfTheWeek("25.06.2018"),
                ArrivalDay           = ToolsClass.DayOfTheWeek("25.06.2018"),
            });

            FlightSearchResultsVM flightSearchResultsVM = new FlightSearchResultsVM()
            {
                selectedFlight      = 0,
                departureDate       = "15.06.2018",
                returnDate          = "25.06.2018",
                originCountry       = "UK",
                originCity          = "London",
                destinationCountry  = "Israel",
                destinationCity     = "Tel Aviv",
                originCodeCity      = "LON",
                destinationCodeCity = "TLV",
                outbound            = outboundLST,
                inbound             = inboundLST,
                airline             = airlineLST,
                price          = priceLST,
                seatsRemaining = seatsRemainingLST
            };

            return(View(LoadDataFor_ViewFlightInfo(flightSearchResultsVM)));
        }
Ejemplo n.º 4
0
 public ActionResult ViewFlightInfo(FlightSearchResultsVM flightSearchResultsVM) => View(LoadDataFor_ViewFlightInfo(flightSearchResultsVM));
Ejemplo n.º 5
0
        // Temp ActionResult
        public ActionResult SearchResults()
        {
            List <string> airline = new List <string>();

            airline.Add("U2");
            airline.Add("IZ");
            airline.Add("BS");

            List <FlightRouteVM> inbound = new List <FlightRouteVM>();
            FlightRouteVM        fr      = new FlightRouteVM()
            {
                ArrivalAirportCode   = "TLV",
                ArrivalAirportName   = "Ben Gurion Airport",
                ArrivalDate          = "10.09.2018",
                ArrivalDay           = "Monday",
                ArrivalTime          = "14:15",
                DepartureAirportCode = "LTN",
                DepartureAirportName = "Luton Airport",
                DepartureDate        = "10.09.2018",
                DepartureDay         = "Monday",
                DepartureTime        = "07:15",
                FlightNumber         = "2083",
                TimeDuration         = ToolsClass.TimeDifferences("07:15", "14:15"),
            };

            inbound.Add(fr);
            inbound.Add(fr);
            inbound.Add(fr);

            List <FlightRouteVM> outbound = new List <FlightRouteVM>();
            FlightRouteVM        fr2      = new FlightRouteVM()
            {
                ArrivalAirportCode   = "LTN",
                ArrivalAirportName   = "Luton Airport",
                ArrivalDate          = "03.09.2018",
                ArrivalDay           = "Monday",
                ArrivalTime          = "23:50",
                DepartureAirportCode = "TLV",
                DepartureAirportName = "Ben Gurion Airport",
                DepartureDate        = "03.09.2018",
                DepartureDay         = "Monday",
                DepartureTime        = "20:25",
                FlightNumber         = "2086",
                TimeDuration         = ToolsClass.TimeDifferences("20:25", "23:50"),
            };

            outbound.Add(fr2);
            outbound.Add(fr2);
            outbound.Add(fr2);

            List <double> price = new List <double>();

            price.Add(404.35);
            price.Add(468.94);
            price.Add(1203.94);

            List <string> seatsRemaining = new List <string>();

            seatsRemaining.Add("9");
            seatsRemaining.Add("9");
            seatsRemaining.Add("9");

            FlightSearchResultsVM objToPass = new FlightSearchResultsVM()
            {
                departureDate       = "03.09.2018",
                destinationCity     = "London",
                destinationCodeCity = "LON",
                destinationCountry  = "Uk",
                inbound             = inbound,
                originCity          = "Tel aviv",
                originCodeCity      = "TLV",
                originCountry       = "Israel",
                outbound            = outbound,
                price          = price,
                returnDate     = "10.09.2018",
                seatsRemaining = seatsRemaining,
                airline        = airline,
                latitude       = 51.5,
                longitude      = -0.1667,
            };

            return(View(objToPass));
        }
Ejemplo n.º 6
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));
        }