示例#1
0
        public RoomResult Find(long id)
        {
            Model.Room entity = Dao.Find(id);
            RoomResult result = ResultConverter.Convert(entity);

            return(result);
        }
示例#2
0
 private static void fillArray(RoomResult[] tArr, int _startIndex, int _endIndex, RoomResult _result)
 {
     for (int i = 0; i < tArr.Length; i++)
     {
         if (i >= _startIndex && i < _endIndex)
         {
             tArr[i] = _result;
         }
     }
 }
示例#3
0
        //获取房间接口
        public ActionResult GetRoom(string data)
        {
            RoomResult r = new RoomResult();

            if (string.IsNullOrEmpty(data))
            {
                r.info    = "参数data不能为空!";
                r.success = false;
            }
            else
            {
                r = us.PushRoomInfo(data);
            }
            return(Content(r.ToJson()));
        }
示例#4
0
        /// <summary>
        /// 获得房间信息
        /// </summary>
        public async Task <BaseResponseData> GetRoom(Guid roleId)
        {
            RoomResult result = new RoomResult();
            var        data   = await Data.Helper.RoomData.Instance.GetRoomData();

            if (data == null)
            {
                //初始化
                data = GetNewRoom(roleId.ToString(), 1);

                await Data.Helper.RoomData.Instance.UpdateRoomData(data);
            }

            result.RoleId = data.RoleId;
            result.RoomId = data.RoomId;
            result.Config = data.Config;
            return(result);
        }
        //获取房间信息接口(参数:楼栋ID)
        public RoomResult PushRoomInfo(string data)
        {
            RoomResult r = new RoomResult();

            try
            {
                List <RoomModel> list = new List <RoomModel>();
                string           sql  = string.Format(@"select * from TB_ROOM(nolock) where STATUS=1 and BUILDING_GUID='{0}' order by ROOM_NUMBER;", data);

                using (SqlDataReader rd = db.ExecuteReader(sql))
                {
                    while (rd.Read())
                    {
                        RoomModel mode = new RoomModel();
                        mode.ROOM_GUID          = getRdString(rd, "ROOM_GUID");
                        mode.ROOM_NUMBER        = getRdString(rd, "ROOM_NUMBER");
                        mode.FLOOR_NUMBER       = getRdString(rd, "FLOOR_NUMBER");
                        mode.BUILDING_GUID      = getRdString(rd, "BUILDING_GUID");
                        mode.ESTATE_GUID        = getRdString(rd, "ESTATE_GUID");
                        mode.ADDRESS            = getRdString(rd, "ADDRESS");
                        mode.ROOM_TYPE          = getRdString(rd, "ROOM_TYPE");
                        mode.AREA               = getRdString(rd, "AREA");
                        mode.DIRECTION          = getRdString(rd, "DIRECTION");
                        mode.SITTING_ROOM_TOTAL = getRdString(rd, "SITTING_ROOM_TOTAL");
                        mode.BEDROOM_TOTAL      = getRdString(rd, "BEDROOM_TOTAL");
                        mode.WASHROOM_TOTAL     = getRdString(rd, "WASHROOM_TOTAL");
                        mode.BALCONY_TOTAL      = getRdString(rd, "BALCONY_TOTAL");
                        mode.KITCHEN_TOTAL      = getRdString(rd, "KITCHEN_TOTAL");
                        list.Add(mode);
                    }
                    rd.Close();
                    rd.Dispose();
                }
                r.success = true;
                r.info    = "成功";
                r.data    = list;
            }
            catch (Exception ex)
            {
                r.success = false;
                r.info    = ex.Message;
            }
            return(r);
        }
示例#6
0
        public ActionResult CreateReport(RoomsBusynessViewModel model, int hotelid)
        {
            TimeSpan                    xd     = model.EndTime - model.StartTime;
            List <Kambarys>             rooms  = repository.Set <Kambarys>().Where(x => x.fk_Viesbutisid == hotelid).ToList();
            Viesbutis                   hotel  = repository.Set <Viesbutis>().Find(hotelid);
            RoomsReportResultsViewModel model2 = new RoomsReportResultsViewModel();

            model2.Title     = hotel.pavadinimas;
            model2.StartTime = model.StartTime;
            model2.EndTime   = model.EndTime;
            List <RoomResult> results = new List <RoomResult>();

            foreach (var item in rooms)
            {
                RoomResult result = new RoomResult();
                result.Number = item.numeris;
                List <Rezervacijos_kambarys> data = repository.Set <Rezervacijos_kambarys>().Where(x => x.fk_Kambarysid == item.id).ToList();
                double count = 0;
                foreach (var item2 in data)
                {
                    Rezervacija data2 = repository.Set <Rezervacija>().Find(item2.fk_Rezervacijaid);
                    if (data2.rezervacijos_pradzia >= model.EndTime)
                    {
                        count += 0;
                    }
                    if (data2.rezervacijos_pradzia >= model.StartTime && data2.rezervacijos_pabaiga <= model.EndTime)
                    {
                        count += data2.rezervacijos_pabaiga.Subtract(data2.rezervacijos_pradzia).TotalDays;
                    }
                    if (data2.rezervacijos_pradzia >= model.StartTime && data2.rezervacijos_pradzia < model.EndTime && data2.rezervacijos_pabaiga > model.EndTime)
                    {
                        count += model.EndTime.Subtract(data2.rezervacijos_pradzia).TotalDays;
                    }
                }

                double lol = xd.TotalDays;
                result.Busyness = count * 100 / lol;
                results.Add(result);
            }
            model2.results = results;
            return(View(model2));
        }
