Exemple #1
0
        public static void Main(string[] args)
        {
            logger.Info("Program started");
            MovieFile movieFile = new MovieFile("../../movies.scrubbed.csv");
            AlbumFile albumFile = new AlbumFile("../../albums.csv");
            BookFile  bookFile  = new BookFile("../../books.csv");
            string    menuInput;

            //loop main menu while input is within bounds for the menu
            do
            {
                Menu();
                menuInput = Console.ReadLine();
                switch (menuInput)
                {
                case "1":
                    movieFile.AddMovie();
                    break;

                case "2":
                    movieFile.DisplayMovies();
                    break;

                case "3":
                    movieFile.SearchMovies();
                    break;

                case "4":
                    albumFile.AddAlbum();
                    break;

                case "5":
                    albumFile.DisplayAlbums();
                    break;

                case "6":
                    albumFile.SearchAlbums();
                    break;

                case "7":
                    bookFile.AddBooks();
                    break;

                case "8":
                    bookFile.DisplayBooks();
                    break;

                case "9":
                    bookFile.SearchBooks();
                    break;
                }
            } while (menuInput != "0");

            logger.Info("Program ended");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            string    scrubbedFile = FileScrubber.ScrubMovies("movies.csv");
            MovieFile movieFile    = new MovieFile("movies.scrubbed.csv");
            string    userchoice   = "";

            do
            {
                Console.WriteLine("Press 1 to add a movie to a file, 2 to read from a file, or 3 to search for a movie and any other key to quit");
                userchoice = Console.ReadLine();

                if (userchoice == "1")
                {
                    string    id         = "";
                    string    title      = "";
                    string    director   = "";
                    string    runTime    = "";
                    string    genre      = "";
                    ArrayList movieGenre = new ArrayList();
                    Console.WriteLine("Please enter movie id");
                    id = Console.ReadLine();
                    Console.WriteLine("Please enter movie title");
                    id = Console.ReadLine();
                    do
                    {
                        Console.WriteLine("Please type the movies genre(s) press -1 to stop");
                        genre = Console.ReadLine();

                        if (genre != "-1")
                        {
                            movieGenre.Add(genre);
                        }
                    } while (genre != "-1");
                    string totalGenre = string.Join("|", (string[])movieGenre.ToArray(Type.GetType("System.String")));

                    Console.WriteLine("Please enter movie runtime (h:m:s)");
                    runTime = Console.ReadLine();
                    Console.WriteLine("Please enter movie director");
                    director = Console.ReadLine();
                }
                if (userchoice == "3")
                {
                    Console.WriteLine("please enter the movies title");

                    string search = Console.ReadLine();
                    movieFile.findMovie(search);
                }
            }while (userchoice == "1" || userchoice == "2" || userchoice == "3");



            logger.Info("Program ended");
        }
Exemple #3
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            string    movieFilePath = "movies.scrubbed.csv";
            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("3) Find movie");
                Console.WriteLine("Enter to quit");
                // input selection
                choice = Console.ReadLine();
                logger.Info("User choice: {Choice}", choice);

                switch (choice)
                {
                case "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)");
                        }
                        Console.WriteLine("Enter movie director");
                        movie.director = Console.ReadLine();
                        Console.WriteLine("Enter running time (h:m:s)");
                        movie.runningTime = TimeSpan.Parse(Console.ReadLine());
                        // add movie
                        movieFile.AddMovie(movie);
                    }
                    break;

                case "2":
                    Console.WriteLine("Test");
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                    break;

                case "3":
                    Console.WriteLine("What is the title of the movie you want?");
                    choice = Console.ReadLine();

                    var movieSearch = movieFile.Movies.Where(m => m.title.Contains($"{choice}"));
                    Console.WriteLine($"There are {movieSearch.Count()} movies with \"{choice}\" in the title:");
                    foreach (Movie m in movieSearch)
                    {
                        Console.WriteLine($"  {m.title}");
                    }

                    break;
                }
            } while (choice == "1" || choice == "2" || choice == "3");

            logger.Info("Program ended");
        }
Exemple #4
0
        static void Main(string[] args)
        {
            logger.Info("Program started");



            string movieFilePath = "movies.scrubbed.csv";

            // When trying to get the MoiveFile it comes up with "Program.cs(16,13): error CS0246: The type or namespace name 'MovieFile' could not be found (are you missing a using directive or an assembly reference?)"
            // but if I want to try and call moive it works just fine (besides for the part of how the program doesn't work because of the MoiveFile not working)
            MovieFile movieFile = new MovieFile(movieFilePath);
            Movie     moive     = new Movie();

            string choice = "";

            do
            {
                // display choices to user
                Console.WriteLine("1) Add Movie");
                Console.WriteLine("2) Display All Movies");
                Console.WriteLine("3) Search based on the title of a movie");
                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)");
                        }

                        Console.WriteLine("Enter movie director");
                        movie.director = Console.ReadLine();

                        Console.WriteLine("Enter running time (h:m:s)");
                        movie.runningTime = TimeSpan.Parse(Console.ReadLine());

                        // add movie
                        movieFile.AddMovie(movie);
                    }
                }
                else if (choice == "2")
                {
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
                else if (choice == "3")
                {
                    string input;

                    Console.WriteLine("what do you want to search for:");
                    input = Console.ReadLine();

                    var titles = movieFile.Movies.Where(m => m.title.Contains(input)).Select(m => m.title);
                    // LINQ - Count aggregation method
                    Console.WriteLine($"There are {titles.Count()} movies with \"{input}\" in the title:");
                    foreach (string t in titles)
                    {
                        Console.WriteLine($"  {t}");
                    }
                }
            } while (choice == "1" || choice == "2" || choice == "3");

            logger.Info("Program ended");
        }
