private void UpdateExistingContent() { // Finish this method Console.Clear(); Console.WriteLine("Enter the title of the content you'd like to update."); string title = Console.ReadLine(); StreamingContent oldItem = _repo.GetContentByTitle(title); if (oldItem == null) { Console.WriteLine("Content not found, press any key to continue..."); Console.ReadKey(); return; } StreamingContent newItem = new StreamingContent( oldItem.Title, oldItem.Description, oldItem.StarRating, oldItem.Genre, oldItem.MaturityRating ); Console.WriteLine("Which property would you like to update:\n" + "1. Title\n" + "2. Description\n" + "3. Star Rating\n" + "4. Maturity Rating\n" + "5. Genre\n" + "6. Nevermind"); string selection = Console.ReadLine(); switch (selection) { case "1": Console.WriteLine("Enter a new title"); string newTitle = Console.ReadLine(); newItem.Title = newTitle; bool wasSuccessful = _repo.UpdateExistingContent(title, newItem); if (wasSuccessful) { Console.WriteLine("Item successfully updated"); } else { Console.WriteLine($"Error: Could not update {title}"); } break; default: break; } }
public void UpdateExistingContent_ShouldReturnTrue() { //Arrange StreamingContent_Repo repo = new StreamingContent_Repo(); StreamingContent oldContent = new StreamingContent("Toy Story", "Toys come to life", 8, Genre.Documentary, MaturityRating.PG); StreamingContent newContent = new StreamingContent("Toy Story", "Toys come to life", 10, Genre.Action, MaturityRating.G); repo.AddContentToDirectory(oldContent); // Act bool updateResult = repo.UpdateExistingContent(oldContent.Title, newContent); //Assert Assert.IsTrue(updateResult); }
public void UpdateContent_ShouldUpdate() { StreamingContent newContent = new StreamingContent( "Spaceballs", "Funny movie about star balls", Maturity.PG13, 5, GenreType.SciFiComedy ); bool wasUpdated = _repo.UpdateExistingContent("Spaceballs", newContent); Assert.IsTrue(wasUpdated); StreamingContent updatedContent = _repo.GetContentByTitle("Spaceballs"); GenreType expected = GenreType.SciFiComedy; GenreType actual = updatedContent.GenreType; Assert.AreEqual(expected, actual); Console.WriteLine(updatedContent.Description); }
public void UpdateContent_ShouldUpdate() { StreamingContent newContent = new StreamingContent( "Spaceballs", "A star pilot and his sidekick must come to the rescue of a princess", Maturity.PG13, 5, GenreType.SciFiComedy ); bool wasUpdated = _repo.UpdateExistingContent("Spaceballs", newContent); Assert.IsTrue(wasUpdated); StreamingContent updatedContent = _repo.GetContentByTitle("Spaceballs"); GenreType expected = GenreType.SciFiComedy; GenreType actual = updatedContent.GenreType; Assert.AreEqual(expected, actual); Console.WriteLine(updatedContent.Description); }
private void UpdateContent() { Console.Clear(); Console.WriteLine("------Updating Conent------"); Console.WriteLine("Currently Available Titles:"); //List<StreamingContent> listOfContent = _repo.GetContents(); //Display all titles in the repo //foreach (StreamingContent content in listOfContent) //{ // Console.WriteLine(content.Title); //} DisplayAllTitles(); Console.WriteLine("---------------------------"); Console.WriteLine("Please enter the title you would like to delete:"); string titleToUpdate = Console.ReadLine(); StreamingContent contentToUpdate = _repo.GetContentByTitle(titleToUpdate); if (contentToUpdate == null) { Console.WriteLine("Content not found, press any key to continue..."); Console.ReadKey(); return; } Console.Clear(); Console.WriteLine("------Updating Conent------"); DisplayContent(contentToUpdate); Console.WriteLine("---------------------------"); StreamingContent newContent = new StreamingContent(); Console.WriteLine("Enter Title:"); newContent.Title = Console.ReadLine(); Console.WriteLine("Enter Description:"); newContent.Description = Console.ReadLine(); Console.WriteLine("Enter Star Rating(1.0-10.0):"); newContent.StarRating = Double.Parse(Console.ReadLine()); Console.WriteLine("Ente number for Genre:"); Console.WriteLine("1. Horror"); Console.WriteLine("2. RomCom"); Console.WriteLine("3. Sci-Fi"); Console.WriteLine("4. Action"); Console.WriteLine("5. Documentary"); Console.WriteLine("6. Musical"); Console.WriteLine("7. Drama"); Console.WriteLine("8. Mystery"); /*string genreInput = Console.ReadLine(); * int genreAsInt = int.Parse(genreInput); * newContent.Genre = (Genre)genreAsInt; */ newContent.Genre = (Genre)int.Parse(Console.ReadLine()); bool stopRunning = false; while (!stopRunning) //Maturity Rating Loop { Console.WriteLine("Enter number for Content Rating:"); Console.WriteLine("1. G"); Console.WriteLine("2. PG"); Console.WriteLine("3. PG-13"); Console.WriteLine("4. R"); Console.WriteLine("5. NC-17"); //newContent.MaturityRating = (MaturityRating)int.Parse(Console.ReadLine()); string maturityRating = Console.ReadLine(); switch (maturityRating) { case "1": newContent.MaturityRating = MaturityRating.G; stopRunning = true; break; case "2": newContent.MaturityRating = MaturityRating.PG; stopRunning = true; break; case "3": newContent.MaturityRating = MaturityRating.PG_13; stopRunning = true; break; case "4": newContent.MaturityRating = MaturityRating.R; stopRunning = true; break; case "5": newContent.MaturityRating = MaturityRating.NC_17; stopRunning = true; break; default: Console.WriteLine("Please enter a valid input."); break; } } //Maturity Rating Loop Console.Clear(); Console.WriteLine("------Replacing------"); DisplayContent(contentToUpdate); Console.WriteLine("-----------With------------"); DisplayContent(newContent); Console.WriteLine("---------------------------"); Console.WriteLine("Continue? (Type 'yes' or 'no')"); string continueUpdate = Console.ReadLine(); if (continueUpdate.ToLower() == "yes" || continueUpdate.ToLower() == "y") { bool wasAdded = _repo.UpdateExistingContent(contentToUpdate.Title, newContent); if (wasAdded == true) { Console.WriteLine("Your Content was successfully updated."); Console.WriteLine("Press any key to return to menu."); } else { Console.WriteLine("Opps. Something went wrong. Your Content was not added. Please try again"); Console.WriteLine("Press any key to return to menu."); } Console.ReadKey(); } else { Console.WriteLine("Update canceled. Press any key to return to Main Menu"); Console.ReadKey(); } }
private void UpdateExistingContent() { Console.Clear(); Console.WriteLine("Enter the title you want to update."); string title = Console.ReadLine(); StreamingContent oldItem = _repo.GetContentByTitle(title); if (oldItem == null) { Console.WriteLine("Content not found, press any key to continue"); Console.ReadKey(); return; } StreamingContent newItem = new StreamingContent( oldItem.Title, oldItem.Description, oldItem.StarRating, oldItem.Genre, oldItem.MaturityRating ); Console.Clear(); DisplayContent(oldItem); Console.WriteLine("Select what you would like to update."); Console.WriteLine("1. Title"); Console.WriteLine("2. Description"); Console.WriteLine("3. Star Rating"); Console.WriteLine("4. Genre"); Console.WriteLine("5. Maturity Rating"); Console.WriteLine("6. Never mind"); string selection = Console.ReadLine(); switch (selection) { case "1": Console.WriteLine("Please enter the new title."); string newTitle = Console.ReadLine(); newItem.Title = newTitle; bool wasSuccessful = _repo.UpdateExistingContent(title, oldItem); if (wasSuccessful) { Console.WriteLine("Item successfully updated"); } else { Console.WriteLine($"Error: Could not update {title}"); } break; default: break; } //Console.ReadKey(); }