public HotelSearchResponse Search(HotelSearchRequest hotelSearchRequest) { var url = "http://api.hotelbeds.com/hotel-api/1.0/availability"; var json = getJson(hotelSearchRequest); var hotelSearchResponse = new HotelSearchResponse(); hotelSearchResponse.HotelStays = new List <HotelStay>(); using (var client = new WebClient()) { client.Headers.Add("Content-Type", "application/json"); client.Headers.Add("Api-Key", "6262k3bddqe67jsbahb9wqnx"); byte[] responsebytes = client.UploadData(url, "POST", System.Text.Encoding.ASCII.GetBytes(json)); string jsonresponse = Encoding.UTF8.GetString(responsebytes); var data = JsonConvert.DeserializeObject <dynamic>(jsonresponse); foreach (var hotel in data.hotels.hotels) { hotelSearchResponse.HotelStays.Add(new HotelStay() { HotelId = Convert.ToInt32(hotel.code), Latitude = hotel.latitude, Longitude = hotel.longitude, Price = hotel.minPrice, LocationName = hotel.destination }); } } return(hotelSearchResponse); }
public HotelSearchResponse Search(HotelSearchRequest hotelSearchRequest) { var hotelSearchResponse = new HotelSearchResponse(); hotelSearchResponse.HotelStays = new List <HotelStay>(); hotelSearchResponse.HotelStays.Add(new HotelStay() { HotelId = 12345, Latitude = "Munich City Center", Longitude = "-5.10000000", LocationName = "64.10000000", Price = 99.99M }); hotelSearchResponse.HotelStays.Add(new HotelStay() { HotelId = 545354, Latitude = "Manchester Palace", Longitude = "-6.10000000", LocationName = "66.10000000", Price = 20.00M }); return(hotelSearchResponse); }