public void GetSearchResult() { HBSearchData searchInputData = PreparesSearchObj(); var SMRresult = SearchHotel.SearchHotels(searchInputData, searchData.sID).Result; MapSearchResult(SMRresult); }
public HBSearchData PreparesSearchObj() { HBSearchData searchInputData = new HBSearchData(); searchInputData.stay.checkIn = Convert.ToDateTime(searchData.DateFrom).ToString("yyyy-MM-dd"); searchInputData.stay.checkOut = Convert.ToDateTime(searchData.DateTo).ToString("yyyy-MM-dd"); searchInputData.stay.shiftDays = "2"; searchInputData.occupancies = new List <Occupancy>(); searchInputData.hotels = new HotelsReq(); searchInputData.hotels.hotel = HotelIds; for (int i = 0; i < searchData.SearchRooms.Count; i++) { Occupancy occupancy = new Occupancy() { rooms = 1, adults = searchData.SearchRooms[i].Adult, children = searchData.SearchRooms[i].Child.Count, paxes = new List <PaxReq>() }; for (int k = 0; k < searchData.SearchRooms[i].Child.Count; k++) { occupancy.paxes.Add(new PaxReq { age = searchData.SearchRooms[i].Child[k], type = "CH" }); } searchInputData.occupancies.Add(occupancy); } return(searchInputData); }
public void GetSearchResult() { try { HBSearchData searchInputData = PreparesSearchObj(); searchOutputs = SearchHotel.SearchHotels(searchInputData, searchData.sID).Result; } catch (Exception ex) { LoggingHelper.WriteToFile("HBLogs/SearchController/Errors/", "HBIntegrationManagement" + "INControoler" + searchData.sID, ex.InnerException?.Message, ex.Message + ex.StackTrace); throw ex; } }
public static async Task <RootObject> SearchHotelService(HBSearchData value, string SessionID) { try { var client = new HttpClient(); var Data = new RootObject(); const string apiKey = "c2yc2s4vhhxqkhssr4p5jma6"; const string Secret = "UeF5JXgdqH"; // Compute the signature to be used in the API call (combined key + secret + timestamp in seconds) string signature; using (var sha = SHA256.Create()) { long ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds / 1000; Console.WriteLine("Timestamp: " + ts); var computedHash = sha.ComputeHash(Encoding.UTF8.GetBytes(apiKey + Secret + ts)); signature = BitConverter.ToString(computedHash).Replace("-", ""); } var url = "https://api.test.hotelbeds.com/hotel-api/1.0/hotels"; client.DefaultRequestHeaders.Add("Api-Key", "c2yc2s4vhhxqkhssr4p5jma6"); client.DefaultRequestHeaders.Add("X-Signature", signature); LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/SearchRequests", "SearchRequest_" + SessionID, "SearchRequest", Newtonsoft.Json.JsonConvert.SerializeObject(value)); var response = client.PostAsJsonAsync(url, value).Result; if (response.IsSuccessStatusCode) { Data = await response.Content.ReadAsAsync <RootObject>(); LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/SearchResponses", "SearchResponses_" + SessionID, "SearchResponses", Newtonsoft.Json.JsonConvert.SerializeObject(Data)); return(Data); } else { LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/SearchResponses", "SearchResponses_" + SessionID, "SearchResponses", Newtonsoft.Json.JsonConvert.SerializeObject(response)); return(null); } } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/SearchException", "SearchException_" + SessionID, "SearchException", requestData); return(null); } }
public static void MapRequestToDB(HBSearchData value, string SessionID) { try { HotelBedEntity db = new HotelBedEntity(); SearchRequest search = new SearchRequest(); search.SessionId = SessionID; search.Req = Newtonsoft.Json.JsonConvert.SerializeObject(value); db.SearchRequests.Add(search); db.SaveChanges(); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LoggingHelper.WriteToFile("HBLogs/SearchException", "SearchException_" + SessionID, "SearchException", requestData); } }
public static async Task <List <Hotel> > SearchHotels(HBSearchData value, string SessionID) { List <Hotel> HotelOutREsult = new List <Hotel>(); try { //yyyy-mm-dd SearchMapping.MapRequestToDB(value, SessionID); var hotels = await HotelSearchSer.SearchHotelService(value, SessionID); if (hotels == null) { return(new List <Hotel>()); } // SearchMapping.MapResponseToDB(hotels.hotels, SessionID); //foreach (var item in hotels.hotels.hotels) //{ // foreach (var r in item.rooms) // { // var room= r.rates.FirstOrDefault(a => a.sellingRate == r.rates.Min(x => x.sellingRate)); // } //} // var lstofSortedHotel = lstofHotels.Where(a => a.price.net == lstofHotels.Min(x => x.price.net)).FirstOrDefault(); return(hotels.hotels.hotels); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LoggingHelper.WriteToFile("HBLogs/SearchException", "SearchException_" + SessionID, "SearchException", requestData); return(new List <Hotel>()); } }
public static async Task <List <Hotel> > SearchHotels(HBSearchData value, string SessionID) { try { //yyyy-mm-dd SearchMapping.MapRequestToDB(value, SessionID); var hotels = await HotelSearchSer.SearchHotelService(value, SessionID); if (hotels == null) { return(new List <Hotel>()); } SearchMapping.MapResponseToDB(hotels.hotels, SessionID); return(hotels.hotels.hotels); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/SearchException", "SearchException_" + SessionID, "SearchException", requestData); return(new List <Hotel>()); } }
public static async Task <RootObject> SearchHotelService(HBSearchData value, string SessionID) { try { string path = ConfigurationSettings.AppSettings["HBSearchEndPonit"]; var client = new HttpClient(); var Data = new RootObject(); string apiKey = ConfigurationSettings.AppSettings["HBToken"]; string Secret = ConfigurationSettings.AppSettings["HBSecret"]; if (apiKey == null) { apiKey = "c2yc2s4vhhxqkhssr4p5jma6"; } if (Secret == null) { Secret = "UeF5JXgdqH"; } // apiKey = "c2yc2s4vhhxqkhssr4p5jma6"; // Secret = "UeF5JXgdqH"; // apiKey = "t4g8uy2qkvkb4wj5bc9q37k2"; // Secret = "SjxGKSA37w"; // 3rd key: hqm7exuenr4bptxhkkpa453s and secret:dbE7FQP7mE // apiKey = "hqm7exuenr4bptxhkkpa453s"; // Secret = "dbE7FQP7mE"; // Compute the signature to be used in the API call (combined key + secret + timestamp in seconds) // apiKey = "m758a2qayme2rk9upnu9qpp3"; /// Secret = "XPvvZeFeFJ"; string signature; using (var sha = SHA256.Create()) { long ts = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds / 1000; Console.WriteLine("Timestamp: " + ts); var computedHash = sha.ComputeHash(Encoding.UTF8.GetBytes(apiKey + Secret + ts)); signature = BitConverter.ToString(computedHash).Replace("-", ""); } // var url = "https://api.test.hotelbeds.com/hotel-api/1.0/hotels"; var url = path; client.DefaultRequestHeaders.Add("Api-Key", apiKey); client.DefaultRequestHeaders.Add("X-Signature", signature); LoggingHelper.WriteToFile("HBLogs/SearchRequests", "SearchRequest_" + SessionID, "SearchRequest", Newtonsoft.Json.JsonConvert.SerializeObject(value)); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var response = client.PostAsJsonAsync(url, value).Result; stopWatch.Stop(); TimeSpan ts1 = stopWatch.Elapsed; if (response.IsSuccessStatusCode) { Data = await response.Content.ReadAsAsync <RootObject>(); LoggingHelper.WriteToFile("HBLogs/SearchResponses", "SearchResponses_" + SessionID, "SearchResponses", "response time " + ts1.ToString() + Newtonsoft.Json.JsonConvert.SerializeObject(Data)); return(Data); } else { LoggingHelper.WriteToFile("HBLogs/SearchResponses", "SearchResponses_" + SessionID, "SearchResponses", "response time " + ts1.ToString() + Newtonsoft.Json.JsonConvert.SerializeObject(response)); return(null); } } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LoggingHelper.WriteToFile("HBLogs/SearchException", "SearchException_" + SessionID, "SearchException", requestData); return(null); } }