public void deleteMovie() { try { NLogger nLogger = new NLogger(); Menu menu = new Menu(); System.Console.WriteLine("\tIdentify the Movie to delete."); lookThenDelete(); System.Console.Write("\tDelete the movie by entering it's ID or [a]bort:\t"); andAgain: var movId = System.Console.ReadLine(); if (movId.Equals("a") || movId.Equals("q")) { menu.menuSelect(); } int movIdDel; if (!Int32.TryParse(movId, out movIdDel)) { System.Console.Write("\t Entering the movie's ID or [a]bort:\t"); goto andAgain; } else { var context = new MovieContext(); context.ChangeTracker.LazyLoadingEnabled = false; var movie = context.Movies.Single(a => a.Id == movIdDel); nLogger.nLog("Movie Id selected: " + movIdDel); var movieGenres = context.MovieGenres.Where(b => EF.Property <int>(b, "MovieId") == movIdDel); foreach (var movieGenre in movieGenres) { movie.MovieGenres.Remove(movieGenre); } var userMovies = context.UserMovies.Where(b => EF.Property <int>(b, "MovieId") == movIdDel); foreach (var userMovie in userMovies) { movie.UserMovies.Remove(userMovie); } context.Remove(movie); context.SaveChanges(); nLogger.nLog("Delete committed Id: " + movIdDel); menu.menuSelect(); } } catch (System.Exception) { System.Console.WriteLine("Wrong login or password ...."); System.Console.WriteLine("\t....(Or maybe you forced an exit (Ctl+C)) "); System.Console.WriteLine("\t...........(Or maybe an incorrect input) "); System.Console.WriteLine("\t.....as you started to delete a Movie "); File.Delete("pass.cnn"); File.Delete("user.cnn"); System.Environment.Exit(0); } }
public void displayAllMovies() { NLogger nLogger = new NLogger(); System.Console.Write("How many movies do you want to see at a time?\t"); andAgain: var moviePerTime = Console.ReadLine(); if (!Int32.TryParse(moviePerTime, out times)) { System.Console.Write("\t Enter a number"); goto andAgain; } else if (times == 0 || times > 300) { System.Console.WriteLine("A number between 1 and 300"); goto andAgain; } else { timeSaved = times; using (var db = new MovieContext()) { var movieList = db.Movies.Include(x => x.MovieGenres).ThenInclude(x => x.Genre).ToList(); int count = 1; foreach (var movie in movieList) { System.Console.WriteLine($"#{count} {movie.Title} {movie.ReleaseDate.ToString("MM-dd-yyyy")}"); foreach (var genre in movie.MovieGenres) { System.Console.Write($"\t{genre.Genre.Name}"); } count++; System.Console.WriteLine("\n"); times--; if (times == 0) { System.Console.Write("Continue any key or (E)xit to go to Menu?\t"); var nextMove = Console.ReadLine(); if (nextMove == "E" || nextMove == "e" || nextMove == "Q" || nextMove == "q") { nLogger.nLog("Number of Movies Displayed a once: " + times); Menu menu = new Menu(); menu.menuSelect(); } else { times = timeSaved; continue; } } } } } }
public void AddMovie() { Menu menu = new Menu(); NLogger nLogger = new NLogger(); try { System.DateTime date = DateTime.Today; addExplain(); var addMovieInput = Console.ReadLine(); nLogger.nLog("Added: " + addMovieInput); if (addMovieInput.Equals("a") || addMovieInput.Equals("q")) { menu.menuSelect(); } else { using (var db = new MovieContext()) { var movie = new Movie { Title = addMovieInput, ReleaseDate = date }; db.Add(movie); nLogger.nLog("Movie Add Committed"); db.SaveChanges(); menu.menuSelect(); } } } catch (System.Exception) { System.Console.WriteLine("Wrong login or password ..."); System.Console.WriteLine("\t...(Or maybe you forced an exit (Ctl+C)) "); System.Console.WriteLine("\t......(Or incorrect input) "); System.Console.WriteLine("\t.........as you started to add a Movie "); File.Delete("pass.cnn"); File.Delete("user.cnn"); System.Environment.Exit(0); } }
public void updateMovie() { NLogger nLogger = new NLogger(); Menu menu = new Menu(); try { MovieContext db = new MovieContext(); System.Console.WriteLine("\nIdentify the Movie to update."); lookThenUpdate(); System.Console.Write("Update the movie by entering it's ID or [a]bort:\t"); andAgain: var movId = System.Console.ReadLine(); if (movId.Equals("a") || movId.Equals("q")) { menu.menuSelect(); } int movIdUp; if (!Int32.TryParse(movId, out movIdUp)) { System.Console.Write("\t Entering the movie's ID or [a]bort:\t"); goto andAgain; } else { nLogger.nLog("Updating Movie Id: " + movIdUp); var adjustedTitle = db.Movies.First(d => d.Id == movIdUp); System.Console.Write("Enter the updated title or [a]bort\n"); System.Console.Write("for the movie:\t"); var newMovieTitle = System.Console.ReadLine(); if (newMovieTitle.Equals("a") || newMovieTitle.Equals("A") || newMovieTitle.Equals("q")) { menu.menuSelect(); } adjustedTitle.Title = newMovieTitle; db.SaveChanges(); menu.menuSelect(); } } catch (System.Exception) { System.Console.WriteLine("Wrong login or password ..... "); System.Console.WriteLine("\t ... ( maybe incorrect input) "); System.Console.WriteLine("\t ... (Or maybe you forced an exit (Ctl+C)) "); System.Console.WriteLine("\tas you started to updating a Movie "); File.Delete("pass.cnn"); File.Delete("user.cnn"); System.Environment.Exit(0); } }
public void rankingHub() { Console.ForegroundColor = ConsoleColor.DarkMagenta; System.Console.WriteLine("\t\tTREND DASHBOARD\n"); Console.ForegroundColor = ConsoleColor.Cyan; System.Console.Write("View by [O]ccupations or by [A]ge bracket?:\t"); var picked = Console.ReadLine(); if (picked == "O" || picked == "o" || picked == "0" || picked == "j") { nLogger.nLog("View ranking by Occupation"); occupationRanking(); } else { nLogger.nLog("View Ranking by Age"); bracket(); } }
public void newUserCreate() { Menu menu = new Menu(); try { var age = ""; var ageInt = 0; var gender = ""; var zip = ""; var occ = ""; var occInt = 0; System.Console.Write("Create a new User "); Console.ForegroundColor = ConsoleColor.Red; System.Console.WriteLine("Wizard"); Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Yellow; System.Console.Write("Step 1 of 4: Age?\t\t"); Console.ForegroundColor = ConsoleColor.White; andAgain: age = Console.ReadLine(); if (!Int32.TryParse(age, out ageInt)) { System.Console.Write("\t Enter a number"); goto andAgain; } else if (ageInt == 0 || ageInt > 120) { System.Console.WriteLine("An age between 1 and 120"); goto andAgain; } nLogger.nLog("Age of User: "******"Step 2 of 4: Gender? [M/F]\t"); Console.ForegroundColor = ConsoleColor.White; andTryAgain: gender = Console.ReadLine(); if (gender.Equals("M") || gender.Equals("m") || gender.Equals("F") || gender.Equals("f")) { if (gender.Equals("m")) { gender = "M"; } if (gender.Equals("f")) { gender = "F"; } } else { System.Console.Write("\t Enter either \"M\" or \"F\" "); gender = ""; goto andTryAgain; } nLogger.nLog("Gender: " + gender); Console.ForegroundColor = ConsoleColor.Yellow; System.Console.Write("Step 3 of 4: Zipcode?\t\t"); Console.ForegroundColor = ConsoleColor.White; andTryZipAgain: zip = Console.ReadLine(); if (zip.Length < 5) { System.Console.Write("\t Zipcodes are at least 5 characters "); goto andTryZipAgain; } nLogger.nLog("Zip: " + zip); Console.ForegroundColor = ConsoleColor.Blue; System.Console.Write("Step 4 of 4: Occupation?"); Console.ForegroundColor = ConsoleColor.White; int occCount = 2; using (var db = new MovieContext()) { var occupationVar = db.Occupations.ToList(); foreach (var occList in occupationVar) { if (occCount == 2) { System.Console.WriteLine(); } if (occCount == 3) { System.Console.Write($" \tID: ({occList.Id}) ___ {occList.Name}\n"); occCount++; continue; } if (occCount % 2 == 1) { System.Console.Write($"\t\tID: ({occList.Id}) ___ {occList.Name}\n"); occCount++; } else { System.Console.Write($"ID: ({occList.Id}) ___ {occList.Name}"); occCount++; } } } System.Console.Write("\nSelect the ID of user's occupation\t"); andOccAgain: occ = Console.ReadLine(); if (!Int32.TryParse(occ, out occInt)) { System.Console.Write("\t Enter a number"); goto andOccAgain; } nLogger.nLog("Occupation ID: " + occInt); // end of gathering new user data using (var db = new MovieContext()) { var user = db.Users.Include(x => x.Occupation).FirstOrDefault(); user = new User { Age = ageInt, Gender = gender, ZipCode = zip }; db.Add(user); db.SaveChanges(); idUsed = user.Id; db.Database.ExecuteSqlInterpolated($"UPDATE Users SET occupationId = {occInt} WHERE Id = {user.Id} "); db.SaveChanges(); } } catch (System.Exception) { System.Console.WriteLine("Something has gone wrong adding a user, please try again."); menu.menuSelect(); } using (var db = new MovieContext()) { var users = db.Users.Include(x => x.Occupation) .Where(x => x.Id == idUsed).ToList(); foreach (var user in users) { Console.ForegroundColor = ConsoleColor.Green; System.Console.WriteLine($"User Added: ({user.Id}) Age: {user.Age} Sex: {user.Gender} Zip: {user.ZipCode} {user.Occupation.Name}"); Console.ForegroundColor = ConsoleColor.White; } } menu.menuSelect(); }
public void UserRatesMovie() { NLogger nLogger = new NLogger(); try { Menu menu = new Menu(); var userId = ""; int userIdInt = 0; System.Console.Write("Rate a Movie "); Console.ForegroundColor = ConsoleColor.Red; System.Console.WriteLine("Wizard"); Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Yellow; System.Console.Write("Step 1 of 4: Identify User?\t\t"); Console.ForegroundColor = ConsoleColor.White; System.Console.Write("What is your User Id?\t"); andAgain: userId = Console.ReadLine(); if (!Int32.TryParse(userId, out userIdInt)) { System.Console.Write("\t Entering the User's ID\t"); goto andAgain; } nLogger.nLog("User Id : " + userIdInt); using (var db = new MovieContext()) { int count = 0; var users = db.Users.Include(x => x.Occupation) .Where(x => x.Id == userIdInt).ToList(); foreach (var user in users) { if (user.Id == userIdInt) { count = 1; } System.Console.WriteLine($"Welcome user: ({user.Id}) Sex: {user.Gender} Age: {user.Age} Zip: {user.ZipCode} {user.Occupation.Name}"); File.WriteAllText(Path.Combine(Environment.CurrentDirectory, "rate.sav"), userId); } if (count == 0) { System.Console.WriteLine("User Not Found, Returning to Menu"); File.WriteAllText(Path.Combine(Environment.CurrentDirectory, "rate.sav"), "rate"); menu.menuSelect(); } Console.ForegroundColor = ConsoleColor.Yellow; System.Console.Write("Step 2 of 4: Search Movie\t\t"); Console.ForegroundColor = ConsoleColor.White; // System.Console.Write("Find the Movie to Rate. Hit any key\t"); // Console.ReadKey(); // System.Console.WriteLine(); Search search = new Search(); search.searchMovie(); } } catch (System.Exception) { System.Console.WriteLine("Problem with the Rating process, returning to Menu"); Menu menu = new Menu(); menu.menuSelect(); } }
public void searchMovie() { NLogger nLogger = new NLogger(); Menu menu = new Menu(); try { int count = 0; andAgain: MovieContext db = new MovieContext(); System.Console.Write("Provide part of the Movie title or year of Movie: \t"); var search = Console.ReadLine(); if (search.Length < 2) { goto andAgain; } var movieList = db.Movies .FromSqlRaw($"SELECT * FROM dbo.Movies where Title like '%" + search + "%'").ToList(); foreach (var showMovie in movieList) { if (count < 9) { System.Console.WriteLine("[0" + (count + 1) + "] ID: " + showMovie.Id + " " + showMovie.Title); } else { System.Console.WriteLine("[" + (count + 1) + "] ID: " + showMovie.Id + " " + showMovie.Title); } count++; } System.Console.WriteLine("\n" + count + " movie(s) fit this search. "); System.Console.WriteLine("\n"); System.Console.Write("Do you want to [S]earch Movies again?\t"); System.Console.Write("([Enter] to Continue to the next action)\t"); var reSearch = Console.ReadLine(); UserRating userRating = new UserRating(); string testRate = System.IO.File.ReadAllText(Path.Combine(System.Environment.CurrentDirectory, "rate.sav")); if (reSearch == "S" || reSearch == "s" || reSearch == "Y" || reSearch == "y" || reSearch == "a") { count = 0; goto andAgain; } if (!testRate.Equals("rate")) { userRating.rateReturn(); } else { nLogger.nLog("Leaving Movie Search"); menu.menuSelect(); } } catch (System.Exception) { System.Console.WriteLine("Wrong login or password .... "); System.Console.WriteLine("\t...(Or maybe you forced an exit (Ctl+C)) "); System.Console.WriteLine("\t...(Or maybe an incorrect input "); System.Console.WriteLine("\tas you started to look-up Movies "); File.Delete("pass.cnn"); File.Delete("user.cnn"); System.Environment.Exit(0); } }
public void addGenreToMovie() { NLogger nLogger = new NLogger(); try { MovieContext db = new MovieContext(); System.Console.WriteLine("\nIdentify the Movie to Insert Genre."); Console.ForegroundColor = ConsoleColor.DarkMagenta; System.Console.WriteLine("Genres will be added never deleted or modified."); System.Console.WriteLine("This is because First Impressions count and shall not be forgotten"); Console.ForegroundColor = ConsoleColor.White; System.Console.WriteLine(); lookOnly(); System.Console.Write("Insert a movie Genre by entering it's Movie ID and AND Genre ID or [a]bort:\n"); viewGenreList(); andAgain: System.Console.Write("\nEnter Movie ID of the Movie you want to add a Genre to or [a]bort\t"); var movId = System.Console.ReadLine(); if (movId.Equals("a") || movId.Equals("A") || movId.Equals("q")) { menu.menuSelect(); } int movIdInt; if (!Int32.TryParse(movId, out movIdInt)) { System.Console.Write("\t Entering the movie's ID or [a]bort:\t"); goto andAgain; } nLogger.nLog("Insert a Movie Genre for Movie Id: " + movIdInt); System.Console.Write("\nEnter the ID of the Genre you want to add\t"); andGenAgain: var genreSelect = Console.ReadLine(); if (genreSelect.Equals("a") || genreSelect.Equals("A") || genreSelect.Equals("q")) { menu.menuSelect(); } if (!Int32.TryParse(genreSelect, out genreSelectInt)) { System.Console.Write("\t Enter a number"); goto andGenAgain; } else { var query = "INSERT INTO MovieGenres (GenreId, MovieId) VALUES (" + genreSelectInt + "," + movIdInt + ")"; using (var db2 = new MovieContext()) { db2.Database.ExecuteSqlRaw(query); } menu.menuSelect(); } } catch (System.Exception) { System.Console.WriteLine("Wrong login or password ..... "); System.Console.WriteLine("\t ... ( maybe incorrect input) "); System.Console.WriteLine("\t ... (Or maybe you forced an exit (Ctl+C)) "); System.Console.WriteLine("\tas you started to updating a Movie's Genre(s) "); File.Delete("pass.cnn"); File.Delete("user.cnn"); System.Environment.Exit(0); } }