public static HotelRoomAvailabilityResponse Availabilty(string SessionId, int ResIndex, string HotelCode, string SID)
        {
            var UName = ConfigurationSettings.AppSettings["TBOUserName"];
            var UPass = ConfigurationSettings.AppSettings["TBOPassword"];
            HotelRoomAvailabilityRequest req = new HotelRoomAvailabilityRequest
            {
                SessionId   = SessionId,
                ResultIndex = ResIndex,
                HotelCode   = HotelCode,
                IsCancellationPolicyRequired = true, // already come in Pricing
                Credentials = new AuthenticationData()
                {
                    UserName = UName,
                    Password = UPass
                }
            };

            ProviderLogger.LogRoomAvailabiltyReq(req, SID);

            IHotelService proxy = TBOCredentials.CreateProxy();
            HotelRoomAvailabilityResponse resp = new HotelRoomAvailabilityResponse();

            resp = proxy.AvailableHotelRooms(req);
            ProviderLogger.LogRoomAvailabilityProviderRsp(resp, SID);

            return(resp);
        }
        public static void LogRoomAvailabilityProviderRsp(HotelRoomAvailabilityResponse AvailabilityRsp, string SearchId)
        {
            string path = MainPath + @"\TBOLogs\" + DateTime.UtcNow.Date.ToString("dd_MM_yyyy") + @"\" + SearchId + @"\RoomAvailabilityResp\";

            Directory.CreateDirectory(path);
            path = path + "RoomAvailabilityResp.txt";
            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer(AvailabilityRsp.GetType());
                using (StreamWriter streamwriter = new StreamWriter(path, append: false))
                {
                    xmlSerializer.Serialize(streamwriter, AvailabilityRsp);
                    streamwriter.Close();
                }
            }
            catch (FileNotFoundException Ex)
            {
                throw new LoggerException(LoggerErrorCodes.LoggerFileNotFound, LoggerErrorCodes.LoggerFileNotFound + " -This path (" + path + ") doesn't exist with file name " + Ex.FileName + " .", Ex.Message);
            }
            catch (IOException Ex)
            {
                throw new LoggerException(LoggerErrorCodes.LoggerFileINProcess, LoggerErrorCodes.LoggerFileINProcess + " -This Logger File (" + path + ") in another process you can not access it right now.", Ex.Message);
            }
            catch (Exception Ex)
            {
                throw new LoggerException(LoggerErrorCodes.FailedLogIntoLogger, LoggerErrorCodes.FailedLogIntoLogger + " -Failed Log Into Logger with path (" + path + ").", Ex.Message);
            }
        }
