// GET: Packages/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var packages = await _context.Packages .Include(p => p.Event) .Include(p => p.Transaction) .FirstOrDefaultAsync(m => m.PackageId == id); if (packages == null) { return(NotFound()); } var items = await _context.Items .Include(i => i.Guest) .Include(i => i.Package) .ToListAsync(); if (items == null) { return(NotFound()); } var packageItems = new PackageDetailsVM { Packages = packages, Items = items }; var guests = _context.Guests .Select(n => new { GuestId = n.GuestId, GuestFullName = string.Format("{0} - {1}", n.GuestFullName, n.GuestEmail) }) .ToList(); ViewData["GuestId"] = new SelectList(guests, "GuestId", "GuestFullName"); ViewData["PackageId"] = new SelectList(_context.Packages, "PackageId", "PackageName"); ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", packageItems.CategoryId); return(View(packageItems)); }
// GET: Packages/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var packages = await _context.Packages .Include(p => p.Event) .Include(p => p.Transaction) .FirstOrDefaultAsync(m => m.PackageId == id); if (packages == null) { return(NotFound()); } var items = await _context.Items.ToListAsync(); if (items == null) { return(NotFound()); } var packageItems = new PackageDetailsVM { Packages = packages, Items = items }; ViewData["GuestId"] = new SelectList(_context.Guests, "GuestId", "GuestFirstName"); ViewData["PackageId"] = new SelectList(_context.Packages, "PackageId", "PackageName"); ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", packageItems.CategoryId); return(View(packageItems)); }
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)); }
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)); }