/// <summary> /// the function below is designed to download json data from the mock json data set after searching, /// using a term supplied by the user, it sifts through the pages of the search results and prints /// the titles of the found movies /// </summary> /// <param name="substr"></param> /// <returns></returns> public static string[] getMovieTitles(string substr) { string url = "https://jsonmock.hackerrank.com/api/movies/search/?Title=" + substr; string[] movies = { }; using (var w = new WebClient()) { var jsonData = string.Empty; try { jsonData = w.DownloadString(url); result = JsonConvert.DeserializeObject <MoviesResult>(jsonData); // to get pageNumbers int numPages = result.total_pages; int total_Results = 0; for (int i = 1; i <= numPages; i++) { jsonData = w.DownloadString(url + "&page=" + i); result = JsonConvert.DeserializeObject <MoviesResult>(jsonData); Console.WriteLine("Printing All Search Results for: " + substr); foreach (Movie m in result.data) { Console.WriteLine(m.title); total_Results++; } } Console.WriteLine(total_Results + " Results Found."); } catch (Exception ex) { Console.WriteLine("failed to load movies, " + ex); } } return(movies); }
private void view_all_Click(object sender, RoutedEventArgs e) { search_string = ""; _viewModel.clear_search(); view_all.Visibility = Visibility.Collapsed; selected = null; _viewModel.LoadPage(); }
private void resultListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (resultListBox.SelectedItem is Model.MoviesResult) { selected = (Model.MoviesResult)resultListBox.SelectedItem; NavigationService.Navigate(new Uri("/info.xaml?id=" + selected.ImdbID + "&url=" + selected.Link + "&share_link=" + selected.Share_URL + "&search=" + _viewModel.get_search() + "&name=" + selected.Title, UriKind.Relative)); } resultListBox.SelectedItem = null; }
private void search_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { selected = null; view_all.Visibility = Visibility.Visible; _viewModel.set_search(search.Text); this.Focus(); } }
private void Search_Tap(object sender, System.Windows.Input.GestureEventArgs e) { selected = null; view_all.Visibility = Visibility.Visible; _viewModel.set_search(search.Text); }