Esempio n. 1
0
        public async Task <HotelSearchCityRS> HotelSearchByCityAsync(HotelSearchCityRQ request)
        {
            try
            {
                _LogService = new CommonServices.LogService();
                _LogService.LogInfo("GTA/HotelSearchCityRQ", request);

                if (!IsValidRequest(request))
                {
                    return(null);
                }

                SearchHotelPriceRequest req = ConvertToSearchHotelPriceRequest(request);

                var xRequest = Serialize(req);

                var result = await SubmitAsync(xRequest);

                var response = Deserialize <SearchHotelPriceResponse>(result);

                var rsp = ConvertToHotelSearchCityRS(response, request);

                _LogService.LogInfo("GTA/HotelSearchCityRS", rsp);

                return(await rsp);
            }
            catch (Exception ex)
            {
                _LogService.LogException(ex, "Gta.HotelService.HotelSearchByCity");
                return(new HotelSearchCityRS());
            }
        }
Esempio n. 2
0
        private SearchHotelPriceRequest ConvertToSearchHotelPriceRequest(HotelSearchCityRQ request)
        {
            SearchHotelPriceRequest req = new SearchHotelPriceRequest
            {
                Source         = Source,
                RequestDetails = new Requestdetails
                {
                    SearchHotelPriceRequest = new Searchhotelpricerequest
                    {
                        ItemDestination = new Itemdestination
                        {
                            DestinationType = "city",
                            DestinationCode = request.City
                        },
                        ImmediateConfirmationOnly = "",
                        PeriodOfStay = new Periodofstay
                        {
                            CheckInDate = request.CheckIn.ToString("yyyy-MM-dd"),
                            Duration    = (int)(request.CheckOut.Date - request.CheckIn.Date).TotalDays,
                        },
                        Rooms   = ConvertToRoom(request.Occupancies),
                        OrderBy = "pricelowtohigh",
                        NumberOfReturnedItems = "2000"
                    },
                }
            };

            return(req);
        }
Esempio n. 3
0
        public async Task <HotelSearchCityRS> Get(string country, string city, DateTime checkIn, DateTime checkOut, string locale, string currency, string rooms)
        {
            HotelSearchCityRQ request = new HotelSearchCityRQ
            {
                CheckIn   = checkIn,
                CheckOut  = checkOut,
                City      = city,
                Country   = country,
                Locale    = locale,
                Currency  = currency,
                Suppliers = new List <string> {
                    "EAN", "GTA"
                },
                Occupancies = rooms.Split('|').ToList().Select(r =>
                {
                    var occu = new RoomOccupancy
                    {
                        AdultCount = Convert.ToInt32(r.Split(',')[0])
                    };

                    if (r.Split(',').Length > 1)
                    {
                        occu.ChildAges = r.Split(',').Skip(1).Select(c => Convert.ToInt32(c)).ToList();
                    }

                    return(occu);
                }).ToList()
            };

            return(await _HotelService.HotelSearchByCityAsync(request));
        }
Esempio n. 4
0
        private HotelSearchCityRS ConvertToResponse(HotelListRs rs,
                                                    HotelSearchCityRQ request, string requestKey)
        {
            HotelSearchCityRS response = new HotelSearchCityRS
            {
                CheckIn     = request.CheckIn,
                CheckOut    = request.CheckOut,
                LocationId  = request.LocationId,
                Supplier    = "EAN",
                Occupancies = request.Occupancies.ToList(),
                Locale      = request.Locale,
                Currency    = request.Currency,
                Hotels      = rs.HotelListResponse.HotelList.HotelSummary.ToList().Select(h =>
                                                                                          new HotelRS
                {
                    Id         = h.hotelId.ToString(),
                    Name       = h.name,
                    Address    = h.address1,
                    Latitude   = h.latitude,
                    Longitude  = h.longitude,
                    Location   = h.locationDescription,
                    ShortDesc  = h.shortDescription,
                    StarRating = (decimal)h.hotelRating,
                    Thumbnail  = $"https://i.travelapi.com{h.thumbNailUrl.Replace("t.jpg", "s.jpg")}",
                    CurrCode   = h.rateCurrencyCode,
                    RateFrom   = (decimal)h.lowRate,
                    RateTo     = (decimal)h.highRate,
                    HotelRooms = h.RoomRateDetailsList.RoomRateDetails.Select(rm =>
                                                                              new RoomListRS
                    {
                        RoomTypeCode   = rm.roomTypeCode.ToString(),
                        RateCode       = rm.rateCode.ToString(),
                        PromoDesc      = rm.RateInfos.RateInfo.promoDescription,
                        Allotment      = rm.RateInfos.RateInfo.currentAllotment,
                        ChargeableRate = new ChargeableRateRS
                        {
                            Currency            = rm.RateInfos.RateInfo.ChargeableRateInfo.currencyCode,
                            MaxNightlyRate      = Convert.ToDecimal(rm.RateInfos.RateInfo.ChargeableRateInfo.maxNightlyRate),
                            TotalCommissionable = Convert.ToDecimal(rm.RateInfos.RateInfo.ChargeableRateInfo.commissionableUsdTotal),
                            TotalSurcharge      = Convert.ToDecimal(rm.RateInfos.RateInfo.ChargeableRateInfo.surchargeTotal),
                            Total = Convert.ToDecimal(rm.RateInfos.RateInfo.ChargeableRateInfo.total),
                        }
                    }).OrderBy(r => r.ChargeableRate.Total).ToList()
                }
                                                                                          ).ToList()
            };

            if (rs.HotelListResponse.moreResultsAvailable)
            {
                response.CacheKey      = rs.HotelListResponse.cacheKey;
                response.CacheLocation = rs.HotelListResponse.cacheLocation;
                response.RequestKey    = requestKey;
            }

            return(response);
        }
