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); }
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); }
private HotelSearchCityRS ConvertToResponse(HotelListRs rs, HotelGetMoreRQ request) { HotelSearchCityRS response = new HotelSearchCityRS { Supplier = "EAN", 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 = h.thumbNailUrl, CurrCode = h.rateCurrencyCode, RateFrom = (decimal)h.lowRate, RateTo = (decimal)h.highRate } ).ToList() }; if (rs.HotelListResponse.moreResultsAvailable) { response.CacheKey = rs.HotelListResponse.cacheKey; response.CacheLocation = rs.HotelListResponse.cacheLocation; response.RequestKey = request.RequestKey; } return(response); }
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" + $"¤cyCode={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); }
public async Task <HotelSearchCityRS> HotelGetMoreAsync(HotelGetMoreRQ 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"; } try { _LogService.LogInfo("EAN/HotelGetMoreRQ", request); var response = await SubmitAsync($"locale={request.Locale ?? "en_US"}" + $"¤cyCode={request.Currency ?? "USD"}" + $"&cachekey={request.CacheKey}" + $"&cachelocation={request.CacheLocation}" + $"&maxRatePlanCount=3", //+ $"&includeDetails=true", RequestType.HotelList); var rs = JsonConvert.DeserializeObject <HotelListRs>(response); HotelSearchCityRS hotelSearchCityRS = ConvertToResponse(rs, request); _LogService.LogInfo("EAN/HotelGetMoreRS", hotelSearchCityRS); //Add result to cache HotelSearchCityRS cacheSearchRS; var cacheEntryOptions = new MemoryCacheEntryOptions() // Keep in cache for this time, reset time if accessed. .SetAbsoluteExpiration(TimeSpan.FromHours(1)); if (!_cache.TryGetValue(request.RequestKey, out cacheSearchRS)) { _cache.Set(request.RequestKey, hotelSearchCityRS, cacheEntryOptions); } else { hotelSearchCityRS.Hotels.ForEach(hotel => { if (cacheSearchRS.Hotels.FirstOrDefault(h => h.Id == hotel.Id) == null) { cacheSearchRS.Hotels.Add(hotel); } }); if (rs.HotelListResponse.moreResultsAvailable) { cacheSearchRS.CacheKey = rs.HotelListResponse.cacheKey; cacheSearchRS.CacheLocation = rs.HotelListResponse.cacheLocation; cacheSearchRS.RequestKey = request.RequestKey; } _cache.Set(request.RequestKey, cacheSearchRS, cacheEntryOptions); } return(hotelSearchCityRS); } catch (Exception ex) { _LogService.LogException(ex, "Ean.HotelService.HotelGetMoreAsync"); return(new HotelSearchCityRS()); } finally { _LogService = null; } }