public ActionResult SubmitFlightComposition(FlightInfoVM obj) { string[] temp_composition = obj.composition.Split(','); int size = temp_composition.Length; int[] composition = new int[size]; string[] composition_price = new string[size]; for (int i = 0; i < size; ++i) { composition[i] = int.Parse(temp_composition[i]); } composition_price[0] = (Math.Round(double.Parse(obj.price) * 0.4, 2)).ToString(); composition_price[1] = (Math.Round(double.Parse(obj.price) * 0.6, 2)).ToString(); composition_price[2] = (Math.Round(double.Parse(obj.price) * 1.2, 2)).ToString(); composition_price[3] = (Math.Round(double.Parse(obj.price) * 1, 2)).ToString(); composition_price[4] = (Math.Round(double.Parse(obj.price) * 0.8, 2)).ToString(); FlightCheckoutVM objToPass = new FlightCheckoutVM() { destCountry = obj.destinationCountry, departureFlightNumber = obj.outbound.FlightNumber, returnFlightNumber = obj.inbound.FlightNumber, departureDate = obj.departureDate, returnDate = obj.returnDate, departureLocation = obj.originCity, returnLocation = obj.destinationCity, numberOfTickets = composition[0] + composition[1] + composition[2] + composition[3] + composition[4], babies = composition[0], children = composition[1], youngsters = composition[2], adults = composition[3], pensioners = composition[4], price_babies = composition_price[0], price_children = composition_price[1], price_youngsters = composition_price[2], price_adults = composition_price[3], price_pensioners = composition_price[4], airline = obj.airline, totalFee = obj.totalPrice, }; return(View("FlightCheckout", objToPass)); }
//----------------------------------------------------------------------------------------------------------------------------- // 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); }
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)); }
// ----------------------------- this view is only for static run (TEMP VIEW) public ActionResult ViewPackageInfo() { List <string> amenities = new List <string>(); amenities.Add("Elevators"); amenities.Add("Sauna"); amenities.Add("Room service"); amenities.Add("Internet services"); amenities.Add("220 AC"); amenities.Add("Parking"); amenities.Add("Pets allowed"); amenities.Add("Wireless internet connection in public areas"); amenities.Add("Lounges/bars"); amenities.Add("24-hour front desk"); List <string> contacts = new List <string>(); contacts.Add("PHONE: 49/8161/5320"); contacts.Add("FAX: 49/8161/532100"); contacts.Add("EMAIL: [email protected]"); contacts.Add("URL: www.mercure.com"); List <string> images = new List <string>(); images.Add("https://maps.googleapis.com/maps/api/place/photo?maxwidth=800&photoreference=CmRaAAAAtIARwdNqhiQNC-jj-6upRvxxBXgk5Wdl_t484HkmD_ecnJrvi1wK3l53njD6C-XYc0dUEdEGg_SThMQJs7bZpb-2SpTAIUbRmTPoe2aOnpK7tIeC-oERWKsSjvS3H7eyEhA1a_4sr0mjoc7yFPpqvEFhGhSzrFsXmCqtC_7EZdfsvH1zdCjqEQ&key=AIzaSyCArIw-PoGMwSXFZr08nZT64BPDvix8w98"); images.Add("https://maps.googleapis.com/maps/api/place/photo?maxwidth=800&photoreference=CmRaAAAA9zNoq-JwlWS9MkZCsM0FxyrXoogblHtJtoaPeJRzD2DZVWQS5qrq9vXYY7gCqS-MrEAd389xmp57gKYv7k1KzeqN7pO2Ufc1EUs6IxTX6D2541mMA-N5cAIVxf7ib_nbEhAoYFrmfqLRbhQbzIkNGqh3GhTk2uP9_DRnbDVmt_Nihbz0_ZDbIA&key=AIzaSyCArIw-PoGMwSXFZr08nZT64BPDvix8w98"); List <string> roomType1 = new List <string>(); roomType1.Add("Room type: Unspecified"); roomType1.Add("Bed type: Double"); roomType1.Add("Number of beds: 1"); List <string> roomType2 = new List <string>(); roomType2.Add("Room type: Unspecified"); roomType2.Add("Bed type: Twin"); roomType2.Add("Number of beds: 2"); List <RoomVM> rooms = new List <RoomVM>(); rooms.Add(new RoomVM() { roomDescription = "1 DOUBLE BED NONSMOKING FEEL YOURSELF AT HOME ", roomPrice = 684.27, roomType = roomType1 }); rooms.Add(new RoomVM() { roomDescription = "2 SINGLE BEDS NONSMOKING FEEL YOURSELF AT HOME ", roomPrice = 684.27, roomType = roomType1 }); HotelOrderDetailsVM hotel = new HotelOrderDetailsVM() { address = "ADDRESS: Dr Von Daller Str 1 3, Freising", amenities = amenities, apiKey = "AIzaSyCArIw-PoGMwSXFZr08nZT64BPDvix8w98", contact = contacts, hotelName = "Mercure Muc Freising Airport", image = images, latitude = 48.40068, longitude = 11.75076, rating = "4", room = rooms, reviews = new List <HotelReview>(), customersName = new List <string>(), }; FlightRouteVM inbound = new FlightRouteVM() { ArrivalAirportCode = "TLV", ArrivalAirportName = "Ben Gurion Airport", ArrivalDate = "18.09.2018", ArrivalDay = "Tuesday", ArrivalTime = "03:35", DepartureAirportCode = "MUC", DepartureAirportName = "Munich International Airport", DepartureDate = "17.09.2018", DepartureDay = "Monday", DepartureTime = "23:00", FlightNumber = "680" }; FlightRouteVM outbound = new FlightRouteVM() { ArrivalAirportCode = "MUC", ArrivalAirportName = "Munich International Airport", ArrivalDate = "10.09.2018", ArrivalDay = "Monday", ArrivalTime = "09:55", DepartureAirportCode = "TLV", DepartureAirportName = "Ben Gurion Airport", DepartureDate = "10.09.2018", DepartureDay = "Monday", DepartureTime = "06:55", FlightNumber = "681" }; FlightInfoVM flight = new FlightInfoVM() { airline = "LH", departureDate = "10.09.2018", destinationCity = "Munich", destinationCodeCity = "MUC", destinationCountry = "Germany", inbound = inbound, originCity = "Tel Aviv", originCodeCity = "TLV", originCountry = "Israel", outbound = outbound, price = "555.07", returnDate = "17.09.2018", seatsRemaining = "9", timeDuration_outbound = ToolsClass.TimeDifferences("06:55", "09:55"), timeDuration_inbound = ToolsClass.TimeDifferences("23:00", "03:35"), }; PackageInfoVM package = new PackageInfoVM() { hotel = hotel, flight = flight, nights = 7, price = 3121.4, composition = "Couple", }; return(View(package)); }
public ActionResult ViewPackageInfo(PackageDetailsVM obj) { var json = ""; using (WebClient wc = new WebClient()) { json = wc.DownloadString(obj.packages[obj.selectedPack].hotel.hotelLink).ToString(); } dynamic results = JsonConvert.DeserializeObject(json); // save some data from json to list. later we will save this data in the object we will pass to the view List <string> contactLST = HotelDetailsHelper1(results, "contacts"); List <string> amenitiesLST = HotelDetailsHelper1(results, "amenities"); List <RoomVM> roomLST = HotelDetailsHelper2(results); if (roomLST.Count == 0) // we need to fix the api { roomLST = HotelDetailsHelper3(obj.packages[obj.selectedPack].hotel.originalLink, obj.selectedPack); } // ---------------------- load reviews DataLayer dl = new DataLayer(); string hotelName = results.property_name; List <HotelReview> hotelReviewsList = (from u in dl.hotelReviews where u.HotelName.ToLower() == hotelName.ToLower() select u).ToList <HotelReview>(); // search for customer name (by email) List <string> customersName = new List <string>(); for (int i = 0; i < hotelReviewsList.Count; ++i) { string tempEmail = hotelReviewsList[i].CustomerEmail; string customerName = (from u in dl.customers where u.Email.ToLower() == tempEmail.ToLower() select u.FullName).ToList <string>()[0]; customersName.Add(customerName); } // ------------------------------------- // get image by GoogleAPI ImageSearch image = new ImageSearch(); try { image.SetHotelName(results.property_name.ToString()); // initialize object by GoogleAPI image.SavePhotoReferences(); } catch (Exception) { Thread.Sleep(1000); return(ViewPackageInfo(obj)); } List <string> imageLST = image.GetImages(); HotelOrderDetailsVM hotel = new HotelOrderDetailsVM() { hotelName = results.property_name, address = "ADDRESS: " + results.address.line1 + ", " + results.address.city, contact = contactLST, amenities = amenitiesLST, rating = obj.packages[obj.selectedPack].hotel.rating.ToString(), latitude = results.location.latitude, longitude = results.location.longitude, room = roomLST, image = imageLST, apiKey = image.GetKey(), reviews = hotelReviewsList, customersName = customersName, }; obj.packages[obj.selectedPack].flight.timeDuration_outbound = ToolsClass.TimeDifferences(obj.packages[obj.selectedPack].flight.outbound.DepartureTime, obj.packages[obj.selectedPack].flight.outbound.ArrivalTime); obj.packages[obj.selectedPack].flight.timeDuration_inbound = ToolsClass.TimeDifferences(obj.packages[obj.selectedPack].flight.inbound.DepartureTime, obj.packages[obj.selectedPack].flight.inbound.ArrivalTime); FlightInfoVM flight = obj.packages[obj.selectedPack].flight; PackageInfoVM package = new PackageInfoVM() { hotel = hotel, flight = flight, nights = obj.nights, price = obj.packages[obj.selectedPack].price, composition = obj.composition, }; return(View(package)); }
public JsonResult GetFlightsCoordinate() { /*Problem with subscribe * var end = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; * var start = end - 3600; * * AirlineFlightSchedules date = new AirlineFlightSchedules() * { * start_date = Convert.ToInt32(start), * end_date = Convert.ToInt32(end) * }; * * AirlineFlightSchedulesResult flights = _flightAwareAPI.GetAirlineFlightSchedules(date); */ FlightVM flightVM = new FlightVM(); List <FlightInfoVM> flightInfo = new List <FlightInfoVM>(); TrackStruct track = new TrackStruct(); FlightInfoStatusStruct infoStatus = new FlightInfoStatusStruct(); List <string> list = new List <string>(); list.Add("AUI146-1512800764-airline-0169"); //Ukraine: AUI146-1512800764-airline-0169 list.Add("SIA321-1512973541-airline-0029"); //London SIA321-1512973541-airline-0029 for (int i = 0; i < list.Count; i++) { FlightInfoVM flight = new FlightInfoVM(); var coordinates = _flightAwareAPI.GetFlightTrack(new GetFlightTrack { ident = list[i], include_position_estimates = false }); var info = _flightAwareAPI.GetFlightInfoStatus(new FlightInfoStatus { ident = list[i], include_ex_data = false, howMany = 3 }); if (coordinates != null && info != null) { track = coordinates.tracks.ToList().Last(); flight.Latitude = track.latitude; flight.Longitude = track.longitude; infoStatus = info.flights.ToList().Last(); flight.FlightId = infoStatus.faFlightID; flight.Airline = infoStatus.airline.ToString(); flightInfo.Add(flight); } } flightVM.FlightInfoVM = flightInfo; try { var email = HttpContext.Request.Cookies["user_login"].Value; flightVM.Email = email; } catch (Exception e) { flightVM.Email = "Error"; } return(Json(flightVM, JsonRequestBehavior.AllowGet)); }