Exemplo n.º 1
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());
            }
        }
        public List <HotelChannelResult> MapSearchResult(List <Hotel> searchOutputs, SearchData searchData)
        {
            try
            {
                //save result
                //apply salesRules
                List <HotelChannelResult> searchResponse            = new List <HotelChannelResult>();
                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.GetChannelHotelData(hotelIds, "4");
                //  List<HotelSearchResult> results = new List<HotelSearchResult>();
                double ProviderExcahngeRate = currencyManager.GetCurrencyConversion(searchOutputs[0].currency, BaseCur, searchData.sID);
                /////double ProviderExcahngeRate = currencyManager.GetCurrencyConversion("EUR", BaseCur);
                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();
                        HotelChannelResult hotel     = new HotelChannelResult();
                        if (hotelData != null)
                        {
                            hotel.providerHotelCode = searchOutputs[i].code.ToString();
                            hotel.providerID        = "4";

                            hotel.providerHotelID = hotelData.ProviderHotelId;
                            hotel.hotelId         = hotelData.ID.ToString();
                            hotel.sellCurrency    = searchData.Currency;
                            //  hotel.costPrice =//Math.Round( (double.Parse(searchOutputs[i].price.net.Value.ToString()) * ProviderExcahngeRate) /duration,3);
                            hotel.costCurrency = searchOutputs[i].currency;
                            hotel.DeepLink     = "http://93.115.27.156:3030/api/WegoHotelSearch?sid=" + searchData.sID + "&hotelId=" + hotelData.HotelId + "&pid=4";
                            CancellationChargeManager.SetResultCriteria(hotelData.HotelName, int.Parse(hotelData.Rating), hotel.costPrice, "4");
                            AppliedSalesRule AppliedCancellationMarkup = CancellationChargeManager.ApplySalesRules("Markup");
                            int roomcount    = 0;
                            int Packagecount = 0;

                            for (int j = 0; j < searchOutputs[i].rooms.Count; j++)
                            {
                                if (Packagecount == 20)
                                {
                                }
                                RoomPackages            roomPackage = new RoomPackages();
                                List <ChannelRoomsRate> roomsRate   = new List <ChannelRoomsRate>();
                                roomPackage.RoomCategory = searchOutputs[i].rooms[j].name;
                                List <RoomPackage> Containers = new List <RoomPackage>();
                                for (int r = 0; r < searchData.SearchRooms.Count; r++)
                                {
                                    ChannelRoomsRate roomRate = new ChannelRoomsRate();

                                    /*  var rooms = searchOutputs[i].rooms[j].rates.GroupBy(c => new
                                     * {
                                     *    c.adults,
                                     *    c.children,
                                     * }).Select(c => c.Where(a=>a.adults== searchData.SearchRooms[r].Adult &&a.children== searchData.SearchRooms[r].Child.Count).ToList());
                                     */
                                    var rooms = searchOutputs[i].rooms[j].rates.Where(a => a.adults == searchData.SearchRooms[r].Adult && a.children == searchData.SearchRooms[r].Child.Count).GroupBy(p => p.rateKey).Select(grp => grp.FirstOrDefault()).ToList();
                                    if (rooms.Count > 0)
                                    {
                                        roomRate.RoomRates.AddRange(rooms);
                                        roomsRate.Add(roomRate);
                                    }
                                    else
                                    {
                                        var roomnames = searchOutputs[i].rooms[j].name.Split(' ');
                                        //    var key = roomnames[roomnames.Length-1];
                                        int indexToRemove = 0;
                                        roomnames = roomnames.Where((source, index) => index != indexToRemove).ToArray();
                                        var key       = string.Join(" ", roomnames);
                                        var roomstype = searchOutputs[i].rooms.Where(a => a.name.Contains(key));
                                        foreach (var item in roomstype)
                                        {
                                            var lstroom        = item.name.Split(' ');
                                            int index1ToRemove = 0;
                                            lstroom = lstroom.Where((source, index) => index != index1ToRemove).ToArray();
                                            var key1 = string.Join(" ", lstroom);
                                            if (key == key1)
                                            {
                                                var RoomsSameType = item.rates.Where(a => a.adults == searchData.SearchRooms[r].Adult && a.children == searchData.SearchRooms[r].Child.Count).GroupBy(p => p.rateKey).Select(grp => grp.FirstOrDefault()).ToList();
                                                if (RoomsSameType.Count > 0)
                                                {
                                                    roomRate.RoomRates.AddRange(RoomsSameType);
                                                    roomsRate.Add(roomRate);
                                                }
                                            }
                                        }
                                    }
                                    if (roomRate.RoomRates.Count == 0)
                                    {
                                        roomsRate = new List <ChannelRoomsRate>();
                                        break;
                                    }
                                }
                                int max = 0;
                                if (roomsRate.Count > 0)
                                {
                                    max = roomsRate.Max(r => r.RoomRates.Count);
                                }

                                for (int ra = 0; ra < max; ra++)
                                {
                                    RoomPackage Container    = new RoomPackage();
                                    double      sellPerNight = 0;
                                    double      sellPerAll   = 0;

                                    List <RoomResult> resultsPackage = new List <RoomResult>();
                                    foreach (var item in roomsRate)
                                    {
                                        int indx = ra;
                                        if (ra >= item.RoomRates.Count)
                                        {
                                            indx = item.RoomRates.Count - 1;
                                        }
                                        RoomResult room = new RoomResult();

                                        room.PackageNO = Packagecount + 1;
                                        if (item.RoomRates[indx].net == null)
                                        {
                                            continue;
                                        }
                                        room.CostPrice = Math.Round(double.Parse(item.RoomRates[indx].net), 3);

                                        ServiceChargeManager.SetResultCriteria(hotelData.HotelName, int.Parse(hotelData.Rating), 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);
                                        sellPerNight       += room.RatePerNight;
                                        room.TotalSellPrice = Math.Round(room.RatePerNight * duration, 3);
                                        sellPerAll         += room.TotalSellPrice;
                                        roomcount          += 1;
                                        room.RoomIndex      = roomcount;
                                        room.RoomReference  = item.RoomRates[indx].rateKey;
                                        /////
                                        room.RoomCode = searchOutputs[i].rooms[j].code;
                                        /////////
                                        room.RoomType = searchOutputs[i].rooms[j].name;
                                        ///////
                                        room.RoomMeal     = item.RoomRates[indx].boardName;
                                        room.Adult        = item.RoomRates[indx].adults;
                                        room.Child        = item.RoomRates[indx].children;
                                        room.IsRefundable = item.RoomRates[indx].rateClass == "NRF" ? false : true;

                                        ///////
                                        room.Paxs = item.RoomRates[indx].adults + item.RoomRates[indx].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.cancellationRules = item.RoomRates[indx].cancellationPolicies == null ? new List <CancellationRule>()
                                        {
                                            new CancellationRule {
                                                Cost = 0, Price = 0, CanellationRuleText = null, FromDate = null, ToDate = null
                                            }
                                        } :
                                        item.RoomRates[indx].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();
                                        resultsPackage.Add(room);
                                    }
                                    Container.No               = Packagecount + 1;
                                    Container.PricePerNight    = sellPerNight;
                                    Container.PricePerAllNight = sellPerAll;
                                    Container.roomResults.AddRange(resultsPackage);
                                    Containers.Add(Container);
                                    Packagecount += 1;
                                }
                                roomPackage.roomPackages.AddRange(Containers);
                                hotel.packages.Add(roomPackage);
                            }
                            double MinPerNight = 0;
                            double MinperAll   = 0;
                            var    mindata     = hotel.packages[0].roomPackages.Where(a => a.PricePerAllNight == hotel.packages[0].roomPackages.Min(x => x.PricePerAllNight)).FirstOrDefault();
                            if (mindata != null)
                            {
                                MinperAll   = mindata.PricePerAllNight;
                                MinPerNight = mindata.PricePerNight;
                            }
                            foreach (var item in hotel.packages)
                            {
                                var minPackage = item.roomPackages.Where(a => a.PricePerAllNight == item.roomPackages.Min(x => x.PricePerAllNight)).FirstOrDefault();
                                if (minPackage != null)
                                {
                                    if (minPackage.PricePerAllNight < MinperAll)
                                    {
                                        MinperAll   = minPackage.PricePerAllNight;
                                        MinPerNight = minPackage.PricePerNight;
                                    }
                                }
                            }
                            // var minRoom = hotel.rooms.Where(a => a.RatePerNight == hotel.rooms.Min(x => x.RatePerNight)).FirstOrDefault();
                            if (MinperAll > 0)
                            {
                                hotel.PricePerNight = MinPerNight;
                                //   hotel.costPrice = minRoom.CostPrice;
                                hotel.PricePerAllNight = MinperAll;
                            }
                            searchResponse.Add(hotel);
                        }
                    }
                    //  searchResponse.HotelResult = results;
                    return(searchResponse);
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.WriteToFile("MapSearchResultChannel/Errors/", "MapSearchResult_" + searchData.sID, ex.Message, ex.Message + " Sourse :" + ex.Source + " Stack Trace :" + ex.StackTrace);
                return(new List <HotelChannelResult>());
            }
        }
