コード例 #1
0
        public static void LogSearchProviderRsp(HotelSearchResponse SearchRsp, string SearchId, string time)
        {
            string path = MainPath + @"\TBOLogs\" + DateTime.UtcNow.Date.ToString("dd_MM_yyyy") + @"\" + SearchId + @"\SearchResponse\";

            Directory.CreateDirectory(path);
            path = path + "HotelSearchResponse.txt";
            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer(SearchRsp.GetType());
                using (StreamWriter streamwriter = new StreamWriter(path, append: false))
                {
                    streamwriter.WriteLine($"Response Time is {time}");
                    streamwriter.WriteLine("");
                    xmlSerializer.Serialize(streamwriter, SearchRsp);
                    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);
            }
        }
コード例 #2
0
        public static HotelSearchResponse Search(HotelSearchRequest req, string SID)
        {
            var UName = ConfigurationSettings.AppSettings["TBOUserName"];
            var UPass = ConfigurationSettings.AppSettings["TBOPassword"];

            IHotelService proxy = TBOCredentials.CreateProxy();

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

            ProviderLogger.LogSearchProviderReq(req, SID);

            HotelSearchResponse resp      = new HotelSearchResponse();
            Stopwatch           stopWatch = new Stopwatch();

            stopWatch.Start();
            resp = proxy.HotelSearch(req);


            stopWatch.Stop();
            TimeSpan ts1 = stopWatch.Elapsed;

            ProviderLogger.LogSearchProviderRsp(resp, SID, ts1.ToString());

            return(resp);
        }
コード例 #3
0
 public ProviderManager()
 {
     searchData          = new SearchData();
     SMRResult           = new List <SearchOutputData>();
     HotelSearchResults  = new List <HotelSearchResult>();
     searchResponse      = new HotelSearchResponse();
     hotelChannelResults = new List <HotelChannelResult>();
 }
