private async Task <List <GroupBookList <object> > > GetGroupedMoochBooks(string queryText) { try { List <GroupBookList <object> > BookGroups = new List <GroupBookList <object> >(); MoochBooksList instanceMoochBooks = new MoochBooksList(); ObservableCollection <MoochBooks> bookList = await instanceMoochBooks.GetMoochBooks(queryText); var query = from book in bookList orderby((MoochBooks)book).Title group book by((MoochBooks) book).Topics[0] into books select new { GroupName = books.Key, Items = books }; foreach (var books in query) { GroupBookList <object> info = new GroupBookList <object>(); info.Group = books.GroupName; foreach (var book in books.Items) { info.Add(book); } BookGroups.Add(info); } return(BookGroups); } catch (TaskCanceledException ex) { return(null); } }
private async Task <List <GroupBookList <object> > > GetBooksByTitle() { List <GroupBookList <object> > BookGroups = new List <GroupBookList <object> >(); ObservableCollection <Books> bookList = await GetBookLists(); var query = from book in bookList orderby((Books)book).title group book by((Books) book).category__name into books select new { GroupName = books.Key, Items = books }; foreach (var books in query) { GroupBookList <object> info = new GroupBookList <object>(); info.Group = books.GroupName; foreach (var book in books.Items) { info.Add(book); } BookGroups.Add(info); } return(BookGroups); }
private async Task <List <GroupBookList <object> > > GetBooksByTitle(string queryText) { List <GroupBookList <object> > BookGroups = new List <GroupBookList <object> >(); ObservableCollection <MoochBooks> bookList = await GetMoochBooks(queryText); var query = from book in bookList orderby((MoochBooks)book).Title group book by((MoochBooks) book).Topics[0] into books select new { GroupName = books.Key, Items = books }; foreach (var books in query) { GroupBookList <object> info = new GroupBookList <object>(); info.Group = books.GroupName; foreach (var book in books.Items) { info.Add(book); } BookGroups.Add(info); } return(BookGroups); }
private async Task <List <GroupBookList <object> > > GetBookSearchResult(string searchTerm) { try { BookList instanceBooks = new BookList(); List <GroupBookList <object> > BookGroups = new List <GroupBookList <object> >(); ObservableCollection <Books> bookList = await instanceBooks.GetBookLists(); var query = from book in bookList where ((Books)book).title.ToLower().Contains(searchTerm.ToLower()) orderby((Books)book).title group book by((Books)book).category__name into books select new { GroupName = books.Key, Items = books, Number = books.Count() }; foreach (var books in query) { GroupBookList <object> info = new GroupBookList <object>(); info.Group = books.GroupName; info.ItemsNumber = books.Number; foreach (var book in books.Items) { info.Add(book); } BookGroups.Add(info); } return(BookGroups); } catch (TaskCanceledException ex) { return(null); } }
protected async override void OnNavigatedTo(NavigationEventArgs args) { var queryText = args.Parameter.ToString().ToLower() as String; GoogleBooks booksList = await GetGoogleBookList(queryText); if (booksList != null) { List <GroupBookList <object> > BookGroups = new List <GroupBookList <object> >(); ObservableCollection <Items> booksItems = booksList.items; var query = from book in booksItems orderby((Items)book).volumeInfo.title group book by((Items) book).volumeInfo.categories[0] into books select new { GroupName = books.Key, Items = books }; foreach (var books in query) { GroupBookList <object> info = new GroupBookList <object>(); info.Group = books.GroupName; foreach (var book in books.Items) { info.Add(book); } BookGroups.Add(info); } int countBooks = BookGroups.Count; var totalItems = 0; var searchFilters = new List <Filter>(); SearchResult = new Dictionary <string, IEnumerable <Items> >(); if (countBooks > 0) { foreach (var groups in BookGroups) { IEnumerable <Items> matchItems = booksItems.Where(book => book.volumeInfo.title.ToLower().Contains(queryText) && book.volumeInfo.categories[0] == (string)groups.Group); int itemsNumber = matchItems.Count <Items>(); totalItems = totalItems + itemsNumber; } searchFilters.Add(new Filter("All", totalItems, true)); foreach (var groups in BookGroups) { IEnumerable <Items> matchItems = booksItems.Where(book => book.volumeInfo.title.ToLower().Contains(queryText) && book.volumeInfo.categories[0] == (string)groups.Group); int itemsNumber = matchItems.Count <Items>(); if (itemsNumber > 0) { SearchResult.Add(groups.Group.ToString(), matchItems); searchFilters.Add(new Filter(groups.Group.ToString(), itemsNumber, false)); totalItems = totalItems + itemsNumber; } } } else { VisualStateManager.GoToState(this, "NoResultsFound", true); } this.DefaultViewModel["QueryText"] = '\u201c' + queryText + '\u201d'; this.DefaultViewModel["Filters"] = searchFilters; this.DefaultViewModel["ShowFilters"] = searchFilters.Count > 1; } else { var popup = new Windows.UI.Popups.MessageDialog("Couldnt fetch books. Plaease check your internet connection."); popup.Commands.Add(new Windows.UI.Popups.UICommand("Try Again")); popup.Commands.Add(new Windows.UI.Popups.UICommand("Cancel")); popup.DefaultCommandIndex = 0; popup.CancelCommandIndex = 1; var results = await popup.ShowAsync(); if (results.Label == "Try Again") { OnNavigatedTo(args); } else { this.Frame.GoBack(); } } }
protected async override void OnNavigatedTo(NavigationEventArgs args) { try { Dictionary <string, string> parameter = new Dictionary <string, string>(); parameter = args.Parameter as Dictionary <string, string>; int index = Convert.ToInt32(parameter["index"]); string queryText = parameter["query"]; GoogleBooks booksList = await GetGoogleBookLists(queryText, index); List <GroupBookList <object> > BookGroups = new List <GroupBookList <object> >(); ObservableCollection <Items> booksItems = booksList.items; var query = from book in booksItems orderby((Items)book).volumeInfo.title group book by((Items) book).volumeInfo.categories[0] into books select new { GroupName = books.Key, Items = books }; foreach (var books in query) { GroupBookList <object> info = new GroupBookList <object>(); info.Group = books.GroupName; foreach (var book in books.Items) { info.Add(book); } BookGroups.Add(info); } if (BookGroups != null) { VisualStateManager.GoToState(this, "ResultsFound", true); groupedGoogleBooks.Source = BookGroups; } else { ShowProgressRing(); } } catch (Exception ex) { var popup = new Windows.UI.Popups.MessageDialog("The app couldn't load books. Please check your connection and try again"); popup.Commands.Add(new Windows.UI.Popups.UICommand("Try Again")); popup.Commands.Add(new Windows.UI.Popups.UICommand("Cancel")); popup.DefaultCommandIndex = 0; popup.CancelCommandIndex = 1; var results = await popup.ShowAsync(); if (results.Label == "Try Again") { ShowProgressRing(); OnNavigatedTo(args); } else { this.Frame.Navigate(typeof(HomePage)); } } }