Beispiel #3
0
        //map tbo rooms rsp to general res

        public static HotelSearchRoom MapTboRoomRspTogenrl(HotelRoomAvailabilityResponse response, string SID)
        {
            if (response.HotelRooms == null)
            {
                return(null);
            }
            //get ADT CHD NO
            SearchRepo manager = new SearchRepo();
            var        rooms   = manager.GetADTCHDNoBySid(SID);

            CurrencyManager   currencyManager           = new CurrencyManager();
            SalesRulesManager ServiceChargeManager      = new SalesRulesManager();
            SalesRulesManager CancellationChargeManager = new SalesRulesManager();
            var BaseCur = ConfigurationSettings.AppSettings["BaseCur"];

            double ProviderExcahngeRate = currencyManager.GetCurrencyConversion(response.HotelRooms[0].RoomRate.Currency, BaseCur, SID);

            double ExcahngeRate = currencyManager.GetCurrencyConversion(BaseCur, response.HotelRooms[0].RoomRate.Currency, SID);

            AppliedSalesRule AppliedCancellationMarkup = CancellationChargeManager.ApplySalesRules("Markup");

            //
            //options for booking
            List <OptionsForBooking> options = new List <OptionsForBooking>();

            foreach (var item in response.OptionsForBooking.RoomCombination)
            {
                options.Add(new OptionsForBooking
                {
                    RoomIndex = item.RoomIndex
                });
            }
            List <RoomResult> roomResults = new List <RoomResult>();

            foreach (var item in response.HotelRooms.ToList())
            {
                //supplements
                List <Hotels.Common.Models.RoomResult.Supplement> supplements = new List <Hotels.Common.Models.RoomResult.Supplement>();
                if (item.Supplements != null)
                {
                    foreach (var sup in item.Supplements)
                    {
                        supplements.Add(new Hotels.Common.Models.RoomResult.Supplement
                        {
                            Price          = sup.Price,
                            SuppChargeType = sup.SuppChargeType.ToString(),
                            SuppID         = sup.SuppID,
                            SuppIsSelected = sup.SuppIsMandatory,
                            Cur            = sup.CurrencyCode,
                        });
                    }
                }

                List <CancellationRule> cancellationRules = new List <CancellationRule>();
                foreach (var cancel in item.CancelPolicies.CancelPolicy)
                {
                    double costToSave = 0;
                    string Cur        = "";
                    //Enum.TryParse(cancel.ChargeType.ToString(), out CancellationChargeTypeForHotel Type);

                    if (cancel.ChargeType == CancellationChargeTypeForHotel.Percentage)
                    {
                        costToSave = (double)cancel.CancellationCharge;
                        Cur        = "%";
                    }
                    else
                    {
                        Cur        = "KWD";
                        costToSave = (double)cancel.CancellationCharge * ProviderExcahngeRate; //Math.Round((double)cancel.CancellationCharge * ProviderExcahngeRate, 3);
                    }
                    cancellationRules.Add(new CancellationRule
                    {
                        Price    = costToSave,
                        Curency  = Cur,
                        FromDate = cancel.FromDate,
                        ToDate   = cancel.ToDate,
                        //Cost = (double)cancel.CancellationCharge,
                        Cost       = (double)cancel.CancellationCharge,
                        ChargeType = cancel.ChargeType.ToString(),
                    });
                }
                //foreach (var PaxNo in rooms)
                //{

                roomResults.Add(new RoomResult
                {
                    RoomIndex = item.RoomIndex,
                    RoomType  = item.RoomTypeName + "   " + item?.RoomPromtion,
                    //RoomCode = item.RoomIndex,
                    RoomCode      = item.RoomTypeCode,
                    RoomReference = item.RatePlanCode,
                    //Adult = rooms.FirstOrDefault(ad=>ad.roomNo == item.RoomIndex).adultNo ?? default(int),
                    //Child = rooms.FirstOrDefault(ad => ad.roomNo == item.RoomIndex).childernNo ?? default(int),
                    // RatePerNight = ((double)item.RoomRate.TotalFare * ProviderExcahngeRate ) * ExcahngeRate,

                    //TotalSellPrice = Math.Round(((double)item.RoomRate.TotalFare * ProviderExcahngeRate) * ExcahngeRate, 3),

                    //tax
                    rateType = item.RoomRate.RoomTax.ToString(),
                    //base
                    rateClass = item.RoomRate.RoomFare.ToString(),
                    //RatePerNight = (double)item.RoomRate.DayRates[0].BaseFare,
                    CostPrice = (double)item.RoomRate.TotalFare,
                    Tax       = item.RoomRate.RoomTax,
                    RoomMeal  = item.MealType,
                    //sell curency   kwd
                    Curency           = BaseCur,
                    TotalSellPrice    = Math.Round((double)item.RoomRate.TotalFare * ProviderExcahngeRate, 3),
                    Supplements       = supplements,
                    cancellationRules = cancellationRules,
                    Images            = item?.RoomAdditionalInfo?.ImageURLs.ToList(),
                    Amenities         = item.Amenities,
                    Inclusion         = item.Inclusion
                });
                //}
            }
            HotelSearchRoom hotelSearchRoom = new HotelSearchRoom();
            int             PkageNO         = 0;

            foreach (var item in options)
            {
                PkageNO++;
                SearchRoomData roomresult = new SearchRoomData();
                roomresult = null;
                SeparatedRoom srts = new SeparatedRoom();
                for (int i = 0; i < item.RoomIndex.Count(); i++)
                {
                    var resultsR = roomResults.Where(res => res.RoomIndex == item.RoomIndex[i]).FirstOrDefault();
                    resultsR.PackageNO = PkageNO;
                    srts.RoomResults.Add(resultsR);
                }
                hotelSearchRoom.rooms.Add(srts);
            }

            SeparatedRoom separatedRoom = new SeparatedRoom
            {
                OptionsForBookings = options,
                RoomResults        = roomResults
            };

            var singles = roomResults.GroupBy(n => n.RoomCode).ToList()
                          //.Where(g => g.Count() == 1)
                          .Select(g => g.First()).ToList();

            hotelSearchRoom.Packages = singles;
            return(hotelSearchRoom);
        }
        public HotelAvailabilityRS MappingHotelAvailability(HotelRoomAvailabilityResponse rawRs)
        {
            HotelAvailabilityRS rs = new HotelAvailabilityRS();

            //EAN warning and error
            if (rawRs.EanWsError != null)
            {
                //error! something has happened
                rs.Errors = new List<WarningAndError>();
                WarningAndError error = helper.GenerateWarningAndError(9001, rawRs.EanWsError);
                rs.Errors.Add(error);
            }
            else
            {

                //init hotel
                rs.Hotel = new HDSInterfaces.Hotel();

                //hotel address info
                rs.Hotel.HotelInfo = new HotelInformation();
                rs.Hotel.HotelInfo.Id = rawRs.hotelId;
                rs.Hotel.HotelInfo.Name = rawRs.hotelName;
                rs.Hotel.HotelInfo.Address = new Address();
                rs.Hotel.HotelInfo.Address.Street1 = rawRs.hotelAddress;
                rs.Hotel.HotelInfo.Address.City = new City { Name = rawRs.hotelCity };
                rs.Hotel.HotelInfo.Address.Country = new Country { Code = rawRs.hotelCountry };

                //room
                rs.Hotel.Rooms = new List<HDSInterfaces.Room>();
                foreach (HotelRoomResponse rawRoom in rawRs.HotelRoomResponse)
                {
                    HDSInterfaces.Room room = new HDSInterfaces.Room();

                    //room cancellation
                    room.CancellationPolicy = new CancellationPolicy { CancellationPolicyDescription = rawRoom.cancellationPolicy };
                    room.CancellationPolicy.IsNonRefundable = rawRoom.nonRefundable;

                    //room info
                    room.Name = rawRoom.rateDescription;
                    room.Description = rawRoom.rateDescription;
                    room.RoomInfo = new RoomInfo();

                    //room promotion
                    if (rawRoom.promoDescription != null){
                        room.Promotions = new List<Promotion>();
                        room.Promotions.Add(new Promotion { Code = rawRoom.promoId, Description = rawRoom.promoDescription });
                    }

                    //room bedding config
                    if (rawRoom.BedTypes != null)
                        room.RoomInfo.BeddingDescription = rawRoom.BedTypes.BedType[0].description;

                    //room images
                    if (rawRoom.RoomImages != null){
                        room.RoomInfo.Images = new List<HDSInterfaces.RoomImage>();
                        room.RoomInfo.Images.Add(new HDSInterfaces.RoomImage { URL = rawRoom.RoomImages.RoomImage[0].url });
                    }

                    //value adds
                    if (rawRoom.ValueAdds != null){
                        room.ValueAdds = new List<RoomValueAdd>();
                        foreach (valueAdd rawValueAdd in rawRoom.ValueAdds.ValueAdd){
                            room.ValueAdds.Add(new RoomValueAdd { Id = rawValueAdd.id, Description = rawValueAdd.description });
                        }
                    }

                    //room rate total and nightly
                    room.Rates = helper.GenerateRoomRate(rawRoom.RateInfo);

                    rs.Hotel.Rooms.Add(room);
                }
            }

            return rs;
        }