Exemple #5
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            // create list of movies
            string    movieFilePath = Directory.GetCurrentDirectory() + "\\movies.scrubbed.csv";
            MovieFile movieFile     = new MovieFile(movieFilePath);
            string    file          = "movies.scrubbed.csv";

            // check if file exists
            if (!File.Exists(file))
            {
                logger.Info("The file " + file + " does not exist.");
            }
            else
            {
                string choice;
                do
                {
                    Console.WriteLine("Enter 1 to add movie.");
                    Console.WriteLine("Enter 2 to display all movies.");
                    Console.WriteLine("Enter anything else to quit.");
                    choice = Console.ReadLine();

                    if (choice == "1")
                    {
                        try {
                            Movie        movie        = new Movie();
                            MovieManager movieManager = new MovieManager();

                            // ask user for name of title
                            movie.title = movieManager.enterTitle();

                            // check to see if the same movie exists in library
                            Boolean isUnique = movieFile.isUniqueTitle(movie.title);

                            if (isUnique)
                            {
                                // movie.mediaId is calculated in movieFile.AddMovie(movie);
                                movie.genres      = movieManager.enterGenres();
                                movie.director    = movieManager.enterDirector();
                                movie.runningTime = movieManager.enterRunningTime();
                                movieFile.AddMovie(movie);
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                    // display movies
                    else if (choice == "2")
                    {
                        try {
                            // Display All Movies
                            foreach (Movie m in movieFile.Movies)
                            {
                                Console.WriteLine(m.Display());
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                } while (choice == "1" || choice == "2");
            }

            logger.Info("Program ended");
        }
Exemple #6
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            // Movie movie = new Movie
            // {
            //     mediaId = 123,
            //     title = "Greatest Movie Ever, The (2020)",
            //     director = "Jeff Grissom",
            //     // timespan (hours, minutes, seconds)
            //     runningTime = new TimeSpan(2, 21, 23),
            //     genres = { "Comedy", "Romance" }
            // };

            // Console.WriteLine(movie.Display());

            // Album album = new Album
            // {
            //     mediaId = 321,
            //     title = "Greatest Album Ever, The (2020)",
            //     artist = "Jeff's Awesome Band",
            //     recordLabel = "Universal Music Group",
            //     genres = { "Rock" }
            // };
            // Console.WriteLine(album.Display());

            // Book book = new Book
            // {
            //     mediaId = 111,
            //     title = "Super Cool Book",
            //     author = "Jeff Grissom",
            //     pageCount = 101,
            //     publisher = "",
            //     genres = { "Suspense", "Mystery" }
            // };
            // Console.WriteLine(book.Display());

            ScrubbedFile = FileScrubber.ScrubMovies("movies.csv");
            logger.Info(ScrubbedFile);
            mf = new MovieFile(ScrubbedFile);
            int choice = -1;

            while (choice != 0)
            {
                Console.WriteLine("[1]Display All movies");
                Console.WriteLine("[2]Add a movie");
                Console.WriteLine("[3]Search for a movie");
                Console.WriteLine("[0]Quit");
                choice = Int16.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    mf.DisplayMovies();
                    break;

                case 2:
                    AddMovie();
                    break;

                case 3:
                    SearchMovies();
                    break;

                default: break;
                }
            }
            logger.Info("Program ended");
        }
Exemple #7
0
        static void Main(string[] args)
        {
            logger.Info("Program started");
            // sets file path for scrubbed file
            string movieFilePath = "movies.scrubbed.csv";
            // creates movie file instance
            MovieFile movieFile = new MovieFile(movieFilePath);

            string choice = "";

            do
            {
                // 1 adds movie, 2 displays movie, entering nothing exits program
                Console.WriteLine("1) Add movie");
                Console.WriteLine("2) Display all movies");
                Console.WriteLine("3) Find movie");
                Console.WriteLine("Enter to quit");
                // takes user input
                choice = Console.ReadLine();
                // logs users choice
                logger.Info("User choice: {choice}", choice);

                if (choice == "1")
                {
                    // creates Movie object
                    Movie movie = new Movie();
                    // asks for title
                    Console.WriteLine("Enter movie title");
                    // stores what user entered into movie.title
                    movie.title = Console.ReadLine();

                    string input;

                    do
                    {
                        // asks for genres or enter done to quit
                        Console.WriteLine("Enter genre (or done to quit)");
                        // stores what user entered into variable
                        input = Console.ReadLine();
                        // if not done and the user entered something, add it to genre list
                        if (input != "done" && input.Length > 0)
                        {
                            movie.genres.Add(input);
                        }
                        // if user didnt enter done, but left it blank, stores no genres listed into list
                    } while (input != "done");
                    if (movie.genres.Count == 0)
                    {
                        movie.genres.Add("no genres listed");
                    }
                    // asks for directors name
                    Console.WriteLine("Enter Directors name");
                    // stores it into movie.director
                    movie.director = Console.ReadLine();
                    // asks for running time of movie
                    Console.WriteLine("Enter running time (h:m:s)");
                    // parses it into timespan
                    movie.runningTime = TimeSpan.Parse(Console.ReadLine());
                    // adds it to the movie file
                    movieFile.AddMovie(movie);
                }
                else if (choice == "2")
                {
                    // foreach loop displays each movie in file
                    foreach (Movie m in movieFile.Movies)
                    {
                        // calls display method
                        Console.WriteLine(m.Display());
                    }
                }
                else if (choice == "3")
                {
                    Console.WriteLine("Enter name of movie or year of movie to search for");

                    string search = Console.ReadLine();

                    Console.ForegroundColor = ConsoleColor.Green;

                    var movieSearch = movieFile.Movies.Where(m => m.title.Contains(search, StringComparison.OrdinalIgnoreCase)).Select(m => m.title);

                    foreach (string m in movieSearch)
                    {
                        Console.WriteLine($" {m}");
                    }

                    Console.ForegroundColor = ConsoleColor.Cyan;

                    Console.WriteLine($"There are {movieSearch.Count()} movies with {search} in the title: ");

                    Console.ForegroundColor = ConsoleColor.White;
                }
                // condition for menu
            }  while (choice == "1" || choice == "2" || choice == "3");



            //   {
            //      mediaId = 123,
            //     title = "Greatest Movie Ever, The (2020)",
            //     director = "Jeff Grissom",
            //     // timespan (hours, minutes, seconds)
            //     runningTime = new TimeSpan(2, 21, 23),
            //       genres = { "Comedy", "Romance" }
            //   };


            // Console.WriteLine(movie.Display());

            // Album album = new Album
            // {
            //     mediaId = 321,
            //     title = "Greatest Album Ever, The (2020)",
            //     artist = "Jeff's Awesome Band",
            //     recordLabel = "Universal Music Group",
            //     genres = { "Rock" }
            // };
            // Console.WriteLine(album.Display());

            // Book book = new Book
            // {
            //     mediaId = 111,
            //     title = "Super Cool Book",
            //     author = "Jeff Grissom",
            //     pageCount = 101,
            //     publisher = "",
            //     genres = { "Suspense", "Mystery" }
            // };
            // Console.WriteLine(book.Display());

            string scrubbedFile = FileScrubber.ScrubMovies("movies.csv");

            logger.Info(scrubbedFile);



            logger.Info("Program ended");
        }
Exemple #8
0
        public static void Main(string[] args)
        {
            logger.Info("Program started");

            string    scrubbedFile  = FileScrubber.ScrubMovies("../../../movies.csv");
            string    albumFileName = "../../albums.csv";
            string    bookFileName  = "../../books.csv";
            MovieFile movieFile     = new MovieFile(scrubbedFile);
            AlbumFile albumFile     = new AlbumFile(albumFileName);
            BookFile  bookFile      = new BookFile(bookFileName);

            string choice = "";

            do
            {
                // display choices to user
                Console.WriteLine("1) Add Movie");
                Console.WriteLine("2) Display All Movies");
                Console.WriteLine("3) Add Album");
                Console.WriteLine("4) Display All Albums");
                Console.WriteLine("5) Add Book");
                Console.WriteLine("6) Display All Books");
                Console.WriteLine("7) Search for a Movie/Album/Book");
                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)");
                        }
                        // ask user to enter director
                        Console.WriteLine("Enter movie director");
                        input          = Console.ReadLine();
                        movie.Director = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter running time
                        Console.WriteLine("Enter running time (h:m:s)");
                        input             = Console.ReadLine();
                        movie.RunningTime = input.Length == 0 ? new TimeSpan(0) : TimeSpan.Parse(input);
                        // add movie
                        movieFile.AddMovie(movie);
                    }
                    else
                    {
                        Console.WriteLine("Movie title already exists\n");
                    }
                }
                else if (choice == "2")
                {
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
                else if (choice == "3")
                {
                    // Add Album
                    Album album = new Album();
                    // ask user to input album title
                    Console.WriteLine("Enter album title");
                    // input title
                    album.title = Console.ReadLine();
                    // verify title is unique
                    if (albumFile.isUniqueTitle(album.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)
                            {
                                album.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (album.genres.Count == 0)
                        {
                            album.genres.Add("(no genres listed)");
                        }
                        // ask user to enter director
                        Console.WriteLine("Enter album artist");
                        input        = Console.ReadLine();
                        album.artist = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter record label
                        Console.WriteLine("Enter record label");
                        input             = Console.ReadLine();
                        album.recordLabel = input.Length == 0 ? "unassigned" : input;
                        // add album
                        albumFile.AddAlbum(album);
                    }
                    else
                    {
                        Console.WriteLine("Album title already exists\n");
                    }
                }
                else if (choice == "4")
                {
                    // Display All Albums
                    foreach (Album a in albumFile.Albums)
                    {
                        Console.WriteLine(a.Display());
                    }
                }

                else if (choice == "5")
                {
                    // Add Book
                    Book book = new Book();
                    // ask user to input book title
                    Console.WriteLine("Enter book title");
                    // input title
                    book.title = Console.ReadLine();
                    // verify title is unique
                    if (bookFile.isUniqueTitle(book.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)
                            {
                                book.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (book.genres.Count == 0)
                        {
                            book.genres.Add("(no genres listed)");
                        }
                        // ask user to enter author
                        Console.WriteLine("Enter book author");
                        input       = Console.ReadLine();
                        book.author = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter publisher
                        Console.WriteLine("Enter publisher");
                        input          = Console.ReadLine();
                        book.publisher = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter number of pages
                        Console.WriteLine("Enter number of pages");
                        input          = Console.ReadLine();
                        book.pageCount = input.Length == 0 ? (UInt16)0 : UInt16.Parse(input);
                        // add book
                        bookFile.AddBook(book);
                    }
                    else
                    {
                        Console.WriteLine("Book title already exists\n");
                    }
                }
                else if (choice == "6")
                {
                    // Display All Books
                    foreach (Book b in bookFile.Books)
                    {
                        Console.WriteLine(b.Display());
                    }
                }
                else if (choice == "7")
                {
                    string userInput = "";

                    Console.WriteLine("Would you like to search for a Movie, Album or Book?? (1 for Movie, 2 for Album, 3 for Book)");
                    userInput = Console.ReadLine();

                    if (userInput == "1")
                    {
                        String userMovieInput;
                        Console.WriteLine("Enter part of or a whole movie title you would like to search for.");
                        userMovieInput = Console.ReadLine();

                        // LINQ - Where filter operator & Contains quantifier operator
                        //var Movies = movieFile.Movies.Where(m => m.title.Contains("(1990)"));
                        // LINQ - Count aggregation method
                        //Console.WriteLine($"There are {Movies.Count()} movies from 1990");


                        var userMovies = movieFile.Movies.Where(m => m.title.Contains(userMovieInput, StringComparison.OrdinalIgnoreCase)).Select(m => m.title);
                        foreach (string t in userMovies)
                        {
                            Console.WriteLine(t);
                        }
                    }
                    else if (userInput == "2")
                    {
                        Console.WriteLine("How would you like to search for your Album?");
                        String userAlbumInput = Console.ReadLine();

                        var userAlbum = albumFile.Albums.Where(m => m.title.Contains(userAlbumInput, StringComparison.OrdinalIgnoreCase)).Select(m => m.title);
                        foreach (string t in userAlbum)
                        {
                            Console.WriteLine(t);
                        }
                    }
                    else if (userInput == "3")
                    {
                        Console.WriteLine("How would you like to search for your Book?");
                        String userBookInput = Console.ReadLine();

                        var userBook = bookFile.Books.Where(m => m.title.Contains(userBookInput, StringComparison.OrdinalIgnoreCase)).Select(m => m.title);
                        foreach (string t in userBook)
                        {
                            Console.WriteLine(t);
                        }
                    }
                    else
                    {
                        Console.WriteLine("You entered something in wrong.");
                    }
                }
            } while (choice == "1" || choice == "2" || choice == "3" || choice == "4" || choice == "5" || choice == "6");

            logger.Info("Program ended");
        }
        static void Main(string[] args)
        {
            logger.Info("Program started");

            // create list of movies
            string    movieFilePath = Directory.GetCurrentDirectory() + "\\movies.scrubbed.csv";
            MovieFile movieFile     = new MovieFile(movieFilePath);
            string    file          = "movies.scrubbed.csv";

            // check if file exists
            if (!File.Exists(file))
            {
                logger.Info("The file " + file + " does not exist.");
            }
            else
            {
                string choice;
                do
                {
                    Console.WriteLine("Enter 1 to add movie.");
                    Console.WriteLine("Enter 2 to display all movies.");
                    Console.WriteLine("Enter 3 to search movie titles.");
                    Console.WriteLine("Enter anything else to quit.");
                    choice = Console.ReadLine();

                    if (choice == "1")
                    {
                        try {
                            Movie        movie        = new Movie();
                            MovieManager movieManager = new MovieManager();

                            // ask user for name of title
                            movie.title = movieManager.enterTitle();

                            // check to see if the same movie exists in library
                            Boolean isUnique = movieFile.isUniqueTitle(movie.title);

                            if (isUnique)
                            {
                                // movie.mediaId is calculated in movieFile.AddMovie(movie);
                                movie.genres      = movieManager.enterGenres();
                                movie.director    = movieManager.enterDirector();
                                movie.runningTime = movieManager.enterRunningTime();
                                movieFile.AddMovie(movie);
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                    // display movies
                    else if (choice == "2")
                    {
                        try {
                            // Display All Movies
                            foreach (Movie m in movieFile.Movies)
                            {
                                Console.WriteLine(m.Display());
                            }
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                    // search movie titles
                    else if (choice == "3")
                    {
                        try {
                            Console.WriteLine("Enter text to search: ");
                            string text = Console.ReadLine();

                            // display number of matches
                            var numberMovies = movieFile.Movies.Where(m => m.title.Contains(text)).Count();
                            Console.WriteLine($"There are {numberMovies} movies with \"{text}\" in the title.");

                            // change display color in terminal
                            Console.ForegroundColor = ConsoleColor.Green;

                            // display movie titles that match
                            var movieTitleMatch = movieFile.Movies.Where(m => m.title.Contains(text));
                            foreach (Movie m in movieTitleMatch)
                            {
                                Console.WriteLine($"  {m.title}");
                            }

                            // change display color back to white
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                        catch (Exception e) {
                            logger.Error(e.Message);
                        }
                    }
                } while (choice == "1" || choice == "2" || choice == "3");
            }

            logger.Info("Program ended");
        }
Exemple #10
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            // Movie movie = new Movie
            // {
            //     mediaId = 123,
            //     title = "Greatest Movie Ever, The (2020)",
            //     director = "Jeff Grissom",
            //     // timespan (hours, minutes, seconds)
            //     runningTime = new TimeSpan(2, 21, 23),
            //     genres = { "Comedy", "Romance" }
            // };

            // Console.WriteLine(movie.Display());

            // Album album = new Album
            // {
            //     mediaId = 321,
            //     title = "Greatest Album Ever, The (2020)",
            //     artist = "Jeff's Awesome Band",
            //     recordLabel = "Universal Music Group",
            //     genres = { "Rock" }
            // };
            // Console.WriteLine(album.Display());

            // Book book = new Book
            // {
            //     mediaId = 111,
            //     title = "Super Cool Book",
            //     author = "Jeff Grissom",
            //     pageCount = 101,
            //     publisher = "",
            //     genres = { "Suspense", "Mystery" }
            // };
            // Console.WriteLine(book.Display());

            // string scrubbedFile = FileScrubber.ScrubMovies("movies.csv");
            // logger.Info(scrubbedFile);

            logger.Info("Movie Manager loaded.");

            MovieFile manager = new MovieFile("movies.scrubbed.csv");

            try
            {
                Boolean done = false;

                while (!done)
                {
                    Console.WriteLine("\nWhat would you like to do?");
                    Console.WriteLine("1 - Add New Movie");
                    Console.WriteLine("2 - List Movies");
                    Console.WriteLine("3 - Save Movie List");
                    Console.WriteLine("Q - Quit Program");

                    string choice = Console.ReadLine();
                    logger.Info("Users choice = " + choice);

                    if (choice == "1")
                    {
                        manager.userAddMovie();
                    }
                    else if (choice == "2")
                    {
                        manager.printMovies();
                    }
                    else if (choice == "3")
                    {
                        manager.writeToFile();
                        logger.Info("Wrote to file");
                    }
                    else if (choice == "Q" || choice == "q")
                    {
                        done = true;
                    }
                    else
                    {
                        Console.WriteLine("Not a valid choice.");
                    };
                }
                logger.Info("Program Quitting");
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
            logger.Info("Program ended");
        }
Exemple #11
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            string    movieFilePath = "movies.scrubbed.csv";
            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)");
                        }
                        Console.WriteLine("Enter movie director");
                        movie.director = Console.ReadLine();
                        Console.WriteLine("Enter running time (h:m:s)");
                        movie.runningTime = TimeSpan.Parse(Console.ReadLine());
                        // add movie
                        movieFile.AddMovie(movie);
                    }
                }
                else if (choice == "2")
                {
                    Console.WriteLine("Test");
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
            } while (choice == "1" || choice == "2");

            logger.Info("Program ended");
        }
        static void Main(string[] args)
        {
            logger.Info("Program started");

            Console.Write("\nWould you like to search for a movie (Y/N): ");
            string decision = Console.ReadLine().ToUpper();

            while (decision == "Y")
            {
                string    scrubbedFile = FileScrubber.ScrubMovies("movies.csv");
                MovieFile movieFile    = new MovieFile(scrubbedFile);

                Console.ForegroundColor = ConsoleColor.Green;

                Console.Write("\nWhat would you like to search for in the movie titles: ");
                string searchedTitle = Console.ReadLine();
                var    searchedMovie = movieFile.Movies.Where(m => m.title.Contains(searchedTitle));
                Console.WriteLine($"\n**There are {searchedMovie.Count()} movies that contain {searchedTitle} in the title**\n");
                foreach (Movie movie in searchedMovie)
                {
                    Console.WriteLine(movie.title);
                }
                Console.Write("\nWould you like to search for another movie? (Y/N): ");
                decision = Console.ReadLine().ToUpper();
            }

            // // LINQ - Where filter operator & Contains quantifier operator
            // var Movies = movieFile.Movies.Where(m => m.title.Contains("(1990)"));
            // // LINQ - Count aggregation method
            // Console.WriteLine($"There are {Movies.Count()} movies from 1990");

            // // LINQ - Any quantifier operator & Contains quantifier operator
            // var validate = movieFile.Movies.Any(m => m.title.Contains("(1921)"));
            // Console.WriteLine($"Any movies from 1921? {validate}");

            // // LINQ - Where filter operator & Contains quantifier operator & Count aggregation method
            // int num = movieFile.Movies.Where(m => m.title.Contains("(1921)")).Count();
            // Console.WriteLine($"There are {num} movies from 1921");

            // // LINQ - Where filter operator & Contains quantifier operator
            // var Movies1921 = movieFile.Movies.Where(m => m.title.Contains("(1921)"));
            // foreach(Movie m in Movies1921)
            // {
            //     Console.WriteLine($"  {m.title}");
            // }

            // // LINQ - Where filter operator & Select projection operator & Contains quantifier operator
            // var titles = movieFile.Movies.Where(m => m.title.Contains("Shark")).Select(m => m.title);
            // // LINQ - Count aggregation method
            // Console.WriteLine($"There are {titles.Count()} movies with \"Shark\" in the title:");
            // foreach(string t in titles)
            // {
            //     Console.WriteLine($"  {t}");
            // }

            // // LINQ - First element operator
            // var FirstMovie = movieFile.Movies.First(m => m.title.StartsWith("Z", StringComparison.OrdinalIgnoreCase));
            // Console.WriteLine($"First movie that starts with letter 'Z': {FirstMovie.title}");

            // Console.ForegroundColor = ConsoleColor.White;

            logger.Info("Program ended");
        }
Exemple #13
0
        public static void Main(string[] args)
        {
            string file   = "../../movies.scrubbed.csv";
            string bkfile = "books.csv";
            string cdfile = "cd.csv";

            logger.Info("Program started");

            MovieFile movieFile = new MovieFile(file);
            BookFile  bookFile  = new BookFile(bkfile);
            AlbumFile albumFile = new AlbumFile(cdfile);
            string    choice    = "";
            string    mchoice   = "";
            string    bchoice   = "";
            string    achoice   = "";

            do
            {
                Console.WriteLine("1) Movie");
                Console.WriteLine("2) Book");
                Console.WriteLine("3) Album");
                Console.WriteLine("Enter to quit");
                choice = Console.ReadLine();
                logger.Info("User choice: {Choice}", choice);

                if (choice == "1")
                {
                    do
                    {
                        Console.WriteLine("1) Add Movie");
                        Console.WriteLine("2) Display All Movies");
                        Console.WriteLine("3) Enter to quit");
                        mchoice = Console.ReadLine();
                        logger.Info("User choice: {Choice}", mchoice);
                        if (mchoice == "1")
                        {
                            Movie movie = new Movie();
                            Console.WriteLine("Enter movie title");
                            movie.title = Console.ReadLine();
                            if (movieFile.isUniqueTitle(movie.title))
                            {
                                string input;
                                do
                                {
                                    Console.WriteLine("Enter Genre (or done to quit)");
                                    input = Console.ReadLine();
                                    if (input != "done" && input.Length > 0)
                                    {
                                        movie.genres.Add(input);
                                    }
                                } while (input != "done");
                                if (movie.genres.Count == 0)
                                {
                                    movie.genres.Add("(no genres listed)");
                                }
                                Console.WriteLine("Enter movie Director");
                                movie.director = Console.ReadLine();
                                Console.WriteLine("Enter running time");
                                movie.runningTime = TimeSpan.Parse(Console.ReadLine());
                                movieFile.AddMovie(movie);
                            }
                            else
                            {
                                Console.WriteLine("Movie title already exists\n");
                            }
                        }
                        else if (mchoice == "2")
                        {
                            foreach (Movie m in movieFile.Movies)
                            {
                                Console.WriteLine(m.Display());
                            }
                        }
                    } while (mchoice == "1" || mchoice == "2");
                }
                else if (choice == "2")
                {
                    Console.WriteLine("1) Add Book");
                    Console.WriteLine("2) Display All Books");
                    Console.WriteLine("3) Enter to quit");
                    bchoice = Console.ReadLine();
                    logger.Info("User choice: {Choice}", bchoice);
                    do
                    {
                        if (mchoice == "1")
                        {
                            Book book = new Book();
                            Console.WriteLine("Enter book title");
                            book.title = Console.ReadLine();
                            if (bookFile.isUniqueTitle(book.title))
                            {
                                string input;
                                do
                                {
                                    Console.WriteLine("Enter Genre (or done to quit");
                                    input = Console.ReadLine();
                                    if (input != "done" && input.Length > 0)
                                    {
                                        book.genres.Add(input);
                                    }
                                } while (input != "done");

                                if (book.genres.Count == 0)
                                {
                                    book.genres.Add("(no genres listed)");
                                }
                                Console.WriteLine("Enter book author");
                                book.author = Console.ReadLine();
                                Console.WriteLine("Enter book publisher");
                                book.publisher = Console.ReadLine();
                                Console.WriteLine("Enter the amount of pages");
                                book.pageCount = UInt16.Parse(Console.ReadLine());
                                bookFile.AddBook(book);
                            }
                            else
                            {
                                Console.WriteLine("Book title already exists\n");
                            }
                        }
                        else if (bchoice == "2")
                        {
                            foreach (Book b in bookFile.Books)
                            {
                                Console.WriteLine(b.Display());
                            }
                        }
                    } while (bchoice == "1" || bchoice == "2");
                }
                else if (choice == "3")
                {
                    Console.WriteLine("1) Add Album");
                    Console.WriteLine("2) Display All Albums");
                    Console.WriteLine("3) Enter to quit");
                    bchoice = Console.ReadLine();
                    logger.Info("User choice: {Choice}", bchoice);
                    do
                    {
                        if (achoice == "1")
                        {
                            Album album = new Album();
                            Console.WriteLine("Enter Album title");
                            album.title = Console.ReadLine();
                            if (albumFile.isUniqueTitle(album.title))
                            {
                                string input;
                                do
                                {
                                    Console.WriteLine("Enter Genre (or done to quit");
                                    input = Console.ReadLine();
                                    if (input != "done" && input.Length > 0)
                                    {
                                        album.genres.Add(input);
                                    }
                                } while (input != "done");

                                if (album.genres.Count == 0)
                                {
                                    album.genres.Add("(no genres listed)");
                                }
                                Console.WriteLine("Enter album artist");
                                album.artist = Console.ReadLine();
                                Console.WriteLine("Enter record label");
                                album.recordLabel = Console.ReadLine();
                                albumFile.AddAlbum(album);
                            }
                            else
                            {
                                Console.WriteLine("Album title already exists\n");
                            }
                        }
                        else if (achoice == "2")
                        {
                            foreach (Album a in albumFile.Albums)
                            {
                                Console.WriteLine(a.Display());
                            }
                        }
                    } while (achoice == "1" || achoice == "2");
                }
            } while ((choice == "1" || choice == "2" || choice == "3"));
            logger.Info("Program Ended");
        }
        public static void Main(string[] args)
        {
            logger.Info("Program started");

            string    scrubbedFile  = FileScrubber.ScrubMovies("../../movies.csv");
            string    albumFileName = "../../albums.csv";
            string    bookFileName  = "../../books.csv";
            MovieFile movieFile     = new MovieFile(scrubbedFile);
            AlbumFile albumFile     = new AlbumFile(albumFileName);
            BookFile  bookFile      = new BookFile(bookFileName);

            string choice = "";

            do
            {
                // display choices to user
                Console.WriteLine("\n1) Add Movie");
                Console.WriteLine("2) Search Movie");
                Console.WriteLine("3) Display All Movies");
                Console.WriteLine("4) Add Album");
                Console.WriteLine("5) Search Album");
                Console.WriteLine("6) Display All Albums");
                Console.WriteLine("7) Add Book");
                Console.WriteLine("8) Search Book");
                Console.WriteLine("9) Display All Books");
                Console.WriteLine("\nEnter 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)");
                        }
                        // ask user to enter director
                        Console.WriteLine("Enter movie director");
                        input          = Console.ReadLine();
                        movie.director = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter running time
                        Console.WriteLine("Enter running time (h:m:s)");
                        input             = Console.ReadLine();
                        movie.runningTime = input.Length == 0 ? new TimeSpan(0) : TimeSpan.Parse(input);
                        // add movie
                        movieFile.AddMovie(movie);
                    }
                    else
                    {
                        Console.WriteLine("Movie title already exists\n");
                    }
                }
                else if (choice == "2")
                {
                    // search movie
                    Console.WriteLine("Enter Movie Title: ");
                    String movieSearch = "";
                    movieSearch = Console.ReadLine();
                    var movie = movieFile.Movies.Where(m => m.title.Contains(movieSearch)).Select(m => m.title);

                    Console.WriteLine($"Here are your movies...\n");
                    foreach (string m in movie)
                    {
                        Console.WriteLine(m);
                    }
                }
                else if (choice == "3")
                {
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
                else if (choice == "4")
                {
                    // Add Album
                    Album album = new Album();
                    // ask user to input album title
                    Console.WriteLine("Enter album title");
                    // input title
                    album.title = Console.ReadLine();
                    // verify title is unique
                    if (albumFile.isUniqueTitle(album.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)
                            {
                                album.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (album.genres.Count == 0)
                        {
                            album.genres.Add("(no genres listed)");
                        }
                        // ask user to enter director
                        Console.WriteLine("Enter album artist");
                        input        = Console.ReadLine();
                        album.artist = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter record label
                        Console.WriteLine("Enter record label");
                        input             = Console.ReadLine();
                        album.recordLabel = input.Length == 0 ? "unassigned" : input;
                        // add album
                        albumFile.AddAlbum(album);
                    }
                    else
                    {
                        Console.WriteLine("Album title already exists\n");
                    }
                }
                else if (choice == "5")
                {
                    // search album
                    Console.WriteLine("Enter Album Title: ");
                    String albumSearch = "";
                    albumSearch = Console.ReadLine();
                    var album = albumFile.Albums.Where(m => m.title.Contains(albumSearch)).Select(m => m.title);

                    Console.WriteLine($"Here are your albums...\n");
                    foreach (string a in album)
                    {
                        Console.WriteLine(a);
                    }
                }
                else if (choice == "6")
                {
                    // Display All Albums
                    foreach (Album a in albumFile.Albums)
                    {
                        Console.WriteLine(a.Display());
                    }
                }
                else if (choice == "7")
                {
                    // Add Book
                    Book book = new Book();
                    // ask user to input book title
                    Console.WriteLine("Enter book title");
                    // input title
                    book.title = Console.ReadLine();
                    // verify title is unique
                    if (bookFile.isUniqueTitle(book.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)
                            {
                                book.genres.Add(input);
                            }
                        } while (input != "done");
                        // specify if no genres are entered
                        if (book.genres.Count == 0)
                        {
                            book.genres.Add("(no genres listed)");
                        }
                        // ask user to enter author
                        Console.WriteLine("Enter book author");
                        input       = Console.ReadLine();
                        book.author = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter publisher
                        Console.WriteLine("Enter publisher");
                        input          = Console.ReadLine();
                        book.publisher = input.Length == 0 ? "unassigned" : input;
                        // ask user to enter number of pages
                        Console.WriteLine("Enter number of pages");
                        input          = Console.ReadLine();
                        book.pageCount = input.Length == 0 ? (UInt16)0 : UInt16.Parse(input);
                        // add book
                        bookFile.AddBook(book);
                    }
                    else
                    {
                        Console.WriteLine("Book title already exists\n");
                    }
                }
                else if (choice == "8")
                {
                    // Search Book
                    Console.WriteLine("Enter Book Title: ");
                    String bookSearch = "";
                    bookSearch = Console.ReadLine();
                    var book = bookFile.Books.Where(m => m.title.Contains(bookSearch)).Select(m => m.title);

                    Console.WriteLine($"Here are your books...\n");
                    foreach (string b in book)
                    {
                        Console.WriteLine(b);
                    }
                }
                else if (choice == "9")
                {
                    // Display All Books
                    foreach (Book b in bookFile.Books)
                    {
                        Console.WriteLine(b.Display());
                    }
                }
            } while (choice == "1" || choice == "2" || choice == "3" || choice == "4" || choice == "5" || choice == "6" || choice == "7" || choice == "8" || choice == "9");

            logger.Info("Program ended");
        }
Exemple #15
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            string scrubbedFile = FileScrubber.ScrubMovies("movies.csv");

            logger.Info(scrubbedFile);

            string movieFilePath = Directory.GetCurrentDirectory() + "\\movies.scrubbed.csv";

            MovieFile movieFile = new MovieFile(movieFilePath);
            string    choice    = "";

            do
            {
                Console.WriteLine("1) Add Movie");
                Console.WriteLine("2) Display All Movies");
                Console.WriteLine("Enter to quit");

                choice = Console.ReadLine();
                logger.Info("User choice: {Choice}", choice);

                if (choice == "1")
                {
                    Movie movie = new Movie();

                    Console.WriteLine("Enter movie title");
                    movie.title = Console.ReadLine();

                    if (movieFile.isUniqueTitle(movie.title))
                    {
                        Console.WriteLine("Movie title is unique\n");

                        string input;
                        do
                        {
                            Console.WriteLine("Enter genre (or done to continue)");
                            input = Console.ReadLine();
                            if (input != "done" && input.Length > 0)
                            {
                                movie.genres.Add(input);
                            }
                        }while (input != "done");

                        if (movie.genres.Count == 0)
                        {
                            movie.genres.Add("(no genres listed)");
                        }

                        Console.WriteLine("\nEnter movie director");
                        movie.director = Console.ReadLine();

                        Console.WriteLine("\nEnter running time (h:m:s)");
                        string runTime = Console.ReadLine();
                        movie.runningTime = TimeSpan.Parse(runTime);

                        movieFile.AddMovie(movie);
                    }
                }
                else if (choice == "2")
                {
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
            } while (choice == "1" || choice == "2");

            logger.Info("Program ended");
        }
Exemple #16
0
        static void Main(string[] args)
        {
            logger.Info("Program started");

            // Movie movie = new Movie
            //     {
            //         mediaId = 123,
            //         title = "Greatest Movie Ever, The (2020)",
            //           director = "Jeff Grissom",
            //         // timespan (hours, minutes, seconds)
            //         runningTime = new TimeSpan(2, 21, 23),
            //         genres = { "Comedy", "Romance" }
            //     };

            //     Console.WriteLine(movie.Display());

            //       Album album = new Album
            //     {
            //         mediaId = 321,
            //         title = "Greatest Album Ever, The (2020)",
            //         artist = "Jeff's Awesome Band",
            //         recordLabel = "Universal Music Group",
            //         genres = { "Rock" }
            //     };
            //     Console.WriteLine(album.Display());

            //      Book book = new Book
            //     {
            //         mediaId = 111,
            //         title = "Super Cool Book",
            //         author = "Jeff Grissom",
            //         pageCount = 101,
            //         publisher = "",
            //         genres = { "Suspense", "Mystery" }
            //     };
            //     Console.WriteLine(book.Display());



            // Movie movie = new Movie
            // {
            //     mediaId = 123,
            //     title = "Greatest Movie Ever, The (2020)",
            //     director = "Jeff Grissom",
            //     // timespan (hours, minutes, seconds)
            //     runningTime = new TimeSpan(2, 21, 23),
            //     genres = { "Comedy", "Romance" }
            // };

            // Console.WriteLine(movie.Display());

            // Album album = new Album
            // {
            //     mediaId = 321,
            //     title = "Greatest Album Ever, The (2020)",
            //     artist = "Jeff's Awesome Band",
            //     recordLabel = "Universal Music Group",
            //     genres = { "Rock" }
            // };
            // Console.WriteLine(album.Display());

            // Book book = new Book
            // {
            //     mediaId = 111,
            //     title = "Super Cool Book",
            //     author = "Jeff Grissom",
            //     pageCount = 101,
            //     publisher = "",
            //     genres = { "Suspense", "Mystery" }
            // };
            // Console.WriteLine(book.Display());
            string    movieFilePath = Directory.GetCurrentDirectory() + "\\movies.scrubbed.csv";
            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("3) Search for a Movie");
                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)");
                        }
                        Console.WriteLine("Enter the Director: ");
                        movie.director = Console.ReadLine();
                        if (movie.director == "")
                        {
                            movie.director = "unassigned";
                        }
                        Console.WriteLine("Enter the Runtime: ");
                        String runtime = Console.ReadLine();
                        if (runtime == "")
                        {
                            movie.runningTime = new TimeSpan(0);
                        }
                        else
                        {
                            movie.runningTime = TimeSpan.Parse(string.Format(runtime));
                        }
                        // add movie
                        movieFile.AddMovie(movie);
                    }
                }
                else if (choice == "2")
                {
                    // Display All Movies
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
                else if (choice == "3")
                {
                    Console.WriteLine("Enter the movie to search");
                    String movieToSearch = Console.ReadLine();

                    var Movies = movieFile.Movies.Where(m => m.title.Contains(movieToSearch));
                    Console.WriteLine($"There are {Movies.Count()} movies with {movieToSearch} in the title");
                    foreach (Movie m in Movies)
                    {
                        Console.WriteLine($"{m.title}");
                    }
                }
            } while (choice == "1" || choice == "2" || choice == "3");
            string scrubbedFile = FileScrubber.ScrubMovies("movies.csv");

            logger.Info(scrubbedFile);
            logger.Info("Program ended");
        }
