Пример #1
0
        static void Main(string[] args)
        {
            // Dependency injection
            var serviceProvider = new ServiceCollection()
                                  .BuildServiceProvider();

            Console.WriteLine("Which media type would you like to display? M - Movie, S -Show, V - Video");
            string mediaChoice = Console.ReadLine();

            string movieFilePath = Directory.GetCurrentDirectory() + "\\movies.csv";
            string showFilePath  = Directory.GetCurrentDirectory() + "\\shows.csv";
            string videoFilePath = Directory.GetCurrentDirectory() + "\\videos.csv";

            logger.Info("Program started");

            MovieFile movieFile = new MovieFile(movieFilePath);
            ShowFile  showFile  = new ShowFile(showFilePath);
            VideoFile videoFile = new VideoFile(videoFilePath);

            do
            {
                if (mediaChoice == "M")
                {
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
                else if (mediaChoice == "S")
                {
                    foreach (Show s in showFile.Shows)
                    {
                        Console.WriteLine(s.Display());
                    }
                }
                else if (mediaChoice == "V")
                {
                    foreach (Video v in videoFile.Videos)
                    {
                        Console.WriteLine(v.Display());
                    }
                }
            } while (mediaChoice == "M" || mediaChoice == "S" || mediaChoice == "V");

            logger.Info("Program ended");
        }
Пример #2
0
        static void Main(string[] args)
        {
            string movieFilePath = Directory.GetCurrentDirectory() + "\\movies.csv";

            logger.Info("Program started");

            MovieFile movieFile = new MovieFile(movieFilePath);

            string choice = "";

            do
            {
                // display choices to user
                Console.WriteLine("1) Add Movie");
                Console.WriteLine("2) Display All Movies");
                Console.WriteLine("Enter to quit");
                // input selection
                choice = Console.ReadLine();
                logger.Info("User choice: {Choice}", choice);

                if (choice == "1")
                {
                    // Add movie
                    Movie movie = new Movie();
                    // ask user to input movie title
                    Console.WriteLine("Enter movie title");
                    // input title
                    movie.title = Console.ReadLine();
                    // verify title is unique
                    if (movieFile.isUniqueTitle(movie.title))
                    {
                        // input genres
                        string input;
                        do
                        {
                            // ask user to enter genre
                            Console.WriteLine("Enter genre (or done to quit)");
                            // input genre
                            input = Console.ReadLine();
                            // if user enters "done"
                            // or does not enter a genre do not add it to list
                            if (input != "done" && input.Length > 0)
                            {
                                movie.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (movie.genres.Count == 0)
                        {
                            movie.genres.Add("(no genres listed)");
                        }
                        // add movie
                        movieFile.AddMovie(movie);
                    }
                }
                else if (choice == "2")
                {
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
            } while (choice == "1" || choice == "2");

            logger.Info("Program ended");
        }