public static void SaveRequestToDB(AvailabilityReq req) { try { using (HotelBookingDBEntities db = new HotelBookingDBEntities()) { CheckAvailabiltyReq availabiltyReq = new CheckAvailabiltyReq(); availabiltyReq.BookinNum = req.BookingNum; availabiltyReq.HotelCode = req.HotelCode; availabiltyReq.Pid = req.PID; availabiltyReq.SID = req.Sid; availabiltyReq.TotalCost = req.TotalCost; availabiltyReq.CreateAt = DateTime.Now; var data = db.CheckAvailabiltyReqs; db.CheckAvailabiltyReqs.Add(availabiltyReq); foreach (var item in req.Rooms) { AvailabilityRoom room = new AvailabilityRoom(); room.BookingNum = req.BookingNum; room.RoomCode = item.RoomId.ToString(); room.RoomRef = item.RoomRef; room.Sid = req.Sid; db.AvailabilityRooms.Add(room); } db.SaveChanges(); } } catch (Exception ex) { LoggingHelper.WriteToFile("AvailabilityController/Errors/", "CheckAvailabilityRepo" + "SaveRequestToDB" + req.Sid, ex.InnerException?.Message, ex.Message + ex.StackTrace); } }
public static AvailabilityReq GetAvailabilityForCancelFromDB(string sid, string HotelCode, string roomcode, string pid) { AvailabilityReq availabilityReq = new AvailabilityReq(); try { SearchDBEntities searchDB = new SearchDBEntities(); using (HotelBookingDBEntities db = new HotelBookingDBEntities()) { availabilityReq.HotelCode = HotelCode; availabilityReq.PID = pid; availabilityReq.Sid = sid; var roomsData = searchDB.SearchRoomResults.Where(x => x.sID == sid && x.HotelCode == HotelCode && x.RoomCode == roomcode && x.ProviderId.ToString() == pid).ToList(); for (int i = 0; i < roomsData.Count; i++) { RoomAvailability room = new RoomAvailability(); room.RoomId = int.Parse(roomsData[i].RoomCode); room.RoomRef = roomsData[i].RoomReference; availabilityReq.Rooms.Add(room); availabilityReq.TotalCost += roomsData[i].costPrice.Value; } } return(availabilityReq); } catch (Exception ex) { throw ex; } }
public static async Task <AvailabilityRes> CheckAvailabilityService(AvailabilityReq value, string SessionID) { try { var client = new HttpClient(); var Data = new AvailabilityRes(); 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("-", ""); } LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/AvailabilityRequests", "AvailabilityRequest_" + SessionID, "AvailabilityRequest", Newtonsoft.Json.JsonConvert.SerializeObject(value)); var url = "https://api.test.hotelbeds.com/hotel-api/1.0/checkrates"; client.DefaultRequestHeaders.Add("Api-Key", "c2yc2s4vhhxqkhssr4p5jma6"); client.DefaultRequestHeaders.Add("X-Signature", signature); var response = client.PostAsJsonAsync(url, value).Result; if (response.IsSuccessStatusCode) { Data = await response.Content.ReadAsAsync <AvailabilityRes>(); LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/AvailabilityResponses", "AvailabilityResponses_" + SessionID, "AvailabilityResponses", Newtonsoft.Json.JsonConvert.SerializeObject(Data)); return(Data); } else { LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/AvailabilityResponses", "AvailabilityResponses_" + SessionID, "AvailabilityResponses", Newtonsoft.Json.JsonConvert.SerializeObject(response)); return(null); } } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/AvailabilityException", "AvailabilityException_" + SessionID, "AvailabilityException", requestData); return(null); } }
public CheckAvailabilityForTs GetHotelDataForTsAvailability(AvailabilityReq roomsReq) { try { SearchDBEntities dBEntities = new SearchDBEntities(); CheckAvailabilityForTs checkAvailability = new CheckAvailabilityForTs(); checkAvailability.HodelData = dBEntities.SearchHotelResults.FirstOrDefault(a => a.sID == roomsReq.Sid && a.HotelCode == roomsReq.HotelCode && a.ProviderID.Value.ToString() == roomsReq.PID); var RoomsData = roomsReq.Rooms.Select(a => a.RoomId.ToString()).ToList(); checkAvailability.roomResults = dBEntities.SearchRoomResults.Where(a => a.sID == roomsReq.Sid && a.HotelCode == roomsReq.HotelCode && a.ProviderId.Value.ToString() == roomsReq.PID && RoomsData.Contains(a.RoomCode)).ToList(); return(checkAvailability); } catch (Exception ex) { LoggingHelper.WriteToFile("AvailabilityController/Errors/", "HotelRepo" + "GetHotelDataForTsAvailability" + roomsReq.Sid, ex.InnerException?.Message, ex.Message + ex.StackTrace); return(null); } }
public static AvailabilityValidModel GetAvailabilityFromDB(string sid, string BN) { AvailabilityValidModel availabilityValid = new AvailabilityValidModel(); AvailabilityReq availabilityReq = new AvailabilityReq(); try { SearchDBEntities searchDB = new SearchDBEntities(); using (HotelBookingDBEntities db = new HotelBookingDBEntities()) { var HotelBookin = db.HotelsBookings.FirstOrDefault(x => x.SessionId == sid && x.Booking_No == BN); availabilityReq.HotelCode = HotelBookin.Hotel_ID; availabilityReq.BookingNum = BN; availabilityReq.PID = HotelBookin.Provider_ID; availabilityReq.Sid = sid; availabilityValid.Curr = HotelBookin.Sell_Currency; var BookedRooms = db.HotelBookingRooms.Where(x => x.SID == sid && x.Booking_No == BN).ToList(); var lstRooms = BookedRooms.Select(s => s.Room_No.ToString()).ToList(); var roomsData = searchDB.SearchRoomResults.Where(x => x.sID == sid && x.HotelCode == HotelBookin.Hotel_ID && lstRooms.Contains(x.RoomCode) && x.ProviderId.ToString() == HotelBookin.Provider_ID).ToList(); if (roomsData != null && roomsData.Count > 0) { for (int i = 0; i < BookedRooms.Count; i++) { RoomAvailability room = new RoomAvailability(); var roomData = roomsData.FirstOrDefault(a => a.RoomCode == BookedRooms[i].Room_No.ToString()); room.RoomId = int.Parse(roomData.RoomCode); room.RoomRef = roomData.RoomReference; room.Cost = roomData.costPrice.Value; availabilityReq.Rooms.Add(room); availabilityReq.TotalCost += roomData.costPrice.Value; } } } availabilityValid.availabilityReq = availabilityReq; return(availabilityValid); } catch (Exception ex) { throw ex; } }
public static void MapRequestToDB(AvailabilityReq value, string SessionID) { try { HotelBedEntities db = new HotelBedEntities(); foreach (var item in value.rooms) { AvailabilityRequest request = new AvailabilityRequest(); request.SessionID = SessionID; request.rate = item.rateKey; db.AvailabilityRequests.Add(request); } db.SaveChanges(); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LogData.WriteToFile("c:/HotelsB2C/Logs/HBLogs/AvailabilityException", "AvailabilityException_" + SessionID, "AvailabilityException", requestData); } }
public static async Task <Models.Availability.Hotel> checkAvailability(AvailabilityReq value, string SessionID) { try { //yyyy-mm-dd AvailabilityMapping.MapRequestToDB(value, SessionID); var hotels = await AvailabiltyService.CheckAvailabilityService(value, SessionID); if (hotels == null) { return(new Models.Availability.Hotel()); } AvailabilityMapping.MapResponseToDB(hotels, SessionID); return(hotels.hotel); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LogData.WriteToFile("c:/HotelsB2C/Logs/SMLogs/AvailabilityException", "AvailabilityException_" + SessionID, "AvailabilityException", requestData); return(new Models.Availability.Hotel()); } }
public static void SaveResponseToDB(CheckAvailabilityResult res, double newCost, AvailabilityReq req, string currency, string src) { try { using (HotelBookingDBEntities db = new HotelBookingDBEntities()) { AvailabilityRe availabilityRes = new AvailabilityRe(); availabilityRes.TotalsellPrice = res.TotalCost; availabilityRes.NewTotalcost = newCost; availabilityRes.OldTotalcost = req.TotalCost; availabilityRes.BookingNum = req.BookingNum; availabilityRes.PID = req.PID; availabilityRes.SellCurrency = currency; availabilityRes.Sid = req.Sid; availabilityRes.Status = res.Status; availabilityRes.hotelCode = req.HotelCode; db.AvailabilityRes.Add(availabilityRes); foreach (var item in res.Result) { availabilityRoomRe roomRes = new availabilityRoomRe(); roomRes.BookingNum = req.BookingNum; roomRes.Pid = req.PID; roomRes.Sid = req.Sid; roomRes.RoomRef = item.RoomCode; roomRes.Cost = item.CostPrice; roomRes.Courrency = currency; roomRes.roomId = item.RoomIndex; roomRes.SellPrice = item.TotalSellPrice; if (src == "policy") { foreach (var cancel in item.cancellationRules) { CancelPolicy policy = new CancelPolicy(); policy.Cost = (decimal)cancel.Cost; //if (req.PID == "4") //{ //policy.Currency = "EUR"; policy.Currency = currency; // } //else if (req.PID == "2") //{ //policy.Currency = "USD"; // } policy.FromDate = DateTime.Parse(cancel.FromDate); policy.HotelCode = req.HotelCode; policy.ProviderCurrency = currency; policy.ProviderID = req.PID; policy.RoomCode = item.RoomIndex; policy.SellPrice = (decimal)cancel.Price; policy.Sid = req.Sid; if (cancel.ToDate != null) { policy.ToDate = DateTime.Parse(cancel.ToDate); } db.CancelPolicies.Add(policy); } } db.availabilityRoomRes.Add(roomRes); } if (res.Status != 0) { var bookingData = db.HotelsBookings.FirstOrDefault(a => a.SessionId == req.Sid && a.Booking_No == req.BookingNum); if (bookingData != null) { bookingData.Sell_Price = res.TotalCost; } } db.SaveChanges(); } } catch (Exception ex) { LoggingHelper.WriteToFile("AvailabilityController/Errors/", "CheckAvailabilityRepo" + "SaveResponseToDB" + req.Sid, ex.InnerException?.Message, ex.Message + ex.StackTrace); } }
public CheckAvailabilityForTs GetHotelDataForTsAvailability(AvailabilityReq roomsReq) { HotelRepo repo = new HotelRepo(); return repo.GetHotelDataForTsAvailability(roomsReq); }