public async Task <ProviderBookOffer> SearchOffersByIsbnAsync(string isbn) { try { var response = await AmazonWrapper.SearchAsync(isbn, AmazonSearchIndex.Books, AmazonResponseGroup.Offers); var item = response.Items.Item.FirstOrDefault(); var itemOffer = item.Offers.Offer.FirstOrDefault(); var itemOfferListing = itemOffer.OfferListing.FirstOrDefault(); return(new ProviderBookOffer { Title = item.ItemAttributes.Title, Isbn = item.ItemAttributes.ISBN, Provider = Name, Price = decimal.Parse(itemOfferListing.Price.Amount), CurrencyCode = itemOfferListing.Price.CurrencyCode, Url = itemOfferListing.OfferListingId }); } catch (Exception e) { _logger.LogError(e, "Amazon: Search offers failed."); return(new ProviderBookOffer()); } }
public async Task <IEnumerable <ProviderBookSearchItem> > SearchByTitleAsync(string title) { try { var response = await AmazonWrapper.SearchAsync(title, AmazonSearchIndex.Books, AmazonResponseGroup.Small); return(response.Items.Item .Select(x => new ProviderBookSearchItem { Title = x.ItemAttributes.Title, Isbn = new IsbnData { Id10Digits = x.ItemAttributes.ISBN }, Authors = x.ItemAttributes.Author, Provider = Name }) .ToList()); } catch (Exception e) { _logger.LogError(e, "Amazon: Search books failed."); return(Enumerable.Empty <ProviderBookSearchItem>()); } }
private async void buttonSearch_Click(object sender, EventArgs e) { var search = this.textBoxSearch.Text; var endpoint = (AmazonEndpoint)this.comboBoxEndpoint.SelectedItem; var searchIndex = (AmazonSearchIndex)this.comboBoxSearchIndex.SelectedItem; var responseGroup = (AmazonResponseGroup)this.comboBoxResponseGroup.SelectedItem; var wrapper = new AmazonWrapper(this._authentication, endpoint, "nagerat-21"); wrapper.XmlReceived += XmlReceived; var result = await wrapper.SearchAsync(search, searchIndex, responseGroup); wrapper.XmlReceived -= XmlReceived; if (result == null) { this.tabControl1.SelectedIndex = 1; MessageBox.Show("Request error"); return; } this.dataGridViewResult.DataSource = result.Items.Item; }