/**
         * Ao receber um POST, parseia a requisição, guarda a reserva desejada nos dados da sessão
         * e conecta ao WebServer, requisitando os hotéis referentes à reserva desejada.
         */
        public async Task OnPostAsync()
        {
            Message = "Hotéis disponíveis";
            Console.WriteLine("I'm not here");
            HttpClient httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
            Reserva reserva = new Reserva("", Request.Form["destino"], int.Parse(Request.Form["nQuartos"]), int.Parse(Request.Form["nPessoas"]));

            HttpContext.Session.SetString("reserva", JsonConvert.SerializeObject(reserva));

            string uri = Constants.serverPath + "/hotel" +
                         "?destino=" + reserva.destino + "&nQuartos=" + reserva.nQuartos.ToString() +
                         "&nPessoas=" + reserva.nPessoas.ToString();
            HttpResponseMessage response = await httpClient.GetAsync(uri);

            if (response.IsSuccessStatusCode)
            {
                hotels = await response.Content.ReadAsAsync <HotelCollection>(new List <MediaTypeFormatter> {
                    new XmlMediaTypeFormatter(),
                    new JsonMediaTypeFormatter()
                });
            }

            httpClient.Dispose();
        }
Esempio n. 2
0
        /**
         * Requisita a lista de hotéis registrados
         */
        private async Task getHotelList(HttpClient client)
        {
            HttpResponseMessage response = await client.GetAsync(Constants.serverPath + "/admin/hotel");

            if (response.IsSuccessStatusCode)
            {
                hotels = await response.Content.ReadAsAsync <HotelCollection>(new List <MediaTypeFormatter> {
                    new XmlMediaTypeFormatter(),
                    new JsonMediaTypeFormatter()
                });
            }
        }
        public static HotelOffers Map(HotelCollection response)
        {
            var dict = new Dictionary <int, string>()
            {
                { 0, "Hamilton Hotel - Washington DC." },
                { 1, "Hilton Garden Inn Washington DC Downtown" },
                { 2, "The Madison Washington, DC, a Hilton Hotel" },
                { 3, "Fairfield Inn & Suites by Marriott Washington, DC/Downtown" },
                { 4, "Embassy Suites by Hilton Washington DC Convention Center" },
                { 5, "Hyatt Place Washington DC/National Mall" },
                { 6, "Courtyard by Marriott Washington Embassy Row" },
            };
            //https://www.google.com/search?q=hertz+logo&tbm=isch&source=iu&ictx=1&fir=n0iDQzzKdolXSM%253A%252CiVtHVwm7oNJmZM%252C_&usg=__OkrVPO57e0GcB8g-3gyFXs088go%3D&sa=X&ved=0ahUKEwiLvKeu0cfbAhXQzlMKHZpCCFkQ9QEIOzAA#imgrc=n0iDQzzKdolXSM:
            var hotels = new List <TravelApp.Model.Orders.Hotel>();

            foreach (var hotel in response.results.hotels)
            {
                if (hotel.amenities == null)
                {
                    hotel.amenities = new List <string>();
                }
                if (hotel.rating == null)
                {
                    hotel.rating = new Rating
                    {
                        value = 5.0
                    };
                }
                if (hotel.offers == null || hotel.offers.Count == 0 || hotel.offers[0] == null)
                {
                    hotel.offers = new List <Offer>
                    {
                        new Offer
                        {
                            price        = 117,
                            cancellation = "non_refundable"
                        }
                    };
                }
                hotels.Add(new TravelApp.Model.Orders.Hotel
                {
                    address     = "Washington,DC", //hotel.city,
                    distance    = $"{hotel.rating.value} miles",
                    isBestHotel = hotel.rating.value > 8.7,
                    name        = dict[int.Parse(hotel.hotel_id) % 5],// hotel.name,
                    offerId     = hotel.hotel_id,
                    price       = $"${hotel.offers[0].price}",
                    amenities   = new HotelAmenities
                    {
                        isBarAvailable      = hotel.amenities.Contains("Bar"),
                        isBreakfastIncluded = hotel.amenities.Contains("Restaurant"),
                        isPetFriendly       = hotel.amenities.Contains("Pool"),
                        isRefundable        = !string.Equals(hotel.offers[0].cancellation, "non_refundable", StringComparison.OrdinalIgnoreCase),
                        isSmokingAllowed    = !hotel.amenities.Contains("NonSmokingService"),
                        isTV   = hotel.amenities.Contains("AirConditioning"),
                        isWifi = hotel.amenities.Contains("WifiService")
                    },
                    imagePath  = hotel.images[0].thumbnail,
                    starRating = hotel.rating.value,
                    starType   = hotel.stars,
                });
            }

            return(new HotelOffers
            {
                Offers = hotels.Count > 20 ? hotels.Take(20).ToList() : hotels
            });
        }