Exemplo n.º 3
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());
            }
        }
Exemplo n.º 4
0
        public List <HotelSearchResult> MapSearchResult(List <SearchOutputData> searchOutputs, List <BoardCode> boardCodes, SearchData searchData)
        {
            try
            {
                //save result
                //apply salesRules
                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);
                //

                List <string>            hotelIds      = searchOutputs.Select(a => a.hotelCode).ToList();
                HotelManager             manager       = new HotelManager();
                List <HotelDetails>      HotelDataList = manager.GetHotelData(hotelIds, "3");
                List <HotelSearchResult> results       = new List <HotelSearchResult>();
                var BaseCur = ConfigurationSettings.AppSettings["BaseCur"];
                // Provider Exchange Rate From User Curency To Provider Curency
                double ProviderExcahngeRate = currencyManager.GetCurrencyConversion(searchData.Currency, BaseCur, searchData.sID);
                /////double ProviderExcahngeRate = currencyManager.GetCurrencyConversion("EUR", BaseCur);
                // Exchange Rate From Base Curency to user cur
                double ExcahngeRate = currencyManager.GetCurrencyConversion(BaseCur, searchData.Currency, searchData.sID);
                int    duration     = Convert.ToInt32((searchData.DateTo - searchData.DateFrom).TotalDays);
                {
                    DateTime CheckInDate = searchData.DateFrom;
                    for (int i = 0; i < searchOutputs.Count; i++)
                    {
                        BoardCode         boardCode = boardCodes.Where(a => a.Code == searchOutputs[i].boardCode).FirstOrDefault();
                        HotelDetails      hotelData = HotelDataList.Where(a => a.ProviderHotelId == searchOutputs[i].hotelCode).FirstOrDefault();
                        HotelSearchResult hotel     = new HotelSearchResult();
                        hotel.hotelCode  = searchOutputs[i].hotelCode;
                        hotel.City       = hotelData.City;
                        hotel.hotelName  = hotelData.HotelName;
                        hotel.Country    = hotelData.Country;
                        hotel.hotelStars = int.Parse(hotelData.Rating) - 558;
                        var images = hotelData.Images.FirstOrDefault();
                        if (images != null)
                        {
                            hotel.hotelThumb = images.Thum;
                        }
                        hotel.hotelImages              = hotelData.Images.Select(a => a.Thum).ToList();
                        hotel.Lat                      = hotelData.Lat;
                        hotel.Lng                      = hotelData.Lng;
                        hotel.providerID               = "3";
                        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.providerHotelCode        = hotelData.HotelId;
                        hotel.sellCurrency             = searchData.Currency;
                        //  hotel.costPrice =//Math.Round( (double.Parse(searchOutputs[i].price.net.Value.ToString()) * ProviderExcahngeRate) /duration,3);
                        hotel.costCurrency = searchOutputs[i].price.currency;
                        //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, "3");
                        AppliedSalesRule AppliedCancellationMarkup = CancellationChargeManager.ApplySalesRules("Markup");

                        for (int j = 0; j < searchOutputs[i].rooms.Count; j++)
                        {
                            RoomResult room = new RoomResult();
                            room.CostPrice = Math.Round(double.Parse(searchOutputs[i].rooms[j].roomPrice.price.net.Value.ToString()), 3);

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

                            room.IsRefundable   = searchOutputs[i].rooms[j].refundable;
                            room.RatePerNight   = ((double.Parse(searchOutputs[i].rooms[j].roomPrice.price.net.Value.ToString()) * ProviderExcahngeRate / duration) + AppliedMarkup.Value - AppliedDiscount.Value) * ExcahngeRate;
                            room.TotalSellPrice = Math.Round(room.RatePerNight * duration, 3);
                            room.RoomIndex      = j + 1;
                            room.RoomReference  = searchOutputs[i].id;

                            room.RoomType          = searchOutputs[i].rooms[j].description;
                            room.RoomMeal          = boardCode.Name;
                            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 = searchOutputs[i].cancelPolicy.cancelPenalties == null? new List <CancellationRule>()
                            {
                                new CancellationRule {
                                    Cost = Math.Round((AppliedCancellationMarkup.Value) * ExcahngeRate, 3)
                                }
                            } :
                            searchOutputs[i].cancelPolicy.cancelPenalties.Select(a => new CancellationRule
                            {
                                ToDate = CheckInDate.AddHours(-a.hoursBefore.Value).ToString("dd MMM yyyy"),
                                Cost   = Math.Round(((a.value.Value * ProviderExcahngeRate) + AppliedCancellationMarkup.Value) * ExcahngeRate, 3),
                                CanellationRuleText = searchData.Lang.ToLower() == "en"? Math.Round(((a.value.Value * ProviderExcahngeRate) + AppliedCancellationMarkup.Value) * ExcahngeRate, 3) + "" + searchData.Currency + " To " + CheckInDate.AddHours(-a.hoursBefore.Value).ToString("dd MMM yyyy") : CheckInDate.AddHours(-a.hoursBefore.Value).ToString("dd MMM yyyy") + " إلى " + "" + searchData.Currency + Math.Round(((a.value.Value * 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();
                        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);
                    }
                    return(results);
                }
            }
            catch (Exception ex) {
                LoggingHelper.WriteToFile("MapSearchResult/Errors/", "MapSearchResult_" + searchData.sID, ex.InnerException?.Message, ex.Message + " Sourse :" + ex.Source + " Stack Trace :" + ex.StackTrace);
                return(new List <HotelSearchResult>());
            }
        }