Esempio n. 5
0
        private async Task <HotelSearchCityRS> ConvertToHotelSearchCityRS(SearchHotelPriceResponse response,
                                                                          HotelSearchCityRQ request)
        {
            var hotelCodes = response.ResponseDetails.SearchHotelPriceResponse.HotelDetails
                             .Select(htl => $"{htl.City.Code}.{htl.Item.Code}").ToList();

            var dbHotels = await _HotelRepository.GetHotelsWithImages(hotelCodes);

            HotelSearchCityRS res = new HotelSearchCityRS
            {
                CheckIn  = request.CheckIn,
                CheckOut = request.CheckOut,
                Supplier = "GTA",
                Hotels   = response.ResponseDetails.SearchHotelPriceResponse.HotelDetails.Select(htl =>
                {
                    var dbHotel = dbHotels.FirstOrDefault(h => h.Code == $"{htl.City.Code}.{htl.Item.Code}");


                    return(new HotelRS
                    {
                        Id = $"{htl.City.Code}.{htl.Item.Code}",
                        Name = htl.Item.Value,
                        Address = dbHotel?.Address1 ?? "",
                        Thumbnail = dbHotel?.HotelImageLinks?.FirstOrDefault()?.Thumbnail,
                        StarRating = htl.StarRating,
                        CurrCode = htl.RoomCategories.First().ItemPrice.Currency,
                        RateFrom = htl.RoomCategories.Min(r => r.ItemPrice.Value),
                        RateTo = htl.RoomCategories.Max(r => r.ItemPrice.Value),
                        CityCode = htl.City.Code,
                        CityName = htl.City.Value,
                        HotelRooms = htl.RoomCategories.Select(rm =>
                                                               new RoomListRS
                        {
                            Allotment = request.Occupancies.Count(),
                            RoomTypeCode = rm.Id,
                            RateCode = rm.Id,
                            PromoDesc = rm.Description,
                            ChargeableRate = new ChargeableRateRS
                            {
                                Currency = rm.ItemPrice.Currency,
                                Total = rm.ItemPrice.Value,
                                MaxNightlyRate = rm.ItemPrice.Value / (decimal)(request.CheckOut - request.CheckIn).TotalDays
                            }
                        }
                                                               ).ToList()
                    });
                }).ToList()
            };

            return(res);
        }
Esempio n. 6
0
        private bool IsValidRequest(HotelSearchCityRQ request)
        {
            if (!request.Suppliers.Contains("GTA"))
            {
                return(false);
            }

            foreach (var occ in request.Occupancies)
            {
                if (occ.AdultCount > 2)
                {
                    return(false);
                }
                if (occ.ChildAges != null)
                {
                    if (occ.ChildAges.Count() > 1)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 7
0
        public async Task <HotelSearchCityRS> HotelSearchByCityAsync(HotelSearchCityRQ request)
        {
            if (!request.Suppliers.Contains("EAN"))
            {
                return(new HotelSearchCityRS());
            }

            _LogService = new LogService();

            if (string.IsNullOrEmpty(request.Locale))
            {
                request.Locale = "en_US";
            }

            if (string.IsNullOrEmpty(request.Currency))
            {
                request.Currency = "USD";
            }

            string            sRequest = "HotelSearch_Ean_" + CreateMD5(JsonConvert.SerializeObject(request));
            HotelSearchCityRS cacheSearchRS;

            if (!_cache.TryGetValue(sRequest, out cacheSearchRS))
            {
                try
                {
                    _LogService.LogInfo("EAN/HotelSearchCityRQ", request);

                    var response = await SubmitAsync($"locale={request.Locale ?? "en_US"}" +
                                                     $"&numberOfResults=200" +
                                                     $"&currencyCode={request.Currency ?? "USD"}" +
                                                     $"&city={request.City}" +
                                                     $"&countryCode={request.Country}" +
                                                     $"&arrivalDate={request.CheckIn.ToString("MM/dd/yyyy")}" +
                                                     $"&departureDate={request.CheckOut.ToString("MM/dd/yyyy")}" +
                                                     $"&{OccupancyToString(request.Occupancies)}" +
                                                     $"&maxRatePlanCount=3",
                                                     //+     $"&includeDetails=true",
                                                     RequestType.HotelList);

                    var rs = JsonConvert.DeserializeObject <HotelListRs>(response);
                    HotelSearchCityRS cityResponse = ConvertToResponse(rs, request, sRequest);

                    _LogService.LogInfo($"EAN/HotelSearchCityRS", cityResponse);

                    if (cityResponse != null)
                    {
                        var cacheEntryOptions = new MemoryCacheEntryOptions()
                                                // Keep in cache for this time, reset time if accessed.
                                                .SetAbsoluteExpiration(TimeSpan.FromHours(1));

                        // Save data in cache.
                        _cache.Set(sRequest, cityResponse, cacheEntryOptions);
                    }

                    return(cityResponse);
                }
                catch (Exception ex)
                {
                    _LogService.LogException(ex, "Ean.HotelService.HotelSearchByCity");
                    return(new HotelSearchCityRS());
                }
                finally
                {
                    _LogService = null;
                }
            }
            //else
            //{
            //    cacheSearchRS.CacheKey = "";
            //    cacheSearchRS.CacheLocation = "";
            //    cacheSearchRS.RequestKey = "";
            //}

            return(cacheSearchRS);
        }