コード例 #4
0
        public HotelSearchResponse GetDataBySession(SearchData searchData)
        {
            try
            {
                #region Hotelbeds pid 5
                HotelSearchResponse hotelsSearch = new HotelSearchResponse();
                HotelRepo           repo         = new HotelRepo();
                hotelsDBEntities    dbh          = new hotelsDBEntities();

                using (SearchDBEntities db = new SearchDBEntities())
                {
                    int duration     = Convert.ToInt32((searchData.DateTo - searchData.DateFrom).TotalDays);
                    var HotelResults = db.SearchHotelResults.Where(a => a.sID == searchData.sID).ToList();
                    var providers    = HotelResults.GroupBy(x => x.ProviderID).Select(x => x.FirstOrDefault()).Select(a => a.ProviderID.Value).ToList();

                    var hotelIds = HotelResults.Select(a => a.HotelCode).ToList();

                    //List<HotelDetails> HotelDataList = repo.GetHotelData(hotelIds, "4");///
                    List <HotelDetails> HotelDataList = new List <HotelDetails>();
                    hotelsSearch.CheckIn  = searchData.DateFrom;
                    hotelsSearch.CheckOut = searchData.DateTo;

                    using (var _TBOContext = new TBOContext())
                    {
                        List <Image> imagesdata = (from i in _TBOContext.HotelImages

                                                   //  join i in dbh.HotelsImages on h.hotelID equals i.HotelID
                                                   where hotelIds.Contains(i.HotelCode)
                                                   select new Image()
                        {
                            Thum = i.URL,
                            HotelId = i.HotelCode,
                            Category = "",
                            Url = i.URL
                        }).ToList();

                        //List<HotelsAmenity> imagesdata = (from i in _TBOContext.Facilities

                        //                              //  join i in dbh.HotelsImages on h.hotelID equals i.HotelID
                        //                          where hotelIds.Contains(i.HotelCode)
                        //                          select new Image()
                        //                          {


                        //                          }).ToList();

                        /*     List<HotelAmenity> amenties = (from h in dbh.hotels
                         *
                         *                                  join A in dbh.HotelsAmenities on h.hotelID equals A.hotelID
                         *                                  where hotelIds.Contains(h.hotelID)
                         *                                  select new HotelAmenity()
                         *                                  {
                         *                                      Amenity = A.amenitie,
                         *                                      HotelCode = h.hotelID,
                         *                                      status = A.Status
                         *                                  }).ToList();*/
                        var list = (from h in _TBOContext.HotelDetails

                                    where hotelIds.Contains(h.HotelCode)
                                    select new HotelDetails()
                        {
                            ID = h.HotelDetailId,
                            HotelId = h.HotelCode,
                            Address = h.Address,
                            Rating = h.HotelRating,
                            HotelName = h.HotelName,
                            Zipcode = h.PinCode,
                            //ProviderHotelId = h.h,
                            //  ProviderID = p.providerID,
                            Location = h.HotelLocation,
                            ShortDescription = h.Description,
                            LongDescriptin = h.Description,
                            City = h.CityName,
                            Country = h.CountryName,
                            //Lat = h.,
                            //Lng = h.,
                            Location1 = h.HotelLocation,
                            Location2 = h.HotelLocation,
                            Location3 = h.HotelLocation


                                        //{ images.Where(a => a.HotelId == h.hotelID).ToList() }
                        }).Distinct().ToList();

                        /*    foreach (var item in list)
                         *  {
                         *      List<HotelAmenity> ams = new List<HotelAmenity>();
                         *      var hotelAmenities = amenties.Where(a => a.HotelCode == item.HotelId).Distinct().ToList();
                         *      foreach (var am in hotelAmenities)
                         *      {
                         *
                         *          am.Amenity = am.Amenity.Replace(" ", String.Empty);
                         *          if (ams.FirstOrDefault(x => x.Amenity == am.Amenity) == null)
                         *          {
                         *              ams.Add(am);
                         *          }
                         *      }
                         *      item.hotelAmenities = ams;
                         *  }*/
                        var stars = new List <string> {
                            "OneStar", "TwoStar", "ThreeStar", "FourStar", "FiveStar"
                        };

                        list.ForEach(a => a.Images = imagesdata.Where(h => h.HotelId == a.HotelId).ToList());
                        HotelDataList.AddRange(list);
                        foreach (var item in HotelResults)
                        {
                            HotelSearchResult hotel     = new HotelSearchResult();
                            HotelDetails      hotelData = HotelDataList.Where(a => a.HotelId == item.HotelCode).FirstOrDefault();

                            if (hotelData != null)
                            {
                                hotel.providerHotelCode = item.ProviderHotelCode;
                                hotel.City      = hotelData.City;
                                hotel.hotelName = hotelData.HotelName;

                                hotel.Country    = hotelData.Country;
                                hotel.hotelStars = stars.IndexOf(hotelData.Rating);
                                var images = hotelData.Images.FirstOrDefault();
                                if (images != null)
                                {
                                    hotel.hotelThumb = images.Thum;
                                }
                                //***   hotel.hotelImages = hotelData.Images.Select(a => a.Url).ToList();
                                //**     hotel.Amenities = hotelData.hotelAmenities;
                                hotel.Lat                      = hotelData.Lat ?? "";
                                hotel.Lng                      = hotelData.Lng ?? "";
                                hotel.providerID               = item.ProviderID.Value.ToString();
                                hotel.hotelDescription         = hotelData.LongDescriptin;
                                hotel.shortcutHotelDescription = hotelData.ShortDescription;
                                hotel.ZipCode                  = hotelData.Zipcode ?? "";
                                hotel.Location                 = hotelData.Location;
                                hotel.Address                  = hotelData.Address;
                                hotel.providerHotelID          = item.ProviderHotelId;
                                hotel.hotelCode                = hotelData.HotelId;
                                hotel.sellCurrency             = searchData.Currency;

                                hotel.hotelRate      = item.SellPrice.Value / duration;
                                hotel.costPrice      = item.CostPrice.Value;
                                hotel.TotalSellPrice = item.SellPrice.Value;
                                hotel.rooms          = new List <RoomResult>();
                                hotelsSearch.HotelResult.Add(hotel);
                            }
                        }
                    }
                }
                hotelsSearch.Locations = hotelsSearch.HotelResult.GroupBy(x => x.Location).Select(x => x.FirstOrDefault()).Select(a => a.Location).ToList();

                return(hotelsSearch);

                #endregion
            }catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #5
0
        public HotelSearchResponse GetHotels(HotelSearchRequest objRequest)
        {
            MarketPropertyContent      objMarketPropertyContent = null;
            List <PropertyRoomContent> lstPropertyRoomContent   = new List <PropertyRoomContent>();
            PropertyRoomContent        objPropertyRoomContent;
            var objHotelSearchResponse = new HotelSearchResponse();

            try
            {
                var SiteBaseUrl           = ConfigurationManager.AppSettings["SiteBaseUrl"].ToString();
                var objHotelSearchRequest = new Model.ServiceModel.HotelSearchRequest.HotelSearchRequest();
                objHotelSearchRequest.request        = new Model.ServiceModel.HotelSearchRequest.Request();
                objHotelSearchRequest.request.__type = "SearchRequest";
                objHotelSearchRequest.request.AppKey = "IAPTestWebsite";

                objHotelSearchRequest.request.Criteria        = new Model.ServiceModel.HotelSearchRequest.Criteria();
                objHotelSearchRequest.request.Criteria.__type = "HotelCriteria";

                if (!string.IsNullOrEmpty(objRequest.Market))
                {
                    var lstMarkets = _iCategryService.GetMarkets();
                    var objMarket  = lstMarkets.Where(item => item.Description.ToLower().Contains(objRequest.Market.ToLower())).FirstOrDefault();

                    if (objMarket != null)
                    {
                        string[] locations = new string[objMarket.BranchList.Count];
                        for (int i = 0; i < objMarket.BranchList.Count; i++)
                        {
                            locations[i] = objMarket.BranchList[i].Code;
                        }
                        objHotelSearchRequest.request.Criteria.Locations = locations;

                        //Need to change this based on the design
                        //objMarketPropertyContent=_iMarketingService.GetMarketPropertyContents(objMarket.Code);

                        //foreach(var item in objMarketPropertyContent.PropertyContents)
                        //{
                        //    objPropertyRoomContent = _iMarketingService.GetPropertyRoomContents(item.PropertyCode);
                        //    lstPropertyRoomContent.Add(objPropertyRoomContent);
                        //}
                    }
                    else
                    {
                        return(objHotelSearchResponse);
                    }
                }
                else if (!string.IsNullOrEmpty(objRequest.Property))
                {
                    string[] locations   = new string[1];
                    var      lstBranches = _iCategryService.GetBranches();
                    if (objRequest.Property.Length == 3)
                    {
                        var objBranch = lstBranches.Where(item => item.Code.ToLower() == objRequest.Property.ToLower()).FirstOrDefault();

                        if (objBranch != null)
                        {
                            locations[0] = objBranch.Code;
                            //Need to change this based on the design
                            //objPropertyRoomContent = _iMarketingService.GetPropertyRoomContents(objBranch.Code);
                            //lstPropertyRoomContent.Add(objPropertyRoomContent);
                        }
                        else
                        {
                            objBranch = lstBranches.Where(item => item.Name.ToLower() == objRequest.Property.ToLower()).FirstOrDefault();
                            if (objBranch != null)
                            {
                                locations[0] = objBranch.Code;
                            }
                            else
                            {
                                return(objHotelSearchResponse);
                            }
                        }
                    }
                    else
                    {
                        var objBranch = lstBranches.Where(item => item.Name.ToLower().Contains(objRequest.Property.ToLower())).FirstOrDefault();

                        if (objBranch != null)
                        {
                            locations[0] = objBranch.Code;
                            //Need to change this based on the design
                            //objPropertyRoomContent = _iMarketingService.GetPropertyRoomContents(objBranch.Code);
                            //lstPropertyRoomContent.Add(objPropertyRoomContent);
                        }
                        else
                        {
                            return(objHotelSearchResponse);
                        }
                    }
                    objHotelSearchRequest.request.Criteria.Locations = locations;
                }
                objHotelSearchRequest.request.Criteria.EndDate                      = objRequest.CheckoutDate.ToString("yyyy-MM-dd");
                objHotelSearchRequest.request.Criteria.HotelRoomDetails             = new Model.ServiceModel.HotelSearchRequest.Hotelroomdetail[1];
                objHotelSearchRequest.request.Criteria.HotelRoomDetails[0]          = new Model.ServiceModel.HotelSearchRequest.Hotelroomdetail();
                objHotelSearchRequest.request.Criteria.HotelRoomDetails[0].Adults   = 2;
                objHotelSearchRequest.request.Criteria.HotelRoomDetails[0].Children = 0;
                objHotelSearchRequest.request.Criteria.HotelRoomDetails[0].__type   = "HotelRoomDetail";
                objHotelSearchRequest.request.Criteria.LengthOfStays                = new int[1];
                objHotelSearchRequest.request.Criteria.LengthOfStays[0]             = (objRequest.CheckoutDate - objRequest.CheckinDate).Days;
                objHotelSearchRequest.request.Criteria.StartDate                    = objRequest.CheckinDate.ToString("yyyy-MM-dd");
                objHotelSearchRequest.request.GroupCode                     = "";
                objHotelSearchRequest.request.Requestor                     = "Galaxy Test Harness";
                objHotelSearchRequest.request.SecurityToken                 = "";
                objHotelSearchRequest.request.SelectionAttributes           = new Model.ServiceModel.HotelSearchRequest.Selectionattribute[1];
                objHotelSearchRequest.request.SelectionAttributes[0]        = new Model.ServiceModel.HotelSearchRequest.Selectionattribute();
                objHotelSearchRequest.request.SelectionAttributes[0].__type = "Attr";
                objHotelSearchRequest.request.SelectionAttributes[0].Id     = 0;
                objHotelSearchRequest.request.SelectionAttributes[0].Name   = "pruning";
                objHotelSearchRequest.request.SelectionAttributes[0].Value  = "LowestPromoAndAllOtherQuotes";
                objHotelSearchRequest.request.TransactionStartTime          = DateTime.UtcNow;

                var response = ServiceBridge <Model.ServiceModel.HotelSearchRequest.HotelSearchRequest, Model.ServiceModel.HotelSearchResponse.HotelSearchResponse> .Run(objHotelSearchRequest, ServiceTypes.HotelSearch, HttpMethod.Post);

                objHotelSearchResponse.properties = new List <Property>();
                Property objProperty;
                Room     objRoom;
                if (response != null)
                {
                    foreach (var productType in response.ProductTypes)
                    {
                        foreach (var product in productType.Products)
                        {
                            objProperty      = new Property();
                            objProperty.Name = product.Name;

                            if (objMarketPropertyContent != null)
                            {
                                var ojPropertyContent = objMarketPropertyContent.PropertyContents.Where(p => p.PropertyName == product.Name).FirstOrDefault();
                                if (ojPropertyContent != null)
                                {
                                    objProperty.Summary  = ojPropertyContent.Summary;
                                    objProperty.ImageUrl = ojPropertyContent.ImageUrl;
                                }
                            }
                            //Need to change this based on the design
                            objPropertyRoomContent = _iMarketingService.GetPropertyRoomContents(product.Location.Code);
                            lstPropertyRoomContent.Add(objPropertyRoomContent);

                            var lstRoomContents = lstPropertyRoomContent.Where(p => p.PropertyName == product.Name).FirstOrDefault();
                            objProperty.Rooms = new List <Room>();
                            foreach (var sku in product.SKUs)
                            {
                                objRoom      = new Room();
                                objRoom.Name = sku.Name;
                                if (sku.Quotes[0] != null)
                                {
                                    objRoom.AvgRate = sku.Quotes[0].Avg;
                                }
                                var objRoomContent = lstRoomContents.RoomContents.Where(r => r.Name == sku.Name).FirstOrDefault();

                                if (objRoomContent != null)
                                {
                                    objRoom.Summary  = objRoomContent.Summary;
                                    objRoom.ImageUrl = SiteBaseUrl + objRoomContent.ImageUrl;
                                }

                                objProperty.Rooms.Add(objRoom);
                            }

                            objHotelSearchResponse.properties.Add(objProperty);
                            break;
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(objHotelSearchResponse);
        }
コード例 #6
0
        // map rooms ??????!!!!!!!!!!!!!!
        public HotelSearchResponse MapSearchResult(List <Hotel> searchOutputs, SearchData searchData)
        {
            try
            {
                //save result
                //apply salesRules
                HotelSearchResponse searchResponse            = new HotelSearchResponse();
                CurrencyManager     currencyManager           = new CurrencyManager();
                SalesRulesManager   ServiceChargeManager      = new SalesRulesManager();
                SalesRulesManager   CancellationChargeManager = new SalesRulesManager();
                var BaseCur = ConfigurationSettings.AppSettings["BaseCur"];

                //start sales rules service charge
                ServiceChargeManager.FillSalesRules(searchData.POS, "Hotel", "Service Charge"); //1
                ServiceChargeManager.PrepareSearchCriteriaDic(searchData);                      //2
                ////
                ///cancellation charge
                CancellationChargeManager.FillSalesRules(searchData.POS, "Hotel", "Cancellation Charge");
                CancellationChargeManager.PrepareSearchCriteriaDic(searchData);
                //

                List <string>            hotelIds      = searchOutputs.Select(a => a.code.ToString()).ToList();
                HotelManager             manager       = new HotelManager();
                List <HotelDetails>      HotelDataList = manager.GetHotelData(hotelIds, "4");
                List <HotelSearchResult> results       = new List <HotelSearchResult>();
                double ProviderExcahngeRate            = currencyManager.GetCurrencyConversion(searchOutputs[0].currency, BaseCur, searchData.sID);
                ////////////double ProviderExcahngeRate = currencyManager.GetCurrencyConversion("EUR", BaseCur);/////MG
                double ExcahngeRate = currencyManager.GetCurrencyConversion(BaseCur, searchData.Currency, searchData.sID);
                //  searchResponse.Locations = HotelDataList.GroupBy(x => x.Location).Select(x => x.FirstOrDefault()).Select(a=>a.Location).ToList();

                int duration = Convert.ToInt32((searchData.DateTo - searchData.DateFrom).TotalDays);
                {
                    DateTime CheckInDate = searchData.DateFrom;
                    for (int i = 0; i < searchOutputs.Count; i++)
                    {
                        HotelDetails      hotelData = HotelDataList.Where(a => a.ProviderHotelId == searchOutputs[i].code.ToString()).FirstOrDefault();
                        HotelSearchResult hotel     = new HotelSearchResult();
                        if (hotelData != null)
                        {
                            hotel.providerHotelCode = searchOutputs[i].code.ToString();
                            hotel.City      = hotelData.City;
                            hotel.hotelName = hotelData.HotelName;

                            hotel.Country    = hotelData.Country;
                            hotel.hotelStars = int.Parse(hotelData.Rating);
                            var images = hotelData.Images.FirstOrDefault();
                            if (images != null)
                            {
                                hotel.hotelThumb = images.Thum;
                            }
                            //***    hotel.hotelImages = hotelData.Images.Select(a => a.Url).ToList();
                            hotel.Amenities                = hotelData.hotelAmenities;
                            hotel.Lat                      = hotelData.Lat;
                            hotel.Lng                      = hotelData.Lng;
                            hotel.providerID               = "4";
                            hotel.hotelDescription         = hotelData.LongDescriptin;
                            hotel.shortcutHotelDescription = hotelData.ShortDescription;
                            hotel.ZipCode                  = hotelData.Zipcode;
                            hotel.Location                 = hotelData.Location;
                            hotel.Address                  = hotelData.Address;
                            hotel.providerHotelID          = hotelData.ProviderHotelId;
                            hotel.hotelCode                = hotelData.HotelId;
                            hotel.sellCurrency             = searchData.Currency;

                            hotel.costCurrency = searchOutputs[i].currency;
                            //set sales rules cirtiera
                            //  hotel.hotelRate = ((hotel.costPrice)+ AppliedMarkup.Value-AppliedDiscount.Value)* ExcahngeRate;

                            hotel.rooms = new List <RoomResult>();

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

                            for (int j = 0; j < searchOutputs[i].rooms.Count; j++)
                            {
                                for (int x = 0; x < searchOutputs[i].rooms[j].rates.Count; x++)
                                {
                                    RoomResult room = new RoomResult();

                                    if (searchOutputs[i].rooms[j].rates[x].net == null)
                                    {
                                        continue;
                                    }
                                    room.CostPrice  = Math.Round(double.Parse(searchOutputs[i].rooms[j].rates[x].net), 3);
                                    hotel.costPrice = room.CostPrice;
                                    CancellationChargeManager.SetResultCriteria(hotel.hotelName, hotel.hotelStars, hotel.costPrice, "4");
                                    ServiceChargeManager.SetResultCriteria(hotel.hotelName, hotel.hotelStars, room.CostPrice
                                                                           * ProviderExcahngeRate, "4");
                                    AppliedSalesRule AppliedMarkup   = ServiceChargeManager.ApplySalesRules("Markup");
                                    AppliedSalesRule AppliedDiscount = ServiceChargeManager.ApplySalesRules("Discount");

                                    //  room.IsRefundable = searchOutputs[i].rooms[j].refundable;
                                    ////******
                                    room.RatePerNight = ((room.CostPrice * ProviderExcahngeRate / duration) + AppliedMarkup.Value - AppliedDiscount.Value) * ExcahngeRate;
                                    room.RatePerNight = Math.Round(room.RatePerNight, 3);

                                    room.TotalSellPrice = Math.Round(room.RatePerNight * duration, 3);

                                    room.RoomIndex     = j + 1;                                      // index front use
                                    room.RoomReference = searchOutputs[i].rooms[j].rates[x].rateKey; // reference of provider
                                    /////
                                    room.RoomCode = searchOutputs[i].rooms[j].code;
                                    /////////
                                    room.RoomType = searchOutputs[i].rooms[j].name; // standard or double
                                    ///////
                                    room.RoomMeal     = searchOutputs[i].rooms[j].rates[x].boardName;
                                    room.Adult        = searchOutputs[i].rooms[j].rates[x].adults;
                                    room.Child        = searchOutputs[i].rooms[j].rates[x].children;
                                    room.IsRefundable = searchOutputs[i].rooms[j].rates[x].rateClass == "NRF"?false:true;

                                    ///////
                                    room.Paxs = searchOutputs[i].rooms[j].rates[x].adults + searchOutputs[i].rooms[j].rates[x].children;
                                    //***   room.Images = hotelData.Images.Where(a => a.Category.ToLower() == "hotel rooms").Select(a => a.Url).ToList();
                                    room.DiscountId        = AppliedDiscount.ID;
                                    room.MarkupId          = AppliedMarkup.ID;
                                    room.DiscountValue     = AppliedDiscount.Value * ExcahngeRate;
                                    room.MarkupValue       = AppliedMarkup.Value * ExcahngeRate;
                                    room.rateClass         = searchOutputs[i].rooms[j].rates[x].rateClass;
                                    room.rateType          = searchOutputs[i].rooms[j].rates[x].rateType;
                                    room.childrenAges      = searchOutputs[i].rooms[j].rates[x].childrenAges;
                                    room.paymentType       = searchOutputs[i].rooms[j].rates[x].paymentType;
                                    room.boardCode         = searchOutputs[i].rooms[j].rates[x].boardCode;
                                    room.cancellationRules = searchOutputs[i].rooms[j].rates[x].cancellationPolicies == null ?
                                                             new List <CancellationRule>()
                                    {
                                        new CancellationRule
                                        {
                                            Cost = 0, Price = 0, CanellationRuleText = null, FromDate = null, ToDate = null
                                        }
                                    } :
                                    searchOutputs[i].rooms[j].rates[x].cancellationPolicies.Select(a => new CancellationRule
                                    {
                                        Price = Math.Round(((double.Parse(a.amount) * ProviderExcahngeRate) + AppliedCancellationMarkup.Value) * ExcahngeRate, 3),
                                        CanellationRuleText = searchData.Lang.ToLower() == "en" ? Math.Round(((double.Parse(a.amount) * ProviderExcahngeRate) + AppliedCancellationMarkup.Value) * ExcahngeRate, 3) + "" + searchData.Currency + " To " + a.from : a.from + " إلى " + "" + searchData.Currency + Math.Round(((double.Parse(a.amount) * ProviderExcahngeRate) /*+ AppliedCancellationMarkup.Value*/) * ExcahngeRate, 3),
                                        Cost     = Math.Round(double.Parse(a.amount)),
                                        FromDate = a.from.ToString()
                                    }).ToList();
                                    hotel.rooms.Add(room);
                                }
                            }

                            var minRoom = hotel.rooms.Where(a => a.RatePerNight == hotel.rooms.Min(x => x.RatePerNight)).FirstOrDefault();
                            if (minRoom != null)
                            {
                                hotel.hotelRate      = minRoom.RatePerNight;
                                hotel.costPrice      = minRoom.CostPrice;
                                hotel.TotalSellPrice = minRoom.TotalSellPrice;
                                hotel.MarkupId       = minRoom.MarkupId;
                                hotel.MarkupValue    = minRoom.MarkupValue;
                                hotel.DiscountId     = minRoom.DiscountId;
                                hotel.DiscountValue  = minRoom.DiscountValue;
                            }
                            results.Add(hotel);
                        }
                    }

                    searchResponse.HotelResult = results;
                    return(searchResponse);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.WriteToFile("MapSearchResult/Errors/", "MapSearchResult_" + searchData.sID, ex.Message, ex.Message + " Sourse :" + ex.Source + " Stack Trace :" + ex.StackTrace);
                return(new HotelSearchResponse());
            }
        }
コード例 #7
0
        public HotelSearchResponse GetSearchResult(SearchData searchData)
        {
            try
            {
                var tasks        = new List <Task>();
                var tokenSource1 = new CancellationTokenSource();
                var tokenSource2 = new CancellationTokenSource();
                List <HotelSearchResult> searchResults  = new List <HotelSearchResult>();
                HotelSearchResponse      searchResponse = new HotelSearchResponse();
                SessionManager           sessionManager = new SessionManager();

                // add validation
                if (!ValidateSearchData(searchData))
                {
                    searchResponse.Status = 1; // invalid data
                    return(searchResponse);
                }

                // sure if session vaild ********
                if (sessionManager.ValidSession(searchData))
                {
                    // get hotel data From DB
                    SessionRepo sessionRepo = new SessionRepo();
                    var         HotelSRes   = sessionRepo.GetDataBySession(searchData);
                    if (HotelSRes != null)
                    {
                        return(HotelSRes);
                    }
                    return(null);
                }

                //MG data not found in db new SID
                searchData = PrepareSearchData(searchData);
                if (searchData != null)
                {
                    using (ProviderManager pm = new ProviderManager())
                    {
                        pm.searchData = searchData;
                        pm.GetHotelSearchResultForAllProviders();
                        //  searchResults = pm.HotelSearchResults;
                        //  searchResults = GetLowestPrice(searchResults);
                        searchResponse = pm.searchResponse;
                        //searchResults = GetLowestPrice(searchResponse.HotelResult);
                        searchResults = searchResponse.HotelResult;

                        searchResponse.HotelResult = searchResults;
                        searchResponse.Locations   = searchResponse.HotelResult.GroupBy(x => x.Location).Select(x => x.FirstOrDefault()).Select(a => a.Location).ToList();

                        tasks.Add(Task.Factory.StartNew(() =>
                        {
                            if (searchResults.Count > 0)
                            {
                                SaveSearchResult(searchResults, searchData.sID);/////////////////
                            }
                        }, tokenSource1.Token));
                        Task.WaitAll(tasks.ToArray());
                    }
                }
                return(searchResponse);
            }
            catch (HotelSearchInputException EX)
            {
                return(new HotelSearchResponse()
                {
                    Status = 1,  //"Invalid"
                    ResultException = new ResultException()
                    {
                        Code = EX.Code,
                        ExceptionMessage = EX.Message
                    }
                });
            }
            catch (Exception ex)
            {
                LoggingHelper.WriteToFile("SearchController/Errors/", "SearchController" + "INServOrch" + searchData.sID, ex.InnerException?.Message, ex.Message + ex.StackTrace);
                return(new HotelSearchResponse());
            }
        }
コード例 #8
0
        public HotelSearchResponse MapSearchResult(List <PropertyResult> searchOutputs, SearchData searchData)
        {
            try
            {
                //    var json = new JavaScriptSerializer().Serialize(obj);
                //save result
                //apply salesRules
                HotelSearchResponse searchResponse            = new HotelSearchResponse();
                CurrencyManager     currencyManager           = new CurrencyManager();
                SalesRulesManager   ServiceChargeManager      = new SalesRulesManager();
                SalesRulesManager   CancellationChargeManager = new SalesRulesManager();

                //start sales rules service charge
                ServiceChargeManager.FillSalesRules(searchData.POS, "Hotel", "Service Charge");
                ServiceChargeManager.PrepareSearchCriteriaDic(searchData);
                ////
                /////cancellation charge
                CancellationChargeManager.FillSalesRules(searchData.POS, "Hotel", "Cancellation Charge");
                CancellationChargeManager.PrepareSearchCriteriaDic(searchData);
                //
                var BaseCur = ConfigurationSettings.AppSettings["BaseCur"];

                List <string>            hotelIds      = searchOutputs.Select(a => a.PropertyReferenceID).ToList();
                HotelManager             manager       = new HotelManager();
                List <HotelDetails>      HotelDataList = manager.GetHotelData(hotelIds, "2");
                List <HotelSearchResult> results       = new List <HotelSearchResult>();
                /////double ProviderExcahngeRate = currencyManager.GetCurrencyConversion("USD", BaseCur);
                double ProviderExcahngeRate = currencyManager.GetCurrencyConversion(searchData.Currency, BaseCur, searchData.sID);
                double ExcahngeRate         = currencyManager.GetCurrencyConversion(BaseCur, searchData.Currency, searchData.sID);
                //  searchResponse.Locations = HotelDataList.GroupBy(x => x.Location).Select(x => x.FirstOrDefault()).Select(a => a.Location).ToList();

                int duration = Convert.ToInt32((searchData.DateTo - searchData.DateFrom).TotalDays);
                {
                    DateTime CheckInDate = searchData.DateFrom;
                    for (int i = 0; i < searchOutputs.Count; i++)
                    {
                        HotelDetails      hotelData = HotelDataList.Where(a => a.ProviderHotelId == searchOutputs[i].PropertyReferenceID.ToString()).FirstOrDefault();
                        HotelSearchResult hotel     = new HotelSearchResult();
                        if (hotelData != null)
                        {
                            hotel.providerHotelCode = searchOutputs[i].PropertyID.ToString();
                            hotel.City       = hotelData.City;
                            hotel.hotelName  = hotelData.HotelName;
                            hotel.Country    = hotelData.Country;
                            hotel.hotelStars = int.Parse(hotelData.Rating) > 0 ? int.Parse(hotelData.Rating) - 558 : 0;
                            var images = hotelData.Images.FirstOrDefault();
                            if (images != null)
                            {
                                hotel.hotelThumb = images.Thum;
                            }
                            hotel.hotelImages              = hotelData.Images.Select(a => a.Thum).ToList();
                            hotel.Amenities                = hotelData.hotelAmenities;
                            hotel.Lat                      = hotelData.Lat;
                            hotel.Lng                      = hotelData.Lng;
                            hotel.providerID               = "2";
                            hotel.hotelDescription         = hotelData.LongDescriptin;
                            hotel.shortcutHotelDescription = hotelData.ShortDescription;
                            hotel.ZipCode                  = hotelData.Zipcode;
                            hotel.Location                 = hotelData.Location;
                            hotel.Address                  = hotelData.Address;
                            hotel.providerHotelID          = hotelData.ProviderHotelId;
                            hotel.hotelCode                = hotelData.HotelId;
                            hotel.sellCurrency             = searchData.Currency;
                            //  hotel.costPrice =//Math.Round( (double.Parse(searchOutputs[i].price.net.Value.ToString()) * ProviderExcahngeRate) /duration,3);
                            hotel.costCurrency = "USD";
                            //set sales rules cirtiera
                            //  hotel.hotelRate = ((hotel.costPrice)+ AppliedMarkup.Value-AppliedDiscount.Value)* ExcahngeRate;

                            hotel.rooms = new List <RoomResult>();
                            CancellationChargeManager.SetResultCriteria(hotel.hotelName, hotel.hotelStars, hotel.costPrice, "4");
                            AppliedSalesRule AppliedCancellationMarkup = CancellationChargeManager.ApplySalesRules("Markup");

                            for (int j = 0; j < searchOutputs[i].RoomTypes.RoomType.Count; j++)
                            {
                                RoomResult room = new RoomResult();

                                room.CostPrice = Math.Round(double.Parse(searchOutputs[i].RoomTypes.RoomType[j].Total), 3);

                                ServiceChargeManager.SetResultCriteria(hotel.hotelName, hotel.hotelStars, room.CostPrice
                                                                       * ProviderExcahngeRate, "2");
                                AppliedSalesRule AppliedMarkup   = ServiceChargeManager.ApplySalesRules("Markup");
                                AppliedSalesRule AppliedDiscount = ServiceChargeManager.ApplySalesRules("Discount");

                                //  room.IsRefundable = searchOutputs[i].rooms[j].refundable;
                                ////******
                                room.RatePerNight = ((room.CostPrice * ProviderExcahngeRate / duration) + AppliedMarkup.Value - AppliedDiscount.Value) * ExcahngeRate;
                                room.RatePerNight = Math.Round(room.RatePerNight, 3);

                                room.TotalSellPrice = Math.Round(room.RatePerNight * duration, 3);
                                room.RoomIndex      = j + 1;
                                room.RoomReference  = searchOutputs[i].RoomTypes.RoomType[j].PropertyRoomTypeID;
                                /////
                                room.RoomCode = searchOutputs[i].RoomTypes.RoomType[j].Seq;    //
                                /////////
                                room.RoomType     = searchOutputs[i].RoomTypes.RoomType[j].RoomTyper;
                                room.IsRefundable = searchOutputs[i].RoomTypes.RoomType[j].RoomTyper.Contains("Non-Refundable") || searchOutputs[i].RoomTypes.RoomType[j].RoomTyper.Contains("Non Refundable")?false:true;
                                room.MealID       = searchOutputs[i].RoomTypes.RoomType[j].MealBasisID;
                                ///////
                                room.RoomMeal     = searchOutputs[i].RoomTypes.RoomType[j].MealBasis;
                                room.Adult        = int.Parse(searchOutputs[i].RoomTypes.RoomType[j].Adults);
                                room.Child        = int.Parse(searchOutputs[i].RoomTypes.RoomType[j].Children);
                                room.BookingKeyTS = searchOutputs[i].RoomTypes.RoomType[j].BookingToken;
                                ///////
                                room.Paxs              = int.Parse(searchOutputs[i].RoomTypes.RoomType[j].Adults) + int.Parse(searchOutputs[i].RoomTypes.RoomType[j].Children);
                                room.Images            = hotelData.Images.Where(a => a.Category.ToLower() == "hotel rooms").Select(a => a.Thum).ToList();
                                room.DiscountId        = AppliedDiscount.ID;
                                room.MarkupId          = AppliedMarkup.ID;
                                room.DiscountValue     = AppliedDiscount.Value * ExcahngeRate;
                                room.MarkupValue       = AppliedMarkup.Value * ExcahngeRate;
                                room.cancellationRules = null;

                                /* room.cancellationRules = searchOutputs[i].rooms[j].rates[x].cancellationPolicies == null ? new List<CancellationRule>() { new CancellationRule { Cost = Math.Round((AppliedCancellationMarkup.Value) * ExcahngeRate, 3) } } :
                                 * searchOutputs[i].rooms[j].rates[x].cancellationPolicies.Select(a => new CancellationRule
                                 * {
                                 *
                                 *   Cost = Math.Round(((double.Parse(a.amount) * ProviderExcahngeRate) + AppliedCancellationMarkup.Value) * ExcahngeRate, 3),
                                 *   CanellationRuleText = searchData.Lang.ToLower() == "en" ? Math.Round(((double.Parse(a.amount) * ProviderExcahngeRate) + AppliedCancellationMarkup.Value) * ExcahngeRate, 3) + "" + searchData.Currency + " To " + a.from : a.from + " إلى " + "" + searchData.Currency + Math.Round(((double.Parse(a.amount) * ProviderExcahngeRate) + AppliedCancellationMarkup.Value) * ExcahngeRate, 3)
                                 * }).ToList();*/
                                hotel.rooms.Add(room);
                            }

                            var minRoom = hotel.rooms.Where(a => a.RatePerNight == hotel.rooms.Min(x => x.RatePerNight)).FirstOrDefault();
                            if (minRoom != null)
                            {
                                hotel.hotelRate      = minRoom.RatePerNight;
                                hotel.costPrice      = minRoom.CostPrice;
                                hotel.TotalSellPrice = minRoom.TotalSellPrice;
                                hotel.MarkupId       = minRoom.MarkupId;
                                hotel.MarkupValue    = minRoom.MarkupValue;
                                hotel.DiscountId     = minRoom.DiscountId;
                                hotel.DiscountValue  = minRoom.DiscountValue;
                            }
                            results.Add(hotel);
                        }
                    }
                    searchResponse.HotelResult = results;
                    return(searchResponse);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.WriteToFile("SearchController/MapSearchResultTS/Errors/", "MapSearchResult_" + searchData.sID, ex.Message, ex.Message + " Sourse :" + ex.Source + " Stack Trace :" + ex.StackTrace);
                return(new HotelSearchResponse());
            }
        }