private static void UserLoadMovieList() { Console.WriteLine("Please type filename to load (no extension) or \"Q\" to return to menu"); var fileName = Console.ReadLine().Trim(); if (fileName.ToUpper() == "Q") { MainMenu(); } while (!File.Exists(fileName + _extension)) { if (fileName.ToUpper() == "Q") { MainMenu(); } Console.WriteLine("File does not exist, please try again or type \"Q\" to return to menu."); fileName = Console.ReadLine().Trim(); while (string.IsNullOrWhiteSpace(fileName) || (fileName + _extension).IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { if (fileName.ToUpper() == "Q") { MainMenu(); } Console.WriteLine("Please enter a valid filename with no extension or \"Q\" to return to menu"); fileName = Console.ReadLine().Trim(); } } var movies = MovieInteraction.LoadMovieList(fileName + _extension); UserListInteraction(movies, fileName); }
private static void UserSaveList(List <Movie> movies) { Console.WriteLine("Please type filename to save to (one word, no extension) or \"Q\" to return to menu."); var fileName = Console.ReadLine().Trim(); if (fileName.ToUpper() == "Q") { return; } while (string.IsNullOrWhiteSpace(fileName) || fileName.IndexOfAny(Path.GetInvalidFileNameChars()) > 0) { if (fileName.ToUpper() == "Q") { return; } Console.WriteLine("Please enter a valid filename with no extension or \"Q\" to return"); fileName = Console.ReadLine().Trim(); } if (!File.Exists(fileName + _extension) && fileName != "Q") { MovieInteraction.SaveMoviesToList(movies, (fileName + _extension)); } else { if (fileName.ToUpper() == "Q") { return; } MovieInteraction.AddMoviesToList(movies, (fileName + _extension)); } }
private static void MainSearch() { List <Movie> searchedMovieList = new List <Movie>(); Console.Clear(); // Gets something to search for Console.WriteLine(_banner + "Type the name of the movie or show you want to search for:"); var input = Console.ReadLine().Trim(); while (string.IsNullOrWhiteSpace(input)) { Console.WriteLine("Please type something."); input = Console.ReadLine().Trim(); } var movieChoice = input; // Perform serch on OMDB Search[] omdbSearchResults = WebInteraction.SearchOmdbByString(movieChoice); // Put results into a list of movies with titles, directors, ratings, etc if (omdbSearchResults == null) { // Getting null is usually a "too many results" error, so we'll take what we get here OmdbResult newOmdbResults = WebInteraction.SearchOmdbForTitle(movieChoice); Movie movie = new Movie { Title = newOmdbResults.Title, ImdbId = newOmdbResults.ImdbId, Year = newOmdbResults.Year, Poster = newOmdbResults.Poster, Actors = newOmdbResults.Actors, Director = newOmdbResults.Director, ImdbRating = newOmdbResults.ImdbRating, Metascore = newOmdbResults.Metascore, Plot = newOmdbResults.Plot, Rated = newOmdbResults.Rated, Ratings = newOmdbResults.Ratings, }; searchedMovieList.Add(movie); } else { searchedMovieList = MovieInteraction.CreateListOfOmdbResults(omdbSearchResults); } Console.Clear(); Console.WriteLine($"You searched for {movieChoice}.\r\n\r\n"); ShowAndPickOmdbSearch(searchedMovieList); }
private static void UserListInteraction(List <Movie> movies, string fileName) { Console.Clear(); Console.WriteLine($"File Loaded: {fileName}.json\r\n\r\n"); Console.WriteLine(DisplayMovieInfo(movies)); Console.WriteLine("\r\nType \"S\" to save movie to a different file, type \"C\" to Copy list to another file, type \"D\" to Delete movie from list, or type \"R\" to Reload streaming providers for a result.\r\nType \"F\" to find a new movie or show, type \"L\" to load another file.\r\nType \"Q\" to quit."); var menuChoice = Console.ReadLine().ToUpper().Trim(); while (menuChoice != "S" && menuChoice != "C" && menuChoice != "D" && menuChoice != "R" && menuChoice != "F" && menuChoice != "L" && menuChoice != "Q") { Console.WriteLine("Please enter S (Save movie to different file), C (Copy list to another list), D (Delete a movie), R (Reload providers), F (Find a movie), L (Load a file), or Q (Quit)"); menuChoice = Console.ReadLine().ToUpper().Trim(); } switch (menuChoice) { case "S": int i = UserPicksArray(); while (i >= movies.Count || i < 0) { Console.WriteLine("Selection is out of range, please pick again"); i = UserPicksArray(); } UserSaveMovie(movies[i]); Console.WriteLine("List may need to be reloaded. Press any key to continue"); Console.ReadKey(); UserListInteraction(movies, fileName); break; case "C": UserSaveList(movies); Console.WriteLine("Press any key to continue"); Console.ReadKey(); UserListInteraction(movies, fileName); break; case "D": i = UserPicksArray(); while (i >= movies.Count || i < 0) { Console.WriteLine("Selection is out of range, please pick again"); i = UserPicksArray(); } movies.RemoveAt(i); MovieInteraction.SaveMoviesToList(movies, fileName + _extension); Console.WriteLine("Press any key to continue"); Console.ReadKey(); UserListInteraction(movies, fileName); break; case "R": i = UserPicksArray(); while (i >= movies.Count || i < 0) { Console.WriteLine("Selection is out of range, please pick again"); i = UserPicksArray(); } var results = WebInteraction.SearchUtellyById(movies[i].ImdbId); movies[i].Locations = results.collection.Locations; MovieInteraction.SaveMoviesToList(movies, fileName + _extension); Console.WriteLine("Press any key to continue"); Console.ReadKey(); UserListInteraction(movies, fileName); break; case "F": MainSearch(); break; case "L": UserLoadMovieList(); break; case "Q": break; } }