示例#7
0
    private AbstractRoom generateRoom(RoomResult _roomType)
    {
        switch (_roomType)
        {
        case RoomResult.Elite:
            return(new MonsterRoomElite());

        case RoomResult.Monster:
            return(new MonsterRoom());

        case RoomResult.Shop:
            return(new ShopRoom());

        case RoomResult.Treasure:
            return(new TreasureRoom());

        default:
            return(new EventRoom());
        }
    }
        public HotelPackagesDetails GetHotelPackages(string pid, string sid, string hid)
        {
            HotelPackagesDetails hotelPackages = new HotelPackagesDetails();
            SearchDBEntities     searchDB      = new SearchDBEntities();
            hotelsDBEntities     hotelsDB      = new hotelsDBEntities();
            var hotelSearchData = hotelsDB.hotels.FirstOrDefault(a => a.hotelID == hid);

            var           hotelSearchpro  = hotelsDB.hotelsProviders.FirstOrDefault(a => a.hotelID == hotelSearchData.ID.ToString() && a.providerID == pid);
            var           hotelSearchDesc = hotelsDB.HotelsDescriptions.FirstOrDefault(a => a.hotelID == hid);
            var           Imgs            = hotelsDB.HotelsImages.Where(a => a.HotelID == hid).ToList();
            List <string> images          = Imgs.Select(x => x.URL).ToList();

            hotelPackages.providerHotelID = hotelSearchpro.providerHotelID;
            hotelPackages.hotelCode       = hotelSearchData.hotelID;
            hotelPackages.Address         = hotelSearchData.address;
            hotelPackages.Lng             = hotelSearchData.Lng;
            hotelPackages.Lat             = hotelSearchData.Lat;

            hotelPackages.hotelStars = int.Parse(hotelSearchData.rating);//
            hotelPackages.hotelName  = hotelSearchData.hotelName;
            hotelPackages.providerID = hotelSearchpro.providerID;
            hotelPackages.Location   = hotelSearchData.location;

            hotelPackages.hotelDescription         = hotelSearchDesc.Description1;
            hotelPackages.shortcutHotelDescription = hotelSearchDesc.Description2;
            hotelPackages.City        = hotelSearchData.cityName;
            hotelPackages.Country     = hotelSearchData.countryName;
            hotelPackages.hotelImages = images;

            var          packages    = searchDB.HotelPackages.Where(a => a.Session == sid && a.Hotelid == hid && a.Provider.ToString() == pid).ToList();
            var          Rooms       = searchDB.SearchRoomResults.Where(a => a.sID == sid && a.HotelCode == hid && a.ProviderId.ToString() == pid).ToList();
            RoomPackages roomPackage = new RoomPackages();

            foreach (var item in packages)
            {
                //    var availableCate = hotelPackages.packages.FirstOrDefault(a => a.RoomCategory == item.Category);
                if (roomPackage.RoomCategory != item.Category)
                {
                    if (roomPackage.roomPackages.Count != 0)
                    {
                        roomPackage.PackagesNo = roomPackage.roomPackages.Count;
                        hotelPackages.packages.Add(roomPackage);
                    }
                    roomPackage = new RoomPackages();
                    roomPackage.RoomCategory = item.Category;
                }


                RoomPackage roomPack = new RoomPackage();
                roomPack.No = item.PackageNum.Value;
                roomPack.PricePerAllNight = item.PricePerAllNight.Value;
                roomPack.PricePerNight    = item.PricePerNight.Value;

                var specPack = Rooms.Where(x => x.PackageNo == item.PackageNum).ToList();
                foreach (var r in specPack)
                {
                    RoomResult result = new RoomResult();
                    result.CostPrice      = r.costPrice.Value;
                    result.DiscountId     = r.DiscountId.Value;
                    result.PackageNO      = r.PackageNo.Value;
                    result.DiscountValue  = r.DiscountVal.Value;
                    result.Images         = Imgs.Where(x => x.Category.ToLower() == "hotel rooms").Select(a => a.URL).ToList();
                    result.MarkupId       = r.MarkupId.Value;
                    result.MarkupValue    = r.MarkupVal.Value;
                    result.Paxs           = r.PaxSQty.Value;
                    result.RoomCode       = r.roomType;
                    result.RoomIndex      = int.Parse(r.RoomCode);
                    result.RoomMeal       = r.meal;
                    result.RoomReference  = r.RoomReference;
                    result.RoomType       = r.RoomName;
                    result.TotalSellPrice = r.SellPrice.Value;
                    result.Adult          = r.Adults.Value;
                    result.Child          = r.Childern.Value;
                    if (r.IsRefundable.Value != null)
                    {
                        result.IsRefundable = r.IsRefundable.Value;
                    }
                    roomPack.roomResults.Add(result);
                }
                roomPackage.roomPackages.Add(roomPack);
                //hotelPackages.packages.Add(roomPackage);
            }
            if (roomPackage.roomPackages.Count != 0)
            {
                hotelPackages.packages.Add(roomPackage);
            }
            return(hotelPackages);
        }
