Ejemplo n.º 1
0
        static void MainMenu()
        {
            /*This is a menu*/
            TxtManagement        txt       = new TxtManagement();
            bool                 exit      = false;
            List <MovingPicture> movieList = txt.GetMovieList();

            do
            {
                Console.Clear();
                Console.WriteLine("1 -> See list of movies");
                Console.WriteLine("2 -> See list of documentaries");
                Console.WriteLine("3 -> See all content");
                Console.WriteLine("4 -> Search");
                Console.WriteLine("5 -> Add Content");
                Console.WriteLine("6 -> Exit");

                bool boolChoice = int.TryParse(Convert.ToString(Console.ReadKey().KeyChar), out int intChoice);
                switch (intChoice)
                {
                case 1:
                    PrintMovies(movieList, "movie");
                    Console.ReadKey();
                    break;

                case 2:
                    PrintMovies(movieList, "documentary");

                    Console.ReadKey();
                    break;

                case 3:
                    PrintMovies(movieList, "all");
                    Console.ReadKey();
                    break;

                case 4:
                    SearchFunction();
                    Console.ReadKey();
                    break;

                case 5:
                    txt.WriteToFile();
                    MainMenu();
                    break;

                case 6:
                    exit = true;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine("Choose an option and try again");
                    Console.ReadKey();
                    break;
                }
            } while (exit == false);
        }
Ejemplo n.º 2
0
        static void SearchFunction()
        {
            /*Gets a list of MovingPicture and checks if the search query is contained inside that object for each item in the list and then adds that object to another list if true
             * which is then printed with PrintMovies() to create a search results page.*/

            TxtManagement        txt          = new TxtManagement();
            List <MovingPicture> movieList    = txt.GetMovieList();
            List <MovingPicture> movieResults = new List <MovingPicture>();

            Console.Clear();
            string[] options      = new string[] { "title", "genre", "theme", "director", "actor", "length", "short-movie" };
            string   searchChoice = "";
            string   searchQuery  = "";

            bool validChoice = true;

            do
            {
                Console.Clear();
                searchChoice = txt.UserInput("What do you want to search for? Title, Genre, Theme, Director, Actor, Length, Short-movie").ToLower();
                if (options.Contains(searchChoice) == false)
                {
                    Console.Clear();
                    Console.WriteLine("You can only use the given categories. Press 'e' to exit or any other key to continue");
                    char exitChar = Console.ReadKey().KeyChar;
                    switch (exitChar)
                    {
                    case 'e':
                        MainMenu();
                        break;

                    default:
                        validChoice = false;
                        break;
                    }
                }
            } while (validChoice == false);


            if (searchChoice != "short-movie")
            {
                searchQuery = txt.UserInput("Type your search query").ToLower();
            }


            if (searchChoice == "genre")
            {
                foreach (MovingPicture item in movieList)
                {
                    if (item.Type == "Movie")
                    {
                        if (ConvertFromList(((Movie)item).Genre).ToLower().Contains(searchQuery) == true) /*Here I cast the MovingPicture object to a Movie object knowing that only Movie objects contain the
                                                                                                           * type "Movie"*/
                        {
                            movieResults.Add(item);
                        }
                    }
                }
            }
            else if (searchChoice == "actor")
            {
                foreach (MovingPicture item in movieList)
                {
                    if (item.Type == "Movie")
                    {
                        if (ConvertFromList(((Movie)item).Cast).ToLower().Contains(searchQuery) == true)
                        {
                            movieResults.Add(item);
                        }
                    }
                }
            }
            else if (searchChoice == "theme")
            {
                foreach (MovingPicture item in movieList)
                {
                    if (item.Type == "Documentary")
                    {
                        if (ConvertFromList(((Documentary)item).Theme).ToLower().Contains(searchQuery) == true)
                        {
                            movieResults.Add(item);
                        }
                    }
                }
            }
            else if (searchChoice == "director")
            {
                foreach (MovingPicture item in movieList)
                {
                    if (item.Director.ToLower().Contains(searchQuery))
                    {
                        movieResults.Add(item);
                    }
                }
            }
            else if (searchChoice == "length")
            {
                double searchLength = Convert.ToDouble(searchQuery);
                foreach (MovingPicture item in movieList)
                {
                    if (item.Length == searchLength || ((item.Length >= searchLength - 0.25 * searchLength) && (item.Length <= searchLength + 0.25 * searchLength)))
                    {
                        movieResults.Add(item);
                    }
                }
            }
            else if (searchChoice == "title")
            {
                foreach (MovingPicture item in movieList)
                {
                    if (item.Title.ToLower().Contains(searchQuery) == true)
                    {
                        movieResults.Add(item);
                    }
                }
            }
            else if (searchChoice == "short-movie")
            {
                foreach (MovingPicture item in movieList)
                {
                    if (item.Length <= 60)
                    {
                        movieResults.Add(item);
                    }
                }
            }

            PrintMovies(movieResults, "all");
        }