示例#1
0
        public ActionResult Index()
        {
            try
            {
                BookHotelModelView bookHotelModelView = new BookHotelModelView();

                //possible destinations
                ViewBag.Destination = new List <SelectListItem>
                {
                    new SelectListItem()
                    {
                        Text = "MIAMI", Value = "1003944"
                    },
                    new SelectListItem()
                    {
                        Text = "ORLANDO", Value = "1010106"
                    }
                };

                return(View(bookHotelModelView));
            }
            catch
            {
                return(View("Error"));
            }
        }
示例#2
0
 public BookHotelRequest(BookHotelModelView bookHotelModelView)
 {
     this.Credential = new Credential();
     this.Criteria   = new Criteria(bookHotelModelView);
 }
示例#3
0
        public async Task <ActionResult> SearchAsync(BookHotelModelView bookHotelModelView)
        {
            try
            {
                //fixed value
                bookHotelModelView.MainPaxCountryCodeNationality = "BR";



                //**********************************************************************
                //TEMPORARY FIX
                //CHILD AGES MUST BE PASSED THROUGH A FORM AND SHOULD NOT BE A FIXED VALUE
                //*********************************************************************
                bookHotelModelView.ChildAges = new List <int>();
                for (int i = 0; i <= bookHotelModelView.NumChildren; i++)
                {
                    bookHotelModelView.ChildAges.Add(5);
                }



                //validate the model received by the form
                if (!ModelState.IsValid)
                {
                    //possible destinations
                    ViewBag.Destination = new List <SelectListItem> {
                        new SelectListItem()
                        {
                            Text = "MIAMI", Value = "1003944"
                        },
                        new SelectListItem()
                        {
                            Text = "ORLANDO", Value = "1010106"
                        }
                    };

                    return(View("Index", bookHotelModelView));
                }

                //create request
                BookHotelRequest bookHotelRequest = new BookHotelRequest(bookHotelModelView);


                //get response
                BookHotelResponse bookHotelResponse = await SearchHotelRoomAsync(bookHotelRequest);


                //check if the response has any error
                if (bookHotelResponse.Error != null)
                {
                    return(View("Index", bookHotelModelView));
                }


                //orders the hotels list by price
                foreach (HotelAvailable hotel in bookHotelResponse.Hotels)
                {
                    hotel.minPrice = int.MaxValue;
                    foreach (Room room in hotel.Rooms)
                    {
                        if (room.TotalSellingPrice.Value < hotel.minPrice)
                        {
                            hotel.minPrice = room.TotalSellingPrice.Value;                                                //sets min price for each hotel
                        }
                    }

                    hotel.Rooms.Sort((x, y) => x.TotalSellingPrice.Value.CompareTo(y.TotalSellingPrice.Value));
                }
                bookHotelResponse.Hotels.Sort((x, y) => x.minPrice.CompareTo(y.minPrice));



                //returns the hotel list to be viewed
                return(View("Search", bookHotelResponse));
            }
            catch
            {
                return(View("Error"));
            }
        }