示例#9
0
        public IHttpActionResult Get(string sid, string hotel, string Pid, string rooms)
        {
            // call bll
            try
            {
                LoggingHelper.WriteToFile("HotelRoomsController/GetRoomsNumber/", "SearchController" + "INController" + sid, "Rooms", "Sid" + sid);


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

                        SearchDBEntities searchDB = new SearchDBEntities();

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

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

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

                                foreach (var cancel in availRes.HotelCancellationPolicies?.CancelPolicies?.CancelPolicy)
                                {
                                    double costToSave = 0;
                                    string Cur        = "";
                                    //Enum.TryParse(cancel.ChargeType.ToString(), out CancellationChargeTypeForHotel Type);
                                    if (cancel.ChargeType == CancellationChargeTypeForHotel.Percentage)
                                    {
                                        costToSave = (double)cancel.CancellationCharge;
                                        Cur        = "%";
                                    }
                                    else
                                    {
                                        Cur        = "KWD";
                                        costToSave = (double)cancel.CancellationCharge * ProviderExcahngeRate; //Math.Round((double)cancel.CancellationCharge * ProviderExcahngeRate, 3);
                                    }
                                    CancellationRule cancellation = new CancellationRule();
                                    cancellation.FromDate   = cancel.FromDate;
                                    cancellation.ToDate     = cancel.ToDate;
                                    cancellation.Cost       = (double)cancel.CancellationCharge;
                                    cancellation.ChargeType = cancel.ChargeType.ToString();
                                    cancellation.Curency    = Cur;
                                    cancellation.Price      = costToSave; //
                                    roomResult.cancellationRules.Add(cancellation);
                                }


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

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

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

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

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

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

                return(BadRequest(ex.Message));
            }
        }
