/// <summary> /// Creates book object from google API. /// </summary> /// <param name="url">The URL.</param> /// <returns>returns true if successful and false if not</returns> public async static Task <Book> CreateBookFromGoogleApi(string url) { JObject jObject = await GoogleBookApiController.GetSpesificBook(url); Book b = new Book(); //b.BookId = jObject["id"].Value<string>(); b.BookId = jObject.Value <string>("id"); b.Title = jObject["volumeInfo"].Value <string>("title"); b.PublisherDate = jObject["volumeInfo"].Value <string>("publishedDate"); if (jObject["volumeInfo"].SelectTokens("authors").Count() > 0) { foreach (var item in jObject["volumeInfo"].SelectTokens("authors").FirstOrDefault()) { b.Author += item.ToString().Replace("[", "").Replace("]", "").Replace("\"", "").Trim(); } } else { b.Author = "No Author found"; } b.Publisher = jObject["volumeInfo"].Value <string>("publisher"); b.PageCount = Int32.Parse(jObject["volumeInfo"].Value <string>("pageCount")); b.Description = jObject["volumeInfo"].Value <string>("description"); b.imageUrl = jObject["volumeInfo"].SelectTokens("imageLinks").First().Value <string>("thumbnail"); return(b); }
/// <summary>Collecteds data needed for a search. then sends that data to the api and the results is populated in gridview with FillGridView method /// pluss it does alot of frontend stuff at the same time /// </summary> private async Task SearchAsync() { IsGridViewVisible(false); string GetComboBoxItemContent(string searchTerm) { if (searchTerm.Equals("All")) { return(""); } if (searchTerm.Equals("Title")) { return("intitle"); } if (searchTerm.Equals("Authors")) { return("inauthor"); } if (searchTerm.Equals("Publisher")) { return("inpublisher"); } else { return(searchTerm); } } searchResultCollection.Clear(); IsLoading(true); MyTextBlock_Background_Message.Visibility = Visibility.Collapsed; if (MyTextBox_SeachWord.Text.Length > 0) { ComboBoxItem searchTerm = (ComboBoxItem)MyComboBox_SearchTerms.SelectedItem; ComboBoxItem orderBy = (ComboBoxItem)MyComboBox_Sorting.SelectedItem; var searchResults = await GoogleBookApiController.Search(10, MyTextBox_SeachWord.Text, GetComboBoxItemContent(searchTerm.Content.ToString()), orderBy.Content.ToString(), 0); if (await FillGridView(searchResults)) { MyGridView.Header = $"Results: {MyGridView.Items.Count}/{await GoogleBookApiController.SearchInfo(MyTextBox_SeachWord.Text)}"; MyGridView.SelectedIndex = 0; IsGridViewVisible(true); IsLoading(false); } else { MyGridView.Header = "No results found..."; } } else { MyTextBox_SeachWord.PlaceholderText = "Empty field..."; } }
/// <summary> /// Creates book object from google API light weight. /// </summary> /// <param name="url">The URL.</param> /// <returns>returns true if successful and false if not</returns> public async static Task <Book> CreateBookFromGoogleApiLightWeight(string url) { JObject jObject = await GoogleBookApiController.GetSpesificBook(url); Book b = new Book(); b.BookId = jObject.Value <string>("id"); b.Title = jObject["volumeInfo"].Value <string>("title"); b.imageUrl = jObject["volumeInfo"].SelectTokens("imageLinks").FirstOrDefault().Value <string>("thumbnail"); return(b); }
/* XAML METHODES */ /// <summary> /// Handles the Loaded event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Windows.UI.Xaml.RoutedEventArgs" /> instance containing the event data.</param> private async void Page_Loaded(object sender, RoutedEventArgs e) { if (InternettChecker.CheckForInternetConnection()) { MyTextBlock_LoggedInUser.Visibility = Visibility.Collapsed; MyPivot.Items.Add(MyPivotItem_Login); DonauApi.ApiHelper.InitializeClient(); GoogleBookApiController.InitializeClient(); } else { MyTextBlock_LoggedInUser.Visibility = Visibility.Collapsed; ContentDialogResult result = await new ContentDialogController().CreateErrorContentDialog("Application does not have a internet connection!\n\nClick the button to close the application\nand connect to the internet and try again").ShowAsync(); if (result == ContentDialogResult.None) { Application.Current.Exit(); } } }