public SearchOffersResponse Get(string phrase, string translatedPhrase, string categoryId, OfferStateEnum state, OfferSortingEnum sorting, int offset, int limit, int?processTopCnt, string searchToken) { _tokenSource = new CancellationTokenSource(); try { if (searchToken != "sfdfjiojaa5345zfhsery7JHG") { throw new AuthenticationException("Invalid token"); } var token = _tokenSource.Token; var res = _client.SearchOffersAsync(phrase, translatedPhrase, categoryId, state, sorting, offset, limit, processTopCnt, token).Result; return(res); } catch (Exception er) { throw; } finally { _tokenSource.Dispose(); } }
public override async Task <EkKioskProductSearchInEuropeGetResponse> ExecuteAsync(EkKioskProductSearchInEuropeGetRequest request) { //var kioskId = _currentUser.Id; //if (kioskId == 75) //{ // return await MySpecialLogicAsync(); //} var categoryId = request.CategoryId; if (string.IsNullOrEmpty(categoryId)) { categoryId = AutomotiveCategoryId; } OfferStateEnum offerState; switch (request.State) { case EkProductStateEnum.New: offerState = OfferStateEnum.New; break; case EkProductStateEnum.Used: offerState = OfferStateEnum.Used; break; case EkProductStateEnum.Recovered: offerState = OfferStateEnum.Recovered; break; case EkProductStateEnum.Broken: offerState = OfferStateEnum.Broken; break; default: offerState = OfferStateEnum.All; break; } OfferSortingEnum offerSorting; switch (request.Sorting) { case EkProductSearchSortingEnum.PriceAscending: offerSorting = OfferSortingEnum.PriceAsc; break; case EkProductSearchSortingEnum.PriceDescending: offerSorting = OfferSortingEnum.PriceDesc; break; default: case EkProductSearchSortingEnum.Default: offerSorting = OfferSortingEnum.Relevance; break; } // cancellation token var cancellationToken = _httpContextAccessor.HttpContext?.RequestAborted ?? CancellationToken.None; var searchOffersResponse = await _allegroPlClient.SearchOffersAsync( request.Term, request.TranslatedTerm, categoryId, offerState, offerSorting, request.From, request.Count, cancellationToken); try { await _allegroPlClient.ApplyTranslations(_translateService, searchOffersResponse.Offers, request.Term, request.TranslatedTerm, cancellationToken); } catch { } EkProduct[] products; if (searchOffersResponse.Offers?.Length > 0) { var exchangeRate = 6;//await GetExchangeRateAsync(); products = searchOffersResponse.Offers .Select(x => EkConvertHelper.EkAllegroPlOfferToProduct(x, exchangeRate)) .ToArray(); } else { products = new EkProduct[0]; } return(new EkKioskProductSearchInEuropeGetResponse() { Products = products, Total = searchOffersResponse.Total, TranslatedTerm = searchOffersResponse.TranslatedPhrase, }); }