Beispiel #1
0
        public static void AddMovie()
        {
            Console.Write("Title: ");
            string title = Console.ReadLine();

            Console.Clear();
            int  releaseYear;
            bool notANum;

            do
            {
                notANum = false;
                Console.Write("Release year: ");
                if (!int.TryParse(Console.ReadLine(), out releaseYear))
                {
                    Console.WriteLine("Invalid input");
                    Console.ReadKey();
                    notANum = true;
                }
                Console.Clear();
            } while (notANum);
            Console.Write("Description: ");
            string desc = Console.ReadLine();

            Console.Clear();

            MovieManager.AddMovie(new Movie(title, releaseYear, desc));
            Console.Write(title + " has been added to Movies");
            Console.WriteLine("\nPress any key to continue...");
            Console.ReadKey();
            Console.Clear();
        }
Beispiel #2
0
        public static void DeleteMovie()
        {
            int          movId;
            bool         notANum;
            List <Movie> movies;

            do
            {
                Console.Write("Which movie would you like to delete?\n");
                movies = MovieManager.MovieList("");
                int i = 0;
                foreach (Movie movie in movies)
                {
                    i++;
                    Console.WriteLine(i + ") " + movie.Title);
                }

                notANum = false;
                Console.Write("Input: ");
                if (!int.TryParse(Console.ReadLine(), out movId))
                {
                    Console.WriteLine("Invalid input");
                    Console.ReadKey();
                    notANum = true;
                }
                Console.Clear();
            } while (notANum);
            int delMov = movies[movId - 1].ID;

            Console.Write("Are you sure you want to delete " + movies[movId - 1].Title + "? \n1) Yes \n2) No \nInput: ");
            if (!int.TryParse(Console.ReadLine(), out int sure))
            {
                Console.WriteLine("Invalid input");
                Console.ReadKey();
                notANum = true;
            }
            if (sure == 1)
            {
                MovieManager.DeleteMovie(movies[movId - 1]);
                Console.Write("Movie has been deleted");
                Console.ReadKey();
                Console.Clear();
            }
            else
            {
                Console.WriteLine("Deletion has been cancelled");
                Console.ReadKey();
                Console.Clear();
            }
        }
Beispiel #3
0
        public static void SearchByGenre()
        {
            Console.Write("search for genre: ");
            string genre = Console.ReadLine();

            Console.WriteLine("\nMovies related to: " + genre);
            List <Movie> movieByGenre = MovieManager.GenreMovieList(genre);

            foreach (Movie item in movieByGenre)
            {
                Console.WriteLine("\n" + item.Title);
            }
            if (movieByGenre.Count == 0)
            {
                Console.WriteLine("\nNo result related to '" + genre + "'\nTry something else.\n");
            }

            Console.WriteLine("\n\nPress any key to continue...");
            Console.ReadKey();
            Console.Clear();
        }
