Exemple #1
0
        private async void btnBuscar_Click(object sender, EventArgs e)
        {
            if (btnBuscar.Enabled)
            {
                statusButtonBuscar(false);
                string             search   = txtPesquisa.Text;
                PesquisaController pesquisa = new PesquisaController();
                changeStatusSearchPanel(true);
                ItemsBook books = await pesquisa.getBooks(search, startIndex : page);

                List <string> bookIds = Favorite.getAllId().ToList();
                if (books.items != null && books.items.Count() > 0)
                {
                    foreach (var book in books.items)
                    {
                        if (bookIds.Any <string>(bk => bk.Equals(book.id)))
                        {
                            book.Favorite = true;
                        }
                        UcCardBook card = new UcCardBook(book);
                        card.Name = "book" + book.id;

                        fpnlBooks.Controls.Add(card);
                    }
                    pnlFundo.Refresh();
                }
                totalItems = books.totalItems;
                setStatusButtons();
                setButtonVisibility(true);
                changeStatusSearchPanel(false);
                statusButtonBuscar(true);
            }
        }
Exemple #2
0
        public async Task <ItemsBook> getBooks(string searchContent, int startIndex = 0, int maxResults = 0)
        {
            ItemsBook books  = new ItemsBook();
            string    result = "";

            if (maxResults == 0)
            {
                maxResults = this.maxResults;
            }
            if (!string.IsNullOrEmpty(searchContent))
            {
                string[] words = searchContent.Split(' ');
                searchContent = string.Join("+", words);
            }
            startIndex = (startIndex) * maxResults;
            string url = $"{endPointApi}?key={keyApi}{(!string.IsNullOrEmpty(searchContent) ? $"&q={WebUtility.UrlEncode(searchContent)}" : "")}&maxResults={maxResults}&startIndex={startIndex}";

            result = await getResult(url);

            books = JsonSerializer.Deserialize <ItemsBook>(result);
            return(books);
        }