public static async Task <Bookingback> BookingHotel(HotelBookInput Value, string SessionID) { try { Bookingback BackData = new Bookingback(); BookingService bookingService = new BookingService(); var data = await bookingService.HotelBooking(Value, SessionID); var OutPutData = data.Data.hotelX.book.booking; BookingMapper serMap = new BookingMapper(); if (data.Data.hotelX.book.errors == null && data.Data.hotelX.book.warnings == null && data.Data.hotelX.book.booking != null) { BackData = serMap.MapResponseofBooking(OutPutData, SessionID); BookingDataEntry db = new BookingDataEntry(); db.SaveSMRBooking(BackData, SessionID); } else { return(new Bookingback()); } return(BackData); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LoggerHelper.WriteToFile("c:/HotelsB2C/Logs/SMLogs/BookingException", "BookingException_" + SessionID, "BookingException", requestData); return(new Bookingback()); } }
public async void SaveSMRBooking(Bookingback result, string SessionId) { try { db.DB_OpenConnection(); DataTable dt_BookingRate = new DataTable(); dt_BookingRate = CreateBookingTable.CreateBookingTB(); DataRow dr = dt_BookingRate.NewRow(); dr["supplier"] = result.reference.supplier; dr["client"] = result.reference.client; dr["SessionId"] = SessionId; if (result.holder != null) { dr["HolderName"] = result.holder.name; dr["HolderSerName"] = result.holder.surname; } dr["CurrencyPrice"] = result.price.currency; dr["Net"] = result.price.net; dr["Gross"] = result.price.gross; dr["BindingPrice"] = result.price.binding; dr["CurrencyExchange"] = result.price.exchange.currency; dr["CurrencyRate"] = result.price.exchange.rate; dr["CancelRefundable"] = result.cancelPolicy.refundable; dr["Status"] = result.status; dr["Payabe"] = result.payable; dr["Remark"] = result.remarks; if (result.hotel != null) { dr["CreationDate"] = result.hotel.creationDate; dr["HotelCode"] = result.hotel.hotelCode; dr["CheckIN"] = result.hotel.checkIn; dr["CheckOut"] = result.hotel.checkOut; dr["BoardCode"] = result.hotel.boardCode; } dt_BookingRate.Rows.Add(dr); // consume sp to get bookingid int bookingID = await db.SaveBooking_Async(dt_BookingRate); DataTable dt_Room = new DataTable(); dt_Room = CreateBookingTable.CreateRoomBookingTB(); if (result.hotel != null) { foreach (var item in result.hotel.rooms) { DataRow drr = dt_Room.NewRow(); drr["occupancyRefId"] = item.occupancyRefId; drr["code"] = item.code; drr["description"] = item.description; drr["CurrencyPrice"] = item.price.currency; drr["NetPrice"] = item.price.net; drr["GrossPrice"] = item.price.gross; drr["Binding"] = item.price.binding; drr["ExchangeCurrency"] = item.price.exchange.currency; drr["ExchangeRate"] = item.price.exchange.rate; drr["BookingID"] = bookingID; dt_Room.Rows.Add(drr); } await db.SaveBookingRoom_Async(dt_Room); } // DataTable dt_Policy = new DataTable(); dt_Policy = CreateBookingTable.CreatePolicyBookingTB(); if (result.cancelPolicy.cancelPenalties != null) { foreach (var item in result.cancelPolicy.cancelPenalties) { DataRow drp = dt_Policy.NewRow(); drp["Currency"] = item.currency; drp["Type"] = item.penaltyType; drp["Value"] = item.value; drp["hoursBefore"] = item.hoursBefore; drp["BookingId"] = bookingID; dt_Policy.Rows.Add(drp); } await db.SavePolicyBooking_Async(dt_Policy); } if (result.hotel != null) { foreach (var R in result.hotel.occupancies) { var roomid = await db.SavePaxROOMBooking_Async(R.id, bookingID); DataTable dt_pax = new DataTable(); dt_pax = CreateBookingTable.CreatePaxesBookingTB(); foreach (var pax in R.paxes) { DataRow drx = dt_pax.NewRow(); drx["Age"] = pax.age; drx["Room_Id"] = roomid; dt_pax.Rows.Add(drx); } await db.SavePaxesBooking_Async(dt_pax); } } // db.DB_CloseConnection(); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LoggerHelper.WriteToFile("SMLogs/BookingDBException", "BookingDBException_" + SessionId, "BookingDBException", requestData); throw; } }
public Bookingback MapResponseofBooking(dynamic OutPutData, string sessionId) { try { var BackData = new Bookingback(); BackData.reference.client = OutPutData.reference.client; BackData.reference.supplier = OutPutData.reference.supplier; if (OutPutData.holder == null) { BackData.holder = null; } else { BackData.holder.name = OutPutData.holder.name; BackData.holder.surname = OutPutData.holder.surname; } if (OutPutData.hotel == null) { BackData.hotel = null; } else { BackData.hotel.boardCode = OutPutData.hotel.boardCode; BackData.hotel.checkIn = OutPutData.hotel.checkIn; BackData.hotel.checkOut = OutPutData.hotel.checkOut; BackData.hotel.creationDate = OutPutData.hotel.creationDate; BackData.hotel.hotelCode = OutPutData.hotel.hotelCode; BackData.hotel.hotelName = OutPutData.hotel.hotelName; if (OutPutData.hotel.rooms != null) { foreach (var item in OutPutData.hotel.rooms) { BookingRoom room = new BookingRoom(); room.code = item.code; room.description = item.description; room.occupancyRefId = item.occupancyRefId; room.price.currency = item.price.currency; room.price.net = item.price.net; room.price.gross = item.price.gross; room.price.binding = item.price.binding; room.price.exchange.currency = item.price.exchange.currency; room.price.exchange.rate = item.price.exchange.rate; BackData.hotel.rooms.Add(room); } } if (OutPutData.hotel.occupancies != null) { foreach (var p in OutPutData.hotel.occupancies) { PaxBack roomPax = new PaxBack(); roomPax.id = p.id; foreach (var x in p.paxes) { Pax pax = new Pax(); pax.age = x.age; roomPax.paxes.Add(pax); } BackData.hotel.occupancies.Add(roomPax); } } } BackData.price.currency = OutPutData.price.currency; BackData.price.net = OutPutData.price.net; BackData.price.gross = OutPutData.price.gross; BackData.status = OutPutData.status; BackData.remarks = OutPutData.remarks; BackData.payable = OutPutData.payable; if (OutPutData.cancelPolicy != null) { BackData.cancelPolicy.refundable = OutPutData.cancelPolicy.refundable; foreach (var c in OutPutData.cancelPolicy.cancelPenalties) { CancelPenalty cancelPenalty = new CancelPenalty(); cancelPenalty.currency = c.currency; cancelPenalty.hoursBefore = c.hoursBefore; cancelPenalty.value = c.value; cancelPenalty.penaltyType = c.penaltyType; BackData.cancelPolicy.cancelPenalties.Add(cancelPenalty); } } return(BackData); } catch (Exception ex) { var requestData = JsonConvert.SerializeObject(ex); LoggerHelper.WriteToFile("c:/HotelsB2C/Logs/SMLogs/BookingMapException", "BookingMapException_" + sessionId, "BookingMapException", requestData); throw; } }