Ejemplo n.º 1
0
        public void SaveSearchData(SearchData searchData)
        {
            try
            {
                using (SearchDBEntities db = new SearchDBEntities())
                {
                    SearchCriteria searchCriteria = new SearchCriteria();
                    searchCriteria.cityName             = searchData.CityName.ToUpper();
                    searchCriteria.currency             = searchData.Currency;
                    searchCriteria.dateFrom             = searchData.DateFrom;
                    searchCriteria.dateTo               = searchData.DateTo;
                    searchCriteria.duration             = Convert.ToInt32((searchData.DateTo - searchData.DateFrom).TotalDays);
                    searchCriteria.language             = searchData.Lang;
                    searchCriteria.passengerNationality = searchData.Nat;
                    searchCriteria.pos    = searchData.POS;
                    searchCriteria.roomNo = searchData.SearchRooms.Count();
                    searchCriteria.sID    = searchData.sID;
                    searchCriteria.source = searchData.Source;
                    for (int i = 0; i < searchData.SearchRooms.Count; i++)
                    {
                        SearchRoomData searchRoomData = new SearchRoomData();
                        searchRoomData.sID        = searchData.sID;
                        searchRoomData.childernNo = searchData.SearchRooms[i].Child.Count;

                        searchRoomData.childAge = string.Join("-", searchData.SearchRooms[i].Child);
                        searchRoomData.adultNo  = searchData.SearchRooms[i].Adult;
                        searchRoomData.roomNo   = i + 1;
                        db.SearchRoomDatas.Add(searchRoomData);
                    }

                    db.SearchCriterias.Add(searchCriteria);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.WriteToFile("SearchRepo/Errors/", "SaveSearchData_" + searchData.sID, ex.InnerException?.Message, ex.Message + " Sourse :" + ex.Source + " Stack Trace :" + ex.StackTrace);
                throw ex;
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        //map tbo rooms rsp to general res

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            hotelSearchRoom.Packages = singles;
            return(hotelSearchRoom);
        }