示例#10
0
        public static HotelSearchRoom GetRoomsByHotelIDAndProvide(string Sid, string pid, string Hid)
        {
            try
            {
                SearchDBEntities  searchDB    = new SearchDBEntities();
                List <RoomResult> roomResults = new List <RoomResult>();
                var RoomsRuslt = searchDB.SearchRoomResults.Where(a => a.HotelCode == Hid && a.sID == Sid && a.ProviderId.ToString() == pid).ToList();
                var Dur        = searchDB.SearchCriterias.FirstOrDefault(a => a.sID == Sid).duration;

                if (pid == "5")
                {
                    TBO.DAL.Models.Context.TBOContext context = new TBO.DAL.Models.Context.TBOContext();

                    var           HImages = context.HotelImages.Where(a => a.HotelCode == Hid).ToList();
                    List <string> images  = HImages.Select(x => x.URL).ToList();

                    var             hotelSearchData = context.HotelDetails.FirstOrDefault(a => a.HotelCode == Hid);
                    var             facilties       = context.Facilities.Where(ff => ff.HotelCode == Hid).ToList();
                    HotelSearchRoom hotelSearchRoom = new HotelSearchRoom();
                    //facilties
                    foreach (var item in facilties)
                    {
                        hotelSearchRoom.Amenities.Add(new HotelAmenity
                        {
                            Amenity   = item.FacilityVal,
                            HotelCode = item.HotelCode
                        });
                    }
                    hotelSearchRoom.providerHotelID = hotelSearchData.HotelCode;
                    hotelSearchRoom.hotelCode       = hotelSearchData.HotelCode;
                    hotelSearchRoom.Address         = hotelSearchData.Address;
                    hotelSearchRoom.Lng             = hotelSearchData.Map;
                    //hotelSearchRoom.Lat = hotelSearchData.Lat;

                    //hotelSearchRoom.hotelStars = int.Parse(hotelSearchData.HotelRating);//
                    hotelSearchRoom.hotelName  = hotelSearchData.HotelName;
                    hotelSearchRoom.providerID = "5";
                    hotelSearchRoom.Location   = hotelSearchData.HotelLocation;

                    hotelSearchRoom.hotelDescription = hotelSearchData.Description;
                    //hotelSearchRoom.shortcutHotelDescription = hotelSearchDesc.Description2;
                    hotelSearchRoom.City        = hotelSearchData.CityName;
                    hotelSearchRoom.Country     = hotelSearchData.CountryName;
                    hotelSearchRoom.hotelImages = images;

                    #region instead call available hotel room api to get tbo rooms
                    //if (RoomsRuslt.Count > 0)
                    //{
                    //    foreach (var item in RoomsRuslt)
                    //    {
                    //        RoomResult result = new RoomResult();
                    //        result.CostPrice = item.costPrice.Value;
                    //        result.DiscountId = item.DiscountId.Value;
                    //        result.DiscountValue = item.DiscountVal.Value;
                    //        //result.Images = roomsImages.Select(a => a.URL).ToList();
                    //        //   result.IsRefundable=item.
                    //        result.MarkupId = item.MarkupId.Value;
                    //        result.MarkupValue = item.MarkupVal.Value;
                    //        result.Paxs = item.PaxSQty.Value;
                    //        result.RatePerNight = (item.SellPrice / Dur).Value;
                    //        result.RoomCode = item.roomType;
                    //        result.RoomIndex = int.Parse(item.RoomCode);
                    //        result.RoomMeal = item.meal;
                    //        result.RoomReference = item.RoomReference;
                    //        result.RoomType = item.RoomName;
                    //        result.TotalSellPrice = item.SellPrice.Value;
                    //        result.Adult = item.Adults.Value;
                    //        result.Child = item.Childern.Value;
                    //        result.IsRefundable = item.IsRefundable.Value;

                    //        //var repeatedRoom = roomResults.Where(x => x.RoomReference == item.RoomReference).ToList();
                    //        //if (repeatedRoom.Count < 1)
                    //            roomResults.Add(result);
                    //    }

                    //    var roomsDetails = searchDB.SearchRoomDatas.Where(a => a.sID == Sid).ToList();
                    //    for (int i = 0; i < roomsDetails.Count; i++)

                    //    {
                    //        SearchRoomData roomresult = new SearchRoomData();
                    //        roomresult = null;
                    //        var resultsR = roomResults.ToList();// Where(x => x.Adult == roomsDetails[i].adultNo.Value && x.Child == roomsDetails[i].childernNo.Value).ToList();
                    //        SeparatedRoom srts = new SeparatedRoom();
                    //        srts.RoomResults.AddRange(resultsR);
                    //        hotelSearchRoom.rooms.Add(srts);

                    //    }
                    //}
                    #endregion
                    return(hotelSearchRoom);
                }
                else
                {
                    hotelsDBEntities hotelsDB = new hotelsDBEntities();
                    var HImages     = hotelsDB.HotelsImages.Where(a => a.HotelID == Hid).ToList();
                    var roomsImages = HImages.Where(a => a.Category.ToLower() == "hotel rooms");

                    if (RoomsRuslt.Count > 0)
                    {
                        foreach (var item in RoomsRuslt)
                        {
                            RoomResult result = new RoomResult();
                            result.CostPrice     = item.costPrice.Value;
                            result.DiscountId    = item.DiscountId.Value;
                            result.DiscountValue = item.DiscountVal.Value;
                            result.Images        = roomsImages.Select(a => a.URL).ToList();
                            //   result.IsRefundable=item.
                            result.MarkupId       = item.MarkupId.Value;
                            result.MarkupValue    = item.MarkupVal.Value;
                            result.Paxs           = item.PaxSQty.Value;
                            result.RatePerNight   = (item.SellPrice / Dur).Value;
                            result.RoomCode       = item.roomType;
                            result.RoomIndex      = int.Parse(item.RoomCode);
                            result.RoomMeal       = item.meal;
                            result.RoomReference  = item.RoomReference;
                            result.RoomType       = item.RoomName;
                            result.TotalSellPrice = item.SellPrice.Value;
                            result.Adult          = item.Adults.Value;
                            result.Child          = item.Childern.Value;
                            result.IsRefundable   = item.IsRefundable.Value;

                            var repeatedRoom = roomResults.Where(x => x.RoomReference == item.RoomReference).ToList();
                            if (repeatedRoom.Count < 1)
                            {
                                roomResults.Add(result);
                            }
                        }
                        //// get hotel

                        HotelSearchRoom hotelSearchRoom = new HotelSearchRoom();

                        List <string> images = HImages.Select(x => x.URL).ToList();


                        List <HotelAmenity> amenties = (from A in hotelsDB.HotelsAmenities
                                                        where A.hotelID == Hid
                                                        select new HotelAmenity()
                        {
                            Amenity = A.amenitie,
                            HotelCode = A.hotelID,
                            status = A.Status
                        }).ToList();


                        var hotelSearchData = hotelsDB.hotels.FirstOrDefault(a => a.hotelID == Hid);
                        var hotelSearchpro  = hotelsDB.hotelsProviders.FirstOrDefault(a => a.hotelID == hotelSearchData.ID.ToString() && a.providerID == pid);
                        var hotelSearchDesc = hotelsDB.HotelsDescriptions.FirstOrDefault(a => a.hotelID == Hid);

                        hotelSearchRoom.providerHotelID = hotelSearchpro.providerHotelID;
                        hotelSearchRoom.hotelCode       = hotelSearchData.hotelID;
                        hotelSearchRoom.Address         = hotelSearchData.address;
                        hotelSearchRoom.Lng             = hotelSearchData.Lng;
                        hotelSearchRoom.Lat             = hotelSearchData.Lat;

                        hotelSearchRoom.hotelStars = int.Parse(hotelSearchData.rating);//
                        hotelSearchRoom.hotelName  = hotelSearchData.hotelName;
                        hotelSearchRoom.providerID = hotelSearchpro.providerID;
                        hotelSearchRoom.Location   = hotelSearchData.location;

                        hotelSearchRoom.hotelDescription         = hotelSearchDesc.Description1;
                        hotelSearchRoom.shortcutHotelDescription = hotelSearchDesc.Description2;
                        hotelSearchRoom.City    = hotelSearchData.cityName;
                        hotelSearchRoom.Country = hotelSearchData.countryName;

                        var hotelAmenities = amenties.Where(a => a.HotelCode == Hid).Distinct().ToList();
                        foreach (var am in hotelAmenities)
                        {
                            am.Amenity = am.Amenity.Replace("  ", String.Empty);
                            if (hotelSearchRoom.Amenities.FirstOrDefault(x => x.Amenity == am.Amenity) == null)
                            {
                                hotelSearchRoom.Amenities.Add(am);
                            }
                        }

                        //  hotelSearchRoom.Amenities = ams;

                        hotelSearchRoom.hotelImages = images;
                        // searchDB to know list of each rooms
                        if (pid == "4")
                        {
                            /*
                             * List<RoomForSearch> searchRooms = new List<RoomForSearch>();
                             * var roomsDetails = searchDB.SearchRoomDatas.Where(a => a.sID == Sid).ToList();
                             * foreach (var item in roomsDetails)
                             * {
                             *  SearchRoomData roomresult = new SearchRoomData();
                             *  roomresult = null;
                             *  var results = roomsDetails.Where(x => x.adultNo == item.adultNo && x.childernNo == item.childernNo).ToList();
                             *  foreach (var r in searchRooms)
                             *  {
                             *      if (roomresult  == null )
                             *      {
                             *          roomresult = r.rooms.FirstOrDefault(a => a.adultNo == item.adultNo && a.childernNo == item.childernNo);
                             *      }
                             *  }
                             *
                             *  if (roomresult == null)
                             *  {
                             *
                             *          RoomForSearch roomFor = new RoomForSearch();
                             *          roomFor.num = results.Count;
                             *          roomFor.rooms = results;
                             *          searchRooms.Add(roomFor);
                             *
                             *  }
                             *  //
                             *  //var ReqiredRooms=  roomResults.Where(x => x.Adult == item.adultNo && x.Child == item.childernNo).ToList();
                             *  //SeparatedRoom sr = new SeparatedRoom();
                             *  //  sr.RoomResults.AddRange(ReqiredRooms);
                             *  //   hotelSearchRoom.rooms.Add(sr);
                             *
                             * }
                             * foreach (var item in searchRooms)
                             * {
                             *  var ReqiredRooms = roomResults.Where(x => x.Adult == item.rooms[0].adultNo && x.Child == item.rooms[0].childernNo).ToList();
                             *  if (item.num == 1)
                             *  {
                             *      SeparatedRoom sr = new SeparatedRoom();
                             *      sr.RoomResults.AddRange(ReqiredRooms);
                             *      hotelSearchRoom.rooms.Add(sr);
                             *  }
                             *  else
                             *  {
                             *      int roomNum = ReqiredRooms.Count / item.num;
                             *      int skipNum = 0;
                             *      for (int i = 0; i < item.num; i++)
                             *      {
                             *          SeparatedRoom sr = new SeparatedRoom();
                             *          List<RoomResult> roomResultsData = new List<RoomResult>();
                             *          //        var roomsReq = ReqiredRooms.Skip(skipNum).ToList();
                             *          for (int j = skipNum; j < skipNum + roomNum; j++)
                             *          {
                             *              roomResultsData.Add(ReqiredRooms[j]);
                             *
                             *
                             *          }
                             *          // sr.RoomResults.AddRange(roomsReq.Take(roomNum).ToList());
                             *          sr.RoomResults.AddRange(roomResultsData);
                             *          skipNum = roomNum * (i + 1);
                             *          hotelSearchRoom.rooms.Add(sr);
                             *      }
                             *  }
                             * }*/
                            var roomsDetails = searchDB.SearchRoomDatas.Where(a => a.sID == Sid).ToList();
                            for (int i = 0; i < roomsDetails.Count; i++)

                            {
                                SearchRoomData roomresult = new SearchRoomData();
                                roomresult = null;
                                var           resultsR = roomResults.Where(x => x.Adult == roomsDetails[i].adultNo.Value && x.Child == roomsDetails[i].childernNo.Value).ToList();
                                SeparatedRoom srts     = new SeparatedRoom();
                                srts.RoomResults.AddRange(resultsR);
                                hotelSearchRoom.rooms.Add(srts);
                            }
                        }
                        if (pid == "2")
                        {
                            var roomsDetails = searchDB.SearchRoomDatas.Where(a => a.sID == Sid).ToList();
                            for (int i = 0; i < roomsDetails.Count; i++)

                            {
                                SearchRoomData roomresult = new SearchRoomData();
                                roomresult = null;
                                var           resultsR = roomResults.Where(x => x.RoomCode == (i + 1).ToString()).ToList();
                                SeparatedRoom srts     = new SeparatedRoom();
                                srts.RoomResults.AddRange(resultsR);
                                hotelSearchRoom.rooms.Add(srts);
                            }
                        }
                        //  hotelSearchRoom.rooms= roomResults;
                        var minRoom = roomResults.Where(a => a.RatePerNight == roomResults.Min(x => x.RatePerNight)).FirstOrDefault();
                        if (minRoom != null)
                        {
                            hotelSearchRoom.hotelRate      = minRoom.RatePerNight;
                            hotelSearchRoom.costPrice      = minRoom.CostPrice;
                            hotelSearchRoom.TotalSellPrice = minRoom.TotalSellPrice;
                            hotelSearchRoom.MarkupId       = minRoom.MarkupId;
                            hotelSearchRoom.MarkupValue    = minRoom.MarkupValue;
                            hotelSearchRoom.DiscountId     = minRoom.DiscountId;
                            hotelSearchRoom.DiscountValue  = minRoom.DiscountValue;
                        }

                        return(hotelSearchRoom);
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
    public static RoomResult Roll()
    {
        float tRoll = AbstractDungeon.EventRng.Next();

        RoomResult[] tPossibleResults = new RoomResult[100];
        for (int i = 0; i < tPossibleResults.Length; i++)
        {
            tPossibleResults[i] = RoomResult.Event;
        }

        int tEliteSize = Convert.ToInt32(EliteChance * 100f);

        if (AbstractDungeon.GetCurMapNode().Y < 6)
        {
            tEliteSize = 0;
        }

        int tMonsterSize = Convert.ToInt32(MonsterChance * 100f);
        int tShopSize    = Convert.ToInt32(ShopChance * 100f);

        if (AbstractDungeon.GetCurrRoom() is ShopRoom)
        {
            tShopSize = 0;
        }

        int tTreasureSize = Convert.ToInt32(TreasureChance * 100f);
        int tFillIndex    = 0;
        int tStartIndex   = Math.Min(99, tFillIndex);
        int tEndIndex     = Math.Min(100, tFillIndex + tEliteSize);

        fillArray(tPossibleResults, tStartIndex, tEndIndex, RoomResult.Monster);
        tFillIndex += tEliteSize;
        tStartIndex = Math.Min(99, tFillIndex);
        tEndIndex   = Math.Min(100, tFillIndex + tMonsterSize);
        fillArray(tPossibleResults, tStartIndex, tEndIndex, RoomResult.Monster);
        tFillIndex += tMonsterSize;
        tStartIndex = Math.Min(99, tFillIndex);
        tEndIndex   = Math.Min(100, tFillIndex + tShopSize);
        fillArray(tPossibleResults, tStartIndex, tEndIndex, RoomResult.Shop);
        tFillIndex += tShopSize;
        tStartIndex = Math.Min(99, tFillIndex);
        tEndIndex   = Math.Min(100, tFillIndex + tTreasureSize);
        fillArray(tPossibleResults, tStartIndex, tEndIndex, RoomResult.Treasure);
        RoomResult tChoice = tPossibleResults[Convert.ToInt32(tRoll * 100f)];

        if (tChoice == RoomResult.Elite)
        {
            if (AbstractDungeon.Player.HasRelic("JuzuBracelet"))
            {
                //AbstractDungeon.Player.GetRelic("JuzuBracelet").flash();
                tChoice = RoomResult.Event;
            }

            EliteChance = 0f;
        }
        else
        {
            EliteChance += 0.02f;
        }

        if (tChoice == RoomResult.Monster)
        {
            if (AbstractDungeon.Player.HasRelic("JuzuBracelet"))
            {
                //AbstractDungeon.Player.GetRelic("JuzuBracelet").flash();
                tChoice = RoomResult.Event;
            }
            MonsterChance = 0.1f;
        }
        else
        {
            MonsterChance += 0.1f;
        }

        if (tChoice == RoomResult.Shop)
        {
            ShopChance = 0.03f;
        }
        else
        {
            ShopChance += 0.03f;
        }

        if (tChoice == RoomResult.Treasure)
        {
            if (AbstractDungeon.Player.HasRelic("TinyChest"))
            {
                //AbstractDungeon.Player.GetRelic("TinyChest").flash();
                TreasureChance = 0.120000005f;
            }
            else
            {
                TreasureChance = 0.02f;
            }
        }
        else
        {
            TreasureChance += 0.02f;
        }

        return(tChoice);
    }
示例#12
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());
            }
        }
示例#13
0
        public static CheckAvailabilityResult GetRoomsFromProviders(Common.Models.AvailabilityReq roomsReq, String ArrivalDate, string dur)
        {
            //try
            //{
            CheckAvailabilityResult results = new CheckAvailabilityResult();

            results.TotalCost = 0;

            #region redo
            //if (roomsReq.PID == "4")
            //{
            //    HotelBedsIntegration.Models.Availability.AvailabilityReq req = new HotelBedsIntegration.Models.Availability.AvailabilityReq();
            //    req.rooms = new List<RoomReq>();
            //    req.upselling = "True";
            //    foreach (var item in roomsReq.Rooms.Select(a => a.RoomRef).ToList())
            //    {
            //        RoomReq roomReq = new RoomReq();
            //        roomReq.rateKey = item;

            //        req.rooms.Add(roomReq);
            //    }
            //    var availabilityRes = HotelBedsIntegration.Controller.CheckAvailability.checkAvailability(req, roomsReq.Sid);
            //    //MG
            //    results.ProviderCur = availabilityRes.Result.currency;

            //    if (availabilityRes.Result.rooms != null)
            //    {
            //        if (roomsReq.TotalCost == double.Parse(availabilityRes.Result.totalNet) || roomsReq.TotalCost > double.Parse(availabilityRes.Result.totalNet))
            //        {
            //            results.Status = 0;
            //            results.TotalCost = roomsReq.TotalCost;
            //        }
            //        else
            //        {
            //            results.Status = 1;
            //            results.TotalCost = double.Parse(availabilityRes.Result.totalNet);
            //        }
            //        foreach (var item in availabilityRes.Result.rooms)
            //        {
            //            for (int i = 0; i < item.rates.Count; i++)
            //            {
            //                RoomResult roomResult = new RoomResult();

            //                roomResult.CostPrice = double.Parse(item.rates[i].net);
            //                var room = roomsReq.Rooms.Where(a => a.RoomRef == item.rates[i].rateKey).OrderBy(a => a.RoomId).ToList();/////////get specific roomid
            //                if (room.Count > 1)
            //                {
            //                    if (results.Result.FirstOrDefault(x => x.RoomCode == item.rates[i].rateKey) == null)
            //                    {
            //                        roomResult.RoomIndex = room[0].RoomId;
            //                    }
            //                    else
            //                    {
            //                        roomResult.RoomIndex = room[results.Result.Where(x => x.RoomCode == item.rates[i].rateKey).ToList().Count].RoomId;
            //                    }
            //                }
            //                else
            //                {
            //                    roomResult.RoomIndex = room[0].RoomId;
            //                }
            //                roomResult.RoomCode = item.rates[i].rateKey;
            //                if (results.Status == 0)
            //                {
            //                    roomResult.CostPrice = roomsReq.Rooms.FirstOrDefault(v => v.RoomRef == item.rates[i].rateKey).Cost;
            //                }
            //                else
            //                {
            //                    roomResult.CostPrice = double.Parse(item.rates[i].net);
            //                }
            //                // roomResult.TotalSellPrice = double.Parse(r.net);

            //                foreach (var Cancel in item.rates[i].cancellationPolicies)
            //                {
            //                    roomResult.cancellationRules.Add(new CancellationRule
            //                    {
            //                        Cost = double.Parse(Cancel.amount),
            //                        FromDate = Cancel.from.ToLongDateString(),
            //                        ToDate = null,
            //                        CanellationRuleText = null
            //                    });

            //                }
            //                results.Result.Add(roomResult);
            //            }
            //        }

            //    }
            //    else
            //    {
            //        results.Status = 2;
            //    }
            //}
            //else if (roomsReq.PID == "2")
            //{
            //    // get hotelproperty and arrival and duration   // get search rooms result from db
            //    HotelManager hotelManager = new HotelManager();
            //    var hotelsData = hotelManager.GetHotelDataForTsAvailability(roomsReq);
            //    if (hotelsData != null)
            //    {
            //        foreach (var item in hotelsData.roomResults)
            //        {
            //            // call ts  and map it with db and ..or new obj
            //            var roomsResults = new List<SearchRoomResult>();
            //            roomsResults.Add(item);
            //            var availReq = AvailabiltyManager.prepareAvailabilityObj(roomsResults, hotelsData.HodelData.ProviderHotelCode, ArrivalDate, dur);

            //            var availRes = IntegrationTotalStay.Controller.CheckAvailability.GetTSAvailability(availReq, roomsReq.Sid);
            //            if (availRes != null)
            //            {
            //                RoomResult roomResult = new RoomResult();
            //                roomResult.Adult = item.Adults.Value;
            //                roomResult.Child = item.Childern.Value;

            //                roomResult.RoomIndex = int.Parse(item.RoomCode);
            //                roomResult.RoomReference = availRes.PreBookingToken;
            //                if (availRes.TotalPrice == item.costPrice.Value.ToString() || double.Parse(availRes.TotalPrice) < item.costPrice.Value)
            //                {
            //                    results.Status = 0;
            //                    roomResult.CostPrice = item.costPrice.Value;
            //                }
            //                else
            //                {
            //                    results.Status = 1;
            //                    roomResult.CostPrice = double.Parse(availRes.TotalPrice);
            //                }
            //                // handel cancel policy

            //                foreach (var cancel in availRes.Cancellations.Cancellation)
            //                {
            //                    CancellationRule cancellation = new CancellationRule();
            //                    DateTime dateFrom = Convert.ToDateTime(cancel.StartDate);
            //                    cancellation.FromDate = dateFrom.ToString("MMMM dd, yyyy");
            //                    cancellation.ToDate = cancel.EndDate;
            //                    cancellation.Cost = double.Parse(cancel.Penalty);
            //                    roomResult.cancellationRules.Add(cancellation);
            //                }

            //                // roomResult.RoomCode=
            //                results.Result.Add(roomResult);
            //                results.TotalCost += double.Parse(availRes.TotalPrice);
            //            }
            //            else
            //            {
            //                results.Status = 2;
            //            }
            //        }
            //    }
            //    else
            //    {
            //        return null;
            //    }

            //}
            ////else if (PID == "3")
            //{
            //    var SearchData = SearchRepo.GetSearchDataBySession(Sid);
            //    DateTime CheckInDate = SearchData.dateFrom.Value; //searchData.DateFrom;

            //    var SMRRuslt = SMCLSValidation.ValidationQuote(Rooms[0], Sid);
            //    results.TotalCost = double.Parse(SMRRuslt.Result.price.net.ToString());
            //    if (SMRRuslt.Result != null)
            //    {
            //        if (Cost == double.Parse(SMRRuslt.Result.price.net.ToString()))
            //        {
            //            results.Status = 0;
            //        }
            //        else
            //        {
            //            results.Status = 1;
            //        }
            //        foreach (var item in Rooms)
            //        {
            //            RoomResult SMroomResult = new RoomResult();
            //            SMroomResult.RoomCode = SMRRuslt.Result.optionRefId;
            //            foreach (var c in SMRRuslt.Result.cancelPolicy.cancelPenalties)
            //            {
            //                SMroomResult.cancellationRules.Add(new CancellationRule
            //                {

            //                    Cost = double.Parse(c.value.ToString()),
            //                    FromDate = CheckInDate.AddHours(-c.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)


            //                });
            //            }
            //            results.Result.Add(SMroomResult);
            //        }
            //    }
            //    else
            //    {
            //        results.Status = 2;
            //    }
            //}
            #endregion
            if (roomsReq.PID == "5")
            {
                // get hotelproperty and arrival and duration   // get search rooms result from db
                HotelManager hotelManager = new HotelManager();
                //FOr  TBO
                var hotelsData = hotelManager.GetHotelDataForTsAvailability(roomsReq);
                if (hotelsData != null)
                {
                    //TBO
                    SearchDBEntities searchDB   = new SearchDBEntities();
                    string           TBOSession = searchDB.ProviderSessions.FirstOrDefault(ps => ps.SearchId == roomsReq.Sid).PSession;                                                 //Select(s => s.PSession).ToString();
                    int ResIndex = int.Parse(searchDB.SearchHotelResults.FirstOrDefault(hotl => hotl.sID == roomsReq.Sid && hotl.HotelCode == roomsReq.HotelCode).ResIndex.ToString()); //Select(indx => indx.ResIndex).ToString();

                    //get room indexes to send in pricing req
                    List <int> indexs = new List <int>();

                    foreach (var indx in roomsReq.Rooms)
                    {
                        indexs.Add(indx.RoomId);
                    }
                    //TBO.WSDL.hotelServiceRef.AvailabilityAndPricingRequest req = new TBO.WSDL.hotelServiceRef.AvailabilityAndPricingRequest
                    //{
                    //    SessionId = TBOSession,
                    //    ResultIndex = ResIndex,
                    //    OptionsForBooking = new TBO.WSDL.hotelServiceRef.BookingOptions
                    //    {
                    //        RoomCombination = new TBO.WSDL.hotelServiceRef.RoomCombination[]
                    //        {
                    //                    new TBO.WSDL.hotelServiceRef.RoomCombination{RoomIndex = indexs.ToArray()}
                    //        }
                    //    }
                    //};
                    //var availRes = AvailablityPricingService.PricingService(req, roomsReq.Sid);
                    //if (availRes != null)
                    //{
                    var             BaseCur         = ConfigurationSettings.AppSettings["BaseCur"];
                    CurrencyManager currencyManager = new CurrencyManager();
                    //double ProviderExcahngeRate = currencyManager.GetCurrencyConversion("USD", BaseCur, req.SessionId);

                    RoomResult roomResult = new RoomResult();
                    //roomResult.HotelNorms = availRes.HotelCancellationPolicies?.HotelNorms;
                    //if (availRes?.PriceVerification?.PriceChanged == false)
                    //{
                    results.Status = 0;
                    foreach (var item in hotelsData.roomResults)
                    {
                        roomResult.TotalSellPrice = (double)item.SellPrice; //Math.Round((double)item.SellPrice * ProviderExcahngeRate, 3);
                        roomResult.CostPrice      = item.SellPrice ?? default(double);
                        results.TotalCost        += (double)item.SellPrice; //Math.Round((double)item.SellPrice * ProviderExcahngeRate, 3);
                        roomResult.Adult          = item.Adults.Value;
                        roomResult.Child          = item.Childern.Value;

                        roomResult.RoomIndex = int.Parse(item.RoomCode);
                        results.Result.Add(roomResult);
                    }

                    //}
                    //else
                    //{

                    //    results.Status = 1;
                    //    foreach (var item in availRes?.PriceVerification.HotelRooms)
                    //    {
                    //        roomResult.TotalSellPrice = Math.Round((double)item.RoomRate.TotalFare * ProviderExcahngeRate, 3);
                    //        roomResult.CostPrice = (double)item.RoomRate.TotalFare;
                    //        results.TotalCost += roomResult.TotalSellPrice; //Math.Round((double)item.RoomRate.TotalFare * ProviderExcahngeRate, 3);
                    //        roomResult.RoomIndex = item.RoomIndex;
                    //        results.Result.Add(roomResult);
                    //        // update price in search db
                    //        //CheckAvailabilityRepo repo = new CheckAvailabilityRepo();
                    //        //repo.UpdateTBORoomsPrice(availRes?.PriceVerification.HotelRooms);
                    //        //update tbo new rooms prices
                    //        var Newroom = searchDB.SearchRoomResults.FirstOrDefault(room => room.sID == req.SessionId && room.RoomCode == item.RoomIndex.ToString());
                    //        Newroom.costPrice = (double)item.RoomRate.TotalFare;
                    //        Newroom.rateClass = item.RoomRate.RoomFare.ToString();
                    //        Newroom.rateType = item.RoomRate.RoomTax.ToString();
                    //        Newroom.SellPrice = roomResult.TotalSellPrice;

                    //        searchDB.SaveChanges();

                    //    }
                }
                //handel cancel policy
                //foreach (var cancel in availRes.HotelCancellationPolicies?.CancelPolicies?.CancelPolicy)
                //{
                //    CancellationRule cancellation = new CancellationRule();
                //    //DateTime dateFrom = Convert.ToDateTime(cancel.FromDate);
                //    cancellation.FromDate = cancel.FromDate;// dateFrom.ToString("MMMM dd, yyyy");
                //    cancellation.ToDate = cancel.ToDate;
                //    cancellation.Cost = (double)cancel.CancellationCharge;
                //    cancellation.ChargeType = cancel.ChargeType.ToString();
                //    roomResult.cancellationRules.Add(cancellation);
                //}
                //var countroom = 0;
                //foreach (var item in hotelsData.roomResults)
                //{
                //    countroom++;
                //    // call ts  and map it with db and ..or new obj
                //    // var roomsResults = new List<SearchRoomResult>();
                //    // roomsResults.Add(item);
                //    roomResult.Adult = item.Adults.Value;
                //    roomResult.Child = item.Childern.Value;

                //    roomResult.RoomIndex = int.Parse(item.RoomCode);
                //roomResult.RoomReference = availRes.PreBookingToken;
                //results = new CheckAvailabilityResult();

                //if (availRes?.PriceVerification?.PriceChanged == false)
                //{
                //    //results.Status = 0;
                //    roomResult.CostPrice = item.costPrice.Value;
                //    results.TotalCost += item.costPrice.Value;

                //}
                //else
                //{
                //    // results.Status = 1;

                //    roomResult.CostPrice = (double)availRes.PriceVerification.HotelRooms[countroom].RoomRate.TotalFare;
                //    results.TotalCost += (double)availRes.PriceVerification.HotelRooms[countroom].RoomRate.TotalFare;

                //}

                //}    //end foreach

                // roomResult.RoomCode=
                //results.Result.Add(roomResult);
                //}
                //else
                //{
                //    results.Status = 2;
                //}
            }
            else
            {
                return(null);
            }
            return(results);
        }
示例#14
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());
            }
        }
        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>());
            }
        }
示例#16
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>());
            }
        }