예제 #1
0
        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));
        }
예제 #2
0
        public ActionResult ViewHotelInfo(SearchResultsVM srvm)
        {
            var json = "";

            using (WebClient wc = new WebClient())
            {
                json = wc.DownloadString(srvm.hotelId).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(srvm.originalLink, srvm.selectedHotel);
            }

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


            // create HotelOrderDetailsVM to pass to the view
            ImageSearch image = new ImageSearch();

            image.SetHotelName(results.property_name.ToString()); // initialize object by GoogleAPI
            image.SavePhotoReferences();
            List <string> imageLST = image.GetImages();

            HotelOrderDetailsVM hotelOrderDetailsVM = new HotelOrderDetailsVM()
            {
                destination     = srvm.destination,
                hotelName       = results.property_name,
                address         = "ADDRESS: " + results.address.line1 + ", " + results.address.city,
                contact         = contactLST,
                amenities       = amenitiesLST,
                rating          = srvm.hotelRating,
                latitude        = results.location.latitude,
                longitude       = results.location.longitude,
                room            = roomLST,
                image           = imageLST,
                apiKey          = image.GetKey(),
                searchResultsVM = srvm,
                reviews         = hotelReviewsList,
                customersName   = customersName
            };

            return(View("ViewHotelInfo", hotelOrderDetailsVM));
        }