Beispiel #4
0
        public static void SearchMovie()
        {
            Console.Write("Movie search: ");
            string searchMov = Console.ReadLine();


            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nList of Movies");
            Console.ResetColor();
            List <Movie> movie = MovieManager.MovieList(searchMov);

            foreach (Movie item in movie)
            {
                Console.WriteLine("Movie title: " + item.Title + "\nRelease Year: " + item.ReleaseYear + "\nDescription: '" + item.Description + "'\n\n");
            }
            if (movie.Count == 0)
            {
                Console.WriteLine("\nNo result related to '" + searchMov + "'\nTry something else.\n");
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
            Console.Clear();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            MovieManager movieManager = new MovieManager();
            List <Actor> actors       = movieManager.GetActors();
            List <Movie> movies       = movieManager.GetMovies();
            List <Genre> genres       = movieManager.GetGenres();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("What would you like to do?.." +
                                  "\n" +
                                  "\n" +
                                  "1. Insert Actor \n" +
                                  "2. Insert Movie \n" +
                                  "3. Insert Genre \n" +
                                  "4. Update Actor \n" +
                                  "5. Update Movie \n" +
                                  "6. Update Genre \n" +
                                  "7. Delete Actor \n" +
                                  "8. Delete Movie \n" +
                                  "9. Delete Genre \n");

                string str = "";

                while (string.IsNullOrWhiteSpace(str))
                {
                    str = Console.ReadLine();
                }

                Console.Clear();
                switch (str)
                {
                    #region CreateSection
                case "1":
                {
                    Console.WriteLine("Enter First name");
                    string fn = Console.ReadLine();
                    Console.WriteLine("Enter Last name");
                    string ln    = Console.ReadLine();
                    Actor  actor = new Actor(fn, ln);

                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine("What movies is this actor in? (Type done if you are finished)\n");
                        if (Console.ReadLine().ToLower() == "done")
                        {
                            break;
                        }
                        for (int i = 0; i < movies.Count; i++)
                        {
                            Console.WriteLine(movies[i].Title + "    " + movies[i].ReleaseYear);
                        }
                        str = "";
                        while (string.IsNullOrWhiteSpace(str))
                        {
                            str = Console.ReadLine();
                        }
                        for (int i = 0; i < movies.Count; i++)
                        {
                            if (str.ToLower() == movies[i].Title.ToLower())
                            {
                                actor.StarringIn.Add(movies[i]);
                                break;
                            }
                        }
                    }
                    Console.WriteLine(movieManager.InsertActor(actor).GetFullName() + " has been added");
                    actors.Add(actor);
                    break;
                }

                case "2":
                {
                    Movie        movie;
                    List <Genre> movieGenres = movieManager.GetGenres();

                    Console.WriteLine("Enter Title");
                    string title = Console.ReadLine();
                    Console.WriteLine("Enter release date (YYYY-MM-DD)");
                    string release = Console.ReadLine();
                    Console.WriteLine("Enter Description");
                    string desc = Console.ReadLine();

                    movie = new Movie(release, title, desc);

                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine("What genres is this movie? (Type done if you are finished)\n");
                        if (Console.ReadLine().ToLower() == "done")
                        {
                            break;
                        }
                        for (int i = 0; i < movieGenres.Count; i++)
                        {
                            Console.WriteLine(movieGenres[i].GenreName);
                        }
                        str = "";
                        while (string.IsNullOrWhiteSpace(str))
                        {
                            str = Console.ReadLine();
                        }
                        for (int i = 0; i < movieGenres.Count; i++)
                        {
                            if (str.ToLower() == movieGenres[i].GenreName.ToLower())
                            {
                                movie.Genres.Add(movieGenres[i]);
                                break;
                            }
                        }
                    }
                    Console.WriteLine(movieManager.InsertMovie(movie).Title + " has been added");
                    movies.Add(movie);
                    break;
                }

                case "3":
                {
                    Console.WriteLine("Enter Genre name");
                    Genre genre = new Genre(Console.ReadLine());
                    Console.WriteLine(movieManager.InsertGenre(genre).GenreName + " has been added");
                    genres.Add(genre);
                    break;
                }

                    #endregion
                    #region UpdateSection
                case "4":
                {
                    Console.WriteLine("Which actor needs an update?");
                    foreach (Actor actor in actors)
                    {
                        Console.WriteLine(actor.ActorId + "  " + actor.GetFullName());
                    }
                    try
                    {
                        for (int i = 0; i < actors.Count; i++)
                        {
                            if (int.Parse(Console.ReadLine()) == actors[i].ActorId)
                            {
                                Console.WriteLine("Enter First name");
                                actors[i].FirstName = Console.ReadLine();

                                Console.WriteLine("Enter Last name");
                                actors[i].LastName = Console.ReadLine();

                                Console.WriteLine(movieManager.UpdateActor(actors[i]));
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("Something went wrong! try again");
                    }
                    break;
                }

                case "5":
                {
                    Console.WriteLine("Which movie needs an update?");
                    foreach (Movie movie in movies)
                    {
                        Console.WriteLine(movie.MovieId + "  " + movie.Title);
                    }
                    try
                    {
                        for (int i = 0; i < movies.Count; i++)
                        {
                            if (int.Parse(Console.ReadLine()) == movies[i].MovieId)
                            {
                                Console.WriteLine("What is the title?");
                                movies[i].Title = Console.ReadLine();
                                Console.WriteLine("What date was it released? (YYYY-MM-DD)");
                                movies[i].ReleaseYear = Console.ReadLine();
                                Console.WriteLine("What is the description?");
                                movies[i].Description = Console.ReadLine();
                                movieManager.UpdateMovie(movies[i]);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Something went wrong! try again");
                    }
                    break;
                }

                case "6":
                {
                    Console.WriteLine("Which genre needs an update?");
                    foreach (Genre genre in genres)
                    {
                        Console.WriteLine(genre.GenreId + "  " + genre.GenreName);
                    }
                    try
                    {
                        for (int i = 0; i < genres.Count; i++)
                        {
                            Console.WriteLine("Enter Genre name to update");

                            if (int.Parse(Console.ReadLine()) == genres[i].GenreId)
                            {
                                Console.WriteLine("Enter new genre name");
                                genres[i].GenreName = Console.ReadLine();
                                Console.WriteLine(movieManager.UpdateGenre(genres[i]));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Something went wrong! try again");
                    }
                    break;
                }

                    #endregion
                    #region deleteSection
                case "7":
                {
                    Console.WriteLine("Which Actor would you like to delete? (use their ID)");
                    foreach (Actor actor in actors)
                    {
                        Console.WriteLine(actor.ActorId + "  " + actor.GetFullName());
                    }
                    try
                    {
                        int input = int.Parse(Console.ReadLine());
                        for (int i = 0; i < actors.Count; i++)
                        {
                            if (input == actors[i].ActorId)
                            {
                                Console.WriteLine(movieManager.DeleteActor(actors[i]));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Something went wrong! try again");
                    }
                    break;
                }

                case "8":
                {
                    Console.WriteLine("Which Movie would you like to delete? (use their ID)");
                    foreach (Movie movie in movies)
                    {
                        Console.WriteLine(movie.MovieId + "  " + movie.Title);
                    }
                    try
                    {
                        int input = int.Parse(Console.ReadLine());
                        for (int i = 0; i < movies.Count; i++)
                        {
                            if (input == movies[i].MovieId)
                            {
                                movieManager.DeleteMovie(movies[i]);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Something went wrong! try again");
                    }

                    break;
                }

                case "9":
                {
                    Console.WriteLine("Which Genre would you like to delete? (use their ID)");
                    foreach (Genre genre in genres)
                    {
                        Console.WriteLine(genre.GenreId + "  " + genre.GenreName);
                    }
                    try
                    {
                        int input = int.Parse(Console.ReadLine());
                        for (int i = 0; i < genres.Count; i++)
                        {
                            if (input == genres[i].GenreId)
                            {
                                movieManager.DeleteGenre(genres[i]);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Something went wrong! try again");
                    }
                    break;
                }

                    #endregion
                default:
                    Console.WriteLine("Wrong input!");
                    break;
                }
                Console.WriteLine("Press any key to continues...");
                Console.ReadLine();
            }
            #region Movie Night part 1
            //Console.WriteLine("Search for a movie title..");
            //string str = "";

            //while (string.IsNullOrWhiteSpace(str))
            //{
            //    str = Console.ReadLine();
            //}
            //foreach (Movie movie in movieManager.GetMovies(str))
            //{
            //    Console.WriteLine(movie.Title);
            //}
            //str = string.Empty;

            //Console.WriteLine("Search for Actors..");
            //while (string.IsNullOrWhiteSpace(str))
            //{
            //    str = Console.ReadLine();
            //}
            //foreach (Actor actor in movieManager.GetActors(str))
            //{
            //    Console.WriteLine(actor.GetFullName() + "\n");
            //}
            //str = string.Empty;

            //foreach (Genre genre in movieManager.GetGenres())
            //{
            //    Console.WriteLine(genre.GenreId +"  "+genre.GenreName);
            //}

            //Console.WriteLine("Search for movies with the number of a genre...");
            //while (string.IsNullOrWhiteSpace(str))
            //{
            //    str = Console.ReadLine();
            //}
            //foreach (Movie movie in movieManager.GetMoviesByGenre(str))
            //{
            //    Console.WriteLine(movie.Title + "    "+movie.Genres);
            //}

            //Console.ReadLine();

            ////gets all movies
            //foreach (Movie movie in movieManager.GetMovies())
            //{
            //    Console.WriteLine(movie.Title + " " + movie.ReleaseYear + "\n");
            //}
            ////Gets all actors
            //foreach (Actor actor in movieManager.GetActors())
            //{
            //    Console.WriteLine(actor.FirstName +" "+ actor.LastName +" "+ actor.ActorId);
            //}
            #endregion
        }
        static void Menu()
        {
            bool showmenu = true;

            while (showmenu)
            {
                Console.Clear();
                Console.WriteLine("================================");
                Console.WriteLine("        Movie Database");
                Console.WriteLine("================================");
                Console.WriteLine("(1) Show all movies!");
                Console.WriteLine("(2) Show all Actors");
                Console.WriteLine("(3) Search movies");
                Console.WriteLine("(4) Search Actors");
                Console.WriteLine("(5) Search Genres");
                Console.WriteLine("(6) Insert Actor");
                Console.WriteLine("(7) Insert Movie");
                Console.WriteLine("(8) Insert Genre");
                Console.WriteLine("(9) Show all genres");
                Console.WriteLine("(F1) Update movie");
                Console.WriteLine("(F2) Update actor");
                Console.WriteLine("(F3) Update Genre");
                Console.WriteLine("(F4) Delete Movie");
                Console.WriteLine("(F5) Delete Actor");
                Console.WriteLine("(F6) Delete Genre");
                switch (UserKeyInput().Key)
                {
                case ConsoleKey.D1:
                    Console.Clear();
                    Console.WriteLine("These are all the movies in the database!");
                    List <Movie> movie = MovieManager.GetMovies();
                    foreach (Movie item in movie)
                    {
                        Console.WriteLine("Movie ID:(" + item.ID + ")");
                        Console.WriteLine("Movie Title: " + item.Title);
                        Console.WriteLine("Movie Description: " + item.Description);
                        Console.WriteLine("Movie Release date: " + item.Date + "\n");
                    }
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D2:
                    Console.Clear();
                    Console.WriteLine("These are all the actors in the database!");
                    List <Actor> actor = MovieManager.GetActors();
                    foreach (Actor item in actor)
                    {
                        Console.WriteLine("Actor ID:(" + item.ID + ")");
                        Console.WriteLine("Actor Firstname: " + item.Firstname);
                        Console.WriteLine("Actor Lastname: " + item.Lastname);
                    }
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D3:
                    Console.Clear();
                    Console.WriteLine("Type the name of the movie you want to find!");
                    string searchmovie = Console.ReadLine();
                    foreach (Movie item in MovieManager.SearchMovies(searchmovie))
                    {
                        Console.WriteLine("Movie ID:(" + item.ID + ")");
                        Console.WriteLine("Movie Title: " + item.Title);
                        Console.WriteLine("Movie Description: " + item.Description + "\n");
                    }
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D4:
                    Console.Clear();
                    Console.WriteLine("Type the name of the actor you want to find!");
                    string searchactor = Console.ReadLine();
                    foreach (Actor item in MovieManager.SearchActor(searchactor))
                    {
                        Console.WriteLine("Movie ID:(" + item.ID + ")");
                        Console.WriteLine("Movie Title: " + item.Firstname);
                        Console.WriteLine("Movie Description: " + item.Lastname + "\n");
                    }
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D5:
                    Console.Clear();
                    Console.WriteLine("Type the name of the genre you want to find movies from");
                    string searchgenre = Console.ReadLine();
                    foreach (Movie item in MovieManager.SearchGenres(searchgenre))
                    {
                        Console.WriteLine("Genre ID:(" + item.ID + ")");
                        Console.WriteLine("Genre Name: " + item.Title);
                        Console.WriteLine("Movie Description: " + item.Description + "\n");
                    }
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D6:
                    Console.Clear();
                    Console.WriteLine("Type the firstname and lastname of the actor you want to add");
                    string firstname = Console.ReadLine();
                    string lastname  = Console.ReadLine();
                    MovieManager.InsertActor(new Actor(firstname, lastname));
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D7:
                    Console.Clear();
                    Console.WriteLine("Type the movie name");
                    string moviename = Console.ReadLine();
                    Console.WriteLine("Type the movie date (YYYY-MM-DD)");
                    string date = Console.ReadLine();
                    Console.WriteLine("Type the description of the movie");
                    string des = Console.ReadLine();
                    MovieManager.InsertMovie(new Movie(moviename, des, date));
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D8:
                    Console.Clear();
                    Console.WriteLine("Type the genre name");
                    string genrename = Console.ReadLine();
                    MovieManager.InsertGenre(new Genre(genrename));
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.D9:
                    Console.Clear();
                    Console.WriteLine("These are all the genres in the database!");
                    List <Genre> genres = MovieManager.GetGenres();
                    foreach (Genre item in genres)
                    {
                        Console.WriteLine("Genre name: " + item._Genre);
                    }
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.F1:
                    Console.Clear();
                    Console.WriteLine("Type the index of the movie you want to change");
                    int updatemovie = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Type the new movie name");
                    string upmoviename = Console.ReadLine();
                    Console.WriteLine("Type the new movie date (YYYY-MM-DD)");
                    string update = Console.ReadLine();
                    Console.WriteLine("Type the new description of the movie");
                    string updes = Console.ReadLine();
                    MovieManager.UpdateMovie(new Movie(upmoviename, updes, update), updatemovie);
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.F2:
                    Console.Clear();
                    Console.WriteLine("Type the index of the actor you want to change");
                    int updateactor = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Type the new actor name");
                    string upactorname = Console.ReadLine();
                    Console.WriteLine("Type the new actor last name");
                    string upactorlast = Console.ReadLine();
                    MovieManager.UpdateActor(new Actor(upactorname, upactorlast), updateactor);
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.F3:
                    Console.Clear();
                    Console.WriteLine("Type the index of the genre you want to change");
                    int updategenre = Int32.Parse(Console.ReadLine());
                    Console.WriteLine("Type the new genre name");
                    string upname = Console.ReadLine();
                    MovieManager.UpdateGenre(new Genre(upname), updategenre);
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.F4:
                    Console.Clear();
                    Console.WriteLine("Type the name of the movie you want to delete");
                    string delmoviename = Console.ReadLine();
                    Console.WriteLine(MovieManager.DeleteMovie(new Movie(delmoviename, null, null), delmoviename));
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.F5:
                    Console.Clear();
                    Console.WriteLine("Type the name of the actor you want to delete");
                    string delactor = Console.ReadLine();
                    Console.WriteLine(MovieManager.DeleteActor(new Actor(delactor, null), delactor));
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                case ConsoleKey.F6:
                    Console.Clear();
                    Console.WriteLine("Type the name of the genre you want to delete");
                    string delgenre = Console.ReadLine();
                    Console.WriteLine(MovieManager.DeleteGenre(new Genre(delgenre), delgenre));
                    Console.WriteLine("Press 'Enter' to return to main menu");
                    Console.ReadLine();
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #7
0
        public static void UpdateMovie()
        {
            int          movId;
            bool         notANum;
            List <Movie> movies;

            do
            {
                Console.Write("Which movie would you like to edit?\n");
                movies = MovieManager.MovieList("");
                int i = 0;
                foreach (Movie movie in movies)
                {
                    i++;
                    Console.WriteLine(i + ") " + movie.Title);
                }

                notANum = false;
                Console.Write("Input: ");
                if (!int.TryParse(Console.ReadLine(), out movId))
                {
                    Console.WriteLine("Invalid input");
                    Console.ReadKey();
                    notANum = true;
                }
                Console.Clear();
            } while (notANum);
            int updMov = movies[movId - 1].ID;

            Console.Clear();
            Console.Write("Title: ");
            string title = Console.ReadLine();

            Console.Clear();

            int  releaseYear;
            bool noNum;

            do
            {
                noNum = false;
                Console.Write("Release year: ");
                if (!int.TryParse(Console.ReadLine(), out releaseYear))
                {
                    Console.WriteLine("Invalid input");
                    Console.ReadKey();
                    noNum = true;
                }
                Console.Clear();
            } while (noNum);

            Console.Write("Description: ");
            string des = Console.ReadLine();

            Console.Clear();

            MovieManager.UpdateMovie(new Movie(updMov, title, releaseYear, des));

            Console.WriteLine("Movie has now been updated");
            Console.ReadKey();
            Console.Clear();
        }