public async Task <Result <LocationResponseDto> > GetLocationAsync(LocationRequestDto request, CancellationToken cancellationToken) { if (request == null) { return(Result.ObjectValidationFail <LocationResponseDto>("Invaid Request")); } if (!request.IsValid()) { return(Result.ObjectValidationFail <LocationResponseDto>(request.Validate())); } var locationSearchEngine = new LocationSearchEngine("skyscanner"); var p = await locationSearchEngine.GetByIDAsync(request.Market[0], request.Currency, request.Locale, request.Id, cancellationToken).ConfigureAwait(false); var location = new LocationResponseDto { PlaceId = p.PlaceId.Replace("-sky", ""), PlaceName = p.PlaceName, CityId = p.CityId.Replace("-sky", ""), CountryId = p.CountryId.Replace("-sky", ""), CountryName = p.CountryName, RegionId = "" }; return(Result.Ok(location)); }
public async Task <Result <LocationAutoSuggestResponseDto> > LocationAutoSuggestAsync(LocationAutoSuggestRequestDto request, CancellationToken cancellationToken) { if (request == null) { return(Result.ObjectValidationFail <LocationAutoSuggestResponseDto>("Invaid Request")); } if (!request.IsValid()) { return(Result.ObjectValidationFail <LocationAutoSuggestResponseDto>(request.Validate())); } var response = new LocationAutoSuggestResponseDto(); Boolean anywhereAdded = false; Boolean nearestAdded = false; if (!string.IsNullOrEmpty(request.Search)) { if ("anywhere".Contains(request.Search.ToLower())) { anywhereAdded = true; response.Locations.Add(new LocationResponseDto { PlaceId = "anywhere", PlaceName = "Anywhere" }); } if ("nearest current".Contains(request.Search.ToLower())) { nearestAdded = true; response.Locations.Add(new LocationResponseDto { PlaceId = "nearest", PlaceName = "Nearest Airport" }); } var locationSearchEngine = new LocationSearchEngine("skyscanner"); cancellationToken.ThrowIfCancellationRequested(); var results = await locationSearchEngine.SearchByQueryAsync(request.Market[0], request.Currency, request.Locale, request.Search, cancellationToken).ConfigureAwait(false); foreach (Place p in results.Places) { var location = new LocationResponseDto { PlaceId = p.PlaceId.Replace("-sky", ""), PlaceName = p.PlaceName, CityId = p.CityId.Replace("-sky", ""), CountryId = p.CountryId.Replace("-sky", ""), CountryName = p.CountryName, RegionId = p.RegionId.Replace("-sky", "") }; response.Locations.Add(location); } } if (!anywhereAdded) { response.Locations.Add(new LocationResponseDto { PlaceId = "anywhere", PlaceName = "Anywhere" }); } if (!nearestAdded) { response.Locations.Add(new LocationResponseDto { PlaceId = "nearest", PlaceName = "Nearest Airport" }); } return(Result.Ok(response)); }