public static void LogAvailablityPricingReq(AvailabilityAndPricingRequest AvailablityPricingReq, string SearchId)
        {
            string path = MainPath + @"\TBOLogs\" + DateTime.UtcNow.Date.ToString("dd_MM_yyyy") + @"\" + SearchId + @"\AvailablityPricingReq\";

            Directory.CreateDirectory(path);
            path = path + "AvailablityPricingReq.txt";
            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer(AvailablityPricingReq.GetType());
                using (StreamWriter streamwriter = new StreamWriter(path, append: false))
                {
                    xmlSerializer.Serialize(streamwriter, AvailablityPricingReq);
                    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);
            }
        }
Esempio n. 2
0
        public static AvailabilityAndPricingResponse PricingService(AvailabilityAndPricingRequest req, string SID)
        {
            var UName = ConfigurationSettings.AppSettings["TBOUserName"];
            var UPass = ConfigurationSettings.AppSettings["TBOPassword"];

            req.Credentials = new AuthenticationData()
            {
                UserName = UName,
                Password = UPass
            };

            IHotelService proxy = TBOCredentials.CreateProxy();

            ProviderLogger.LogAvailablityPricingReq(req, SID);
            AvailabilityAndPricingResponse resp = new AvailabilityAndPricingResponse();

            resp = proxy.AvailabilityAndPricing(req);
            ProviderLogger.LogAvailablityPricingProviderRsp(resp, SID);
            return(resp);
        }