Exemple #17
0
        static void Main(string[] args)
        {
            logger.Info("Program started");
            string scrubbedFile = FileScrubber.ScrubMovies("movies.csv");

            logger.Info(scrubbedFile);

            MovieFile movieFile = new MovieFile(scrubbedFile);

            string choice = "";

            do
            {
                //Choices
                Console.WriteLine("1) Add Movie");
                Console.WriteLine("2) Display Movies");
                Console.WriteLine("3) Find Movie");
                Console.WriteLine("Enter to quit");
                //input
                choice = Console.ReadLine();
                logger.Info($"User choice: {choice}");

                if (choice == "1")
                {
                    Movie movie = new Movie();
                    //request and input title
                    Console.WriteLine("Enter movie title: ");
                    movie.title = Console.ReadLine();
                    //verify title
                    if (movieFile.isUniqueTitle(movie.title))
                    {
                        //input genres
                        string input;
                        do
                        {
                            //request and input genre
                            Console.WriteLine("Enter genre (or 'done' to quit)");
                            input = Console.ReadLine();
                            if (input != "done" && input.Length > 0)
                            {
                                movie.genres.Add(input);
                            }
                        } while(input != "done");
                        if (movie.genres.Count == 0)
                        {
                            movie.genres.Add("(no genres listed)");
                        }
                        //request and input director
                        Console.WriteLine("Enter director: ");
                        movie.director = Console.ReadLine();
                        //request and input running time
                        Console.WriteLine("Enter running time (hh:mm:ss)");
                        movie.runningTime = TimeSpan.Parse(Console.ReadLine());
                        //add movie
                        movieFile.AddMovie(movie);
                    }
                }
                else if (choice == "2")
                {
                    foreach (Movie m in movieFile.Movies)
                    {
                        Console.WriteLine(m.Display());
                    }
                }
                else if (choice == "3")
                {
                    //request search of movie title
                    Console.WriteLine("Enter name of movie to search");
                    string title = Console.ReadLine();
                    Console.ForegroundColor = ConsoleColor.Green;
                    var SearchMovies = movieFile.Movies.Where(m => m.title.Contains(title));
                    Console.WriteLine($"{SearchMovies.Count()} movies found with \"{title}\" in them");
                    foreach (Movie m in SearchMovies)
                    {
                        Console.WriteLine($" - {m.title}");
                    }
                    Console.ForegroundColor = ConsoleColor.White;
                }
            } while(choice == "1" || choice == "2" || choice == "3");

            logger.Info("Program ended");
        }