Ejemplo n.º 1
0
        public HotelAvailabilityProviderRes Execute(HotelAvailabilityProviderReq request)
        {
            //Logger.Instance.LogFunctionEntry(this.GetType().Name, "Execute");
            Availability avail  = new Availability();
            List <Hotel> hotels = new List <Hotel>();

            if (request.CheckInDate <= DateTime.Today)
            {
                throw new ArgumentOutOfRangeException(nameof(request.CheckInDate));
            }
            if (request.CheckInDate >= request.CheckOutDate)
            {
                throw new ArgumentOutOfRangeException(nameof(request.CheckOutDate));
            }
            if (request.TotalAdults < HotelBedsConstants.TotalAdults)
            {
                throw new ArgumentOutOfRangeException(nameof(request.TotalAdults));
            }
            //Check if #of nights are more than 30, if so throw exception
            var duration = (request.CheckOutDate - request.CheckInDate).TotalDays;

            if (duration > HotelBedsConstants.NightsDuration)
            {
                throw new ArgumentOutOfRangeException(nameof(duration));
            }

            HotelAvailabilityProviderRes hotelSearchResults;

            using (var hotelBedsworker = new HotelBedsWorker())
            {
                //convert the request dto to the HotelBeds search api payload
                AvailabilityRQ hotelBedsSearchRq = ConvertToHotelBedsSearchRequest(request);

                try
                {
                    var hotelBedsHotels = hotelBedsworker.GetAvailability <AvailabilityRQ, AvailabilityRS>(hotelBedsSearchRq);
                    //Check if we need to check .hotels == null
                    if (hotelBedsHotels.hotels == null)
                    {
                        //throw new ProviderUnavailableException(ProviderTypes.HotelBeds.ToString(), $"No response to {nameof(AvailabilityRQ)}.", null);
                        throw new ProviderUnavailableException(ProviderTypes.HotelBeds.ToString(), hotelBedsHotels.error.message.ToString(), null);
                    }
                    hotelSearchResults = ConvertToProviderResponse(hotelBedsHotels);
                }
                catch (HotelBedsProviderException e)
                {
                    if (e.HasKnownError(HotelBedsProviderException.HotelKnownError.NoListings))
                    {
                        hotelSearchResults = new HotelAvailabilityProviderRes();
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            //Logger.Instance.LogFunctionExit(this.GetType().Name, "Execute");
            return(hotelSearchResults);
        }
        public HotelAvailabilityProviderRes Execute(HotelAvailabilityProviderReq request)
        {
            //Logger.Instance.LogFunctionEntry(this.GetType().Name, "Execute");
            Availability avail = new Availability();
            List<Hotel> hotels = new List<Hotel>();

            if (request.CheckInDate <= DateTime.Today)
            {
                throw new ArgumentOutOfRangeException(nameof(request.CheckInDate));
            }
            if (request.CheckInDate >= request.CheckOutDate)
            {
                throw new ArgumentOutOfRangeException(nameof(request.CheckOutDate));
            }
            if (request.TotalAdults < HotelBedsConstants.TotalAdults)
            {
                throw new ArgumentOutOfRangeException(nameof(request.TotalAdults));
            }
            //Check if #of nights are more than 30, if so throw exception
            var duration = (request.CheckOutDate - request.CheckInDate).TotalDays;

            if (duration > HotelBedsConstants.NightsDuration)
            {
                throw new ArgumentOutOfRangeException(nameof(duration));
            }

            HotelAvailabilityProviderRes hotelSearchResults;
            using (var hotelBedsworker = new HotelBedsWorker())
            {
                //convert the request dto to the HotelBeds search api payload
                AvailabilityRQ hotelBedsSearchRq = ConvertToHotelBedsSearchRequest(request);

                try
                {
                    var hotelBedsHotels = hotelBedsworker.GetAvailability<AvailabilityRQ, AvailabilityRS>(hotelBedsSearchRq);
                    //Check if we need to check .hotels == null
                    if (hotelBedsHotels.hotels == null)
                    {
                        //throw new ProviderUnavailableException(ProviderTypes.HotelBeds.ToString(), $"No response to {nameof(AvailabilityRQ)}.", null);
                        throw new ProviderUnavailableException(ProviderTypes.HotelBeds.ToString(), hotelBedsHotels.error.message.ToString(), null);
                    }
                    hotelSearchResults = ConvertToProviderResponse(hotelBedsHotels);
                }
                catch (HotelBedsProviderException e)
                {
                    if (e.HasKnownError(HotelBedsProviderException.HotelKnownError.NoListings))
                    {
                        hotelSearchResults = new HotelAvailabilityProviderRes();
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            //Logger.Instance.LogFunctionExit(this.GetType().Name, "Execute");
            return hotelSearchResults;
        }
Ejemplo n.º 3
0
        private HotelAvailabilityProviderRes ConvertToProviderResponse(AvailabilityRS request)
        {
            Logger.Instance.LogFunctionEntry(this.GetType().Name, "ConvertToProviderResponse");
            HotelAvailabilityProviderRes hotelResultRS = new HotelAvailabilityProviderRes();

            //if (request.hotels != null)
            //    hotelResultRS.Hotels = request.hotels.hotels;
            //else
            //    hotelResultRS.Hotels = null;
            //Logger.Instance.LogFunctionExit(this.GetType().Name, "ConvertToProviderResponse");
            return(hotelResultRS);
        }
Ejemplo n.º 4
0
        private HotelAvailabilityProviderRes ConvertToProviderResponse(AvailabilityRS request)
        {
            HotelAvailabilityProviderRes hotelResultRS = new HotelAvailabilityProviderRes();

            var hotels = new List <HotelSearchResultItem>();

            if (request?.hotels?.hotels != null && request.hotels.hotels.Any())
            {
                foreach (var htl in request.hotels.hotels)
                {
                    var searchResult = new HotelSearchResultItem()
                    {
                        HotelInfo = new HotelInfo()
                        {
                            HotelName           = htl.name,
                            HotelCode           = htl.code.ToString(),
                            Description         = htl.zoneCode + ", " + htl.zoneName,
                            Rating              = Convert.ToInt16(htl.categoryName.Split(HotelBedsConstants.SpaceSeperator)[0]),
                            PropertyInformation = new HotelPropertyDetail()
                            {
                                Latitude  = Convert.ToDecimal(htl.latitude),
                                Longitude = Convert.ToDecimal(htl.longitude)
                            },
                        },
                        Price = new TE.DataAccessLayer.Models.TMoney()
                        {
                            Amount   = htl.minRate,
                            Currency = new TE.DataAccessLayer.Models.TCurrency()
                            {
                                CurrencyCode = htl.currency
                            }
                        }
                    };
                    hotels.Add(searchResult);
                }
                hotelResultRS.Hotels = hotels;
            }
            else
            {
                hotelResultRS.Hotels = null;
            }

            return(hotelResultRS);
        }
Ejemplo n.º 5
0
        // GET api/<controller>
        public HotelAvailabilityProviderRes Get()
        {
            TouricoHotelSearchProvider searchProvider = new TouricoHotelSearchProvider();

            HotelAvailabilityProviderReq request = new HotelAvailabilityProviderReq();

            request.CheckInDate  = DateTime.Now.AddDays(3).Date;
            request.CheckOutDate = DateTime.Now.AddDays(5).Date;

            request.HotelCodes = new System.Collections.Generic.List <string> {
                "8198"
            };
            //TODO:
            //request.TotalAdults = 2;

            HotelAvailabilityProviderRes res = searchProvider.Search(request);

            return(res);
        }
Ejemplo n.º 6
0
        private HotelSearchResponseDto ConvertFromHotelSearchResp(HotelAvailabilityProviderRes response)
        {
            var results = new HotelSearchResponseDto();

            results.Hotels = new List <HotelSearchResultItem>();
            HotelCatalogManager manager = new HotelCatalogManager();

            foreach (var providerHotel in response.Hotels)
            {
                var staticData = manager.GetHotelPropertyInformation(providerHotel.HotelInfo.HotelCode);
                if (staticData != null)
                {
                    providerHotel.HotelInfo.HeroImageUrl = staticData.ImageUrl;
                    providerHotel.HotelInfo.HomepageUrl  = staticData.HomepageUrl;
                    providerHotel.HotelInfo.Email        = staticData.Email;
                }
                results.Hotels.Add(providerHotel);
            }
            return(results);
        }
        private HotelAvailabilityProviderRes ConvertToProviderResponse(AvailabilityRS request)
        {
            HotelAvailabilityProviderRes hotelResultRS = new HotelAvailabilityProviderRes();

            var hotels = new List<HotelSearchResultItem>();
            if (request?.hotels?.hotels != null && request.hotels.hotels.Any())
            {
                foreach (var htl in request.hotels.hotels)
                {
                    var searchResult = new HotelSearchResultItem()
                    {
                        HotelInfo = new HotelInfo()
                        {
                            HotelName = htl.name,
                            HotelCode = htl.code.ToString(),
                            Description = htl.zoneCode + ", " + htl.zoneName,
                            Rating = Convert.ToInt16(htl.categoryName.Split(HotelBedsConstants.SpaceSeperator)[0]),
                            PropertyInformation = new HotelPropertyDetail()
                            {
                                Latitude = Convert.ToDecimal(htl.latitude),
                                Longitude = Convert.ToDecimal(htl.longitude)
                            },

                        },
                        Price = new TE.DataAccessLayer.Models.TMoney()
                        {
                            Amount = htl.minRate,
                            Currency = new TE.DataAccessLayer.Models.TCurrency()
                            {
                                CurrencyCode = htl.currency
                            }
                        }

                    };
                    hotels.Add(searchResult);
                }
                hotelResultRS.Hotels = hotels;
            }
            else
                hotelResultRS.Hotels = null;

            return hotelResultRS;
        }
 private HotelAvailabilityProviderRes ConvertToProviderResponse(AvailabilityRS request)
 {
     Logger.Instance.LogFunctionEntry(this.GetType().Name, "ConvertToProviderResponse");
     HotelAvailabilityProviderRes hotelResultRS = new HotelAvailabilityProviderRes();
     //if (request.hotels != null)
     //    hotelResultRS.Hotels = request.hotels.hotels;
     //else
     //    hotelResultRS.Hotels = null;
     //Logger.Instance.LogFunctionExit(this.GetType().Name, "ConvertToProviderResponse");
     return hotelResultRS;
 }