Esempio n. 3
0
        public IHttpActionResult Get(string sid, string hotel, string Pid, string rooms)
        {
            // call bll
            try
            {
                LoggingHelper.WriteToFile("HotelRoomsController/GetRoomsNumber/", "SearchController" + "INController" + sid, "Rooms", "Sid" + sid);


                var Rooms = GetRoom.GetRoomsData(sid, hotel, Pid, rooms);
                if (Rooms != null && Rooms.rooms.Count > 0)
                {
                    #region tbo  disable to not calling pricing api
                    if (Pid == "5")
                    {
                        // var ActionUrlData = ConfigurationSettings.AppSettings["ActionUrl"];
                        // var BaseCur = ConfigurationSettings.AppSettings["BaseCur"];
                        //payLinkData.ActionsUrl.ValidationUrl = ActionUrlData + "/api/HotelCheckAvailability?sid=" + Sid + "&bookingnum=" + BN;

                        SearchDBEntities searchDB = new SearchDBEntities();

                        RequiredBookingData requiredBooking = new RequiredBookingData();
                        //var data = searchDB.SearchCriterias.FirstOrDefault(a => a.sID == sid);
                        var HRooms = searchDB.SearchRoomResults.Where(a => a.sID == sid && a.HotelCode == hotel && a.ProviderId.ToString() == Pid).ToList();
                        //requiredBooking.Currency = data?.currency;
                        //requiredBooking.City = data?.cityName;
                        var RoomsCode = rooms.Split('-');
                        foreach (var item in RoomsCode)
                        {
                            var roomdata = HRooms.FirstOrDefault(a => a.RoomCode == item);

                            requiredBooking.rooms.Add(roomdata);
                        }
                        //TBO
                        //call check availability tbo to get hotel norms and cancel policy
                        //get room indexes to send in pricing req
                        List <int> indexs = new List <int>();

                        foreach (var indx in requiredBooking.rooms)
                        {
                            indexs.Add(int.Parse(indx.RoomCode));
                        }
                        string TBOSession = searchDB.ProviderSessions.FirstOrDefault(ps => ps.SearchId == sid).PSession;                                                   //Select(s => s.PSession).ToString();
                        int    ResIndex   = int.Parse(searchDB.SearchHotelResults.FirstOrDefault(hotl => hotl.sID == sid && hotl.HotelCode == hotel).ResIndex.ToString()); //Select(indx => indx.ResIndex).ToString();
                        AvailabilityAndPricingRequest req = new AvailabilityAndPricingRequest
                        {
                            SessionId         = TBOSession,
                            ResultIndex       = ResIndex,
                            OptionsForBooking = new TBO.WSDL.hotelServiceRef.BookingOptions
                            {
                                RoomCombination = new TBO.WSDL.hotelServiceRef.RoomCombination[]
                                {
                                    new TBO.WSDL.hotelServiceRef.RoomCombination {
                                        RoomIndex = indexs.ToArray()
                                    }
                                }
                            }
                        };
                        var        availRes   = AvailablityPricingService.PricingService(req, sid);
                        RoomResult roomResult = new RoomResult();
                        if (availRes != null)
                        {
                            if (availRes?.PriceVerification?.Status == PriceVerificationStatus.Failed ||
                                availRes?.PriceVerification?.Status == PriceVerificationStatus.NotAvailable)
                            {
                                return(Ok("No Result Found"));
                            }
                            if (availRes.HotelCancellationPolicies != null)
                            {
                                roomResult.HotelNorms = availRes.HotelCancellationPolicies?.HotelNorms;
                                //handel cancel policy
                                var             BaseCur              = ConfigurationSettings.AppSettings["BaseCur"];
                                CurrencyManager currencyManager      = new CurrencyManager();
                                double          ProviderExcahngeRate = currencyManager.GetCurrencyConversion("USD", BaseCur, sid);

                                foreach (var cancel in availRes.HotelCancellationPolicies?.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);
                                    }
                                    CancellationRule cancellation = new CancellationRule();
                                    cancellation.FromDate   = cancel.FromDate;
                                    cancellation.ToDate     = cancel.ToDate;
                                    cancellation.Cost       = (double)cancel.CancellationCharge;
                                    cancellation.ChargeType = cancel.ChargeType.ToString();
                                    cancellation.Curency    = Cur;
                                    cancellation.Price      = costToSave; //
                                    roomResult.cancellationRules.Add(cancellation);
                                }


                                if (availRes?.PriceVerification?.PriceChanged == true)
                                {
                                    //var roomsTbo = searchDB.SearchRoomResults.Where(a => a.sID == sid && a.HotelCode == hotel && a.ProviderId.ToString() == Pid).ToList();
                                    Rooms.Status  = 1;
                                    Rooms.Message = "Price Change";
                                    //results.Status = 1;
                                    foreach (var item in availRes?.PriceVerification.HotelRooms)
                                    {
                                        roomResult.TotalSellPrice = Math.Round((double)item.RoomRate.TotalFare * ProviderExcahngeRate, 3);
                                        roomResult.CostPrice      = (double)item.RoomRate.TotalFare;
                                        //results.TotalCost += roomResult.TotalSellPrice; //Math.Round((double)item.RoomRate.TotalFare * ProviderExcahngeRate, 3);
                                        roomResult.RoomIndex = item.RoomIndex;
                                        //results.Result.Add(roomResult);

                                        //update Rooms obj with new price
                                        Rooms.rooms.FirstOrDefault(r => r.RoomCode == item.RoomIndex.ToString()).costPrice = (double)item.RoomRate.TotalFare;
                                        Rooms.rooms.FirstOrDefault(r => r.RoomCode == item.RoomIndex.ToString()).SellPrice = Math.Round((double)item.RoomRate.TotalFare * ProviderExcahngeRate, 3);

                                        // update price in search db
                                        // update tbo new rooms prices
                                        SearchRoomResult Newroom = new SearchRoomResult();
                                        Newroom           = searchDB.SearchRoomResults.FirstOrDefault(room => room.sID == sid && room.RoomCode == item.RoomIndex.ToString());
                                        Newroom.costPrice = (double)item.RoomRate.TotalFare;
                                        Newroom.rateClass = item.RoomRate.RoomFare.ToString();
                                        Newroom.rateType  = item.RoomRate.RoomTax.ToString();
                                        Newroom.SellPrice = roomResult.TotalSellPrice;

                                        searchDB.SaveChanges();
                                    }
                                }
                                else
                                {
                                    Rooms.Status  = 0;
                                    Rooms.Message = "No Price Change";
                                }

                                Rooms.TBoRooms.Add(roomResult);
                            }
                        }
                        #endregion
                        LoggingHelper.WriteToFile("HotelRoomsController/GetRoomsOFHotel/", "SearchController" + "OutController" + sid, "RoomsResult", JsonConvert.SerializeObject(Rooms));

                        return(Ok(Rooms));
                    }
                }
                return(Ok("No Result Found"));
            }
            catch (Exception ex)
            {
                LoggingHelper.WriteToFile("HotelRoomsController/Errors/", "SearchController" + "INController" + sid, "Exception", ex.InnerException?.Message + ex.Message + ex.StackTrace);

                return(BadRequest(ex.Message));
            }
        }