//Adds movie to dictionary public void AddMovieToDatabase(Movie movie) { if (movieTable.ContainsKey(movie.Year)) { Feedback = "A movie for that year already exists in the database"; } else { movieTable.Add(movie.Year, movie); Feedback = movie.Title + ", " + movie.Year + ", has been successfully added to the database."; } }
//Seeds the database with records public void CreateInitialMovieEntries() { List<Movie> seedList = new List<Movie>(); Movie movie1 = new Movie(1961, "West SideStory", "Jerome Robbins"); Movie movie2 = new Movie(1972, "The Godfather", "Francis Ford Coppola"); Movie movie3 = new Movie(1984, "Amadeus", "Milos Forman"); Movie movie4 = new Movie(2007, "No Country for Old Men", "Ethan & Joel Coen"); seedList.Add(movie1); seedList.Add(movie2); seedList.Add(movie3); seedList.Add(movie4); foreach (Movie movie in seedList) { AddMovieToDatabase(movie); } }
//Creates movie object from textbox entries public Movie CreateMovieRecord() { int key = Convert.ToInt16(txtAddYear.Text); String addTitle = txtAddTitle.Text; String addDirector = txtAddDirector.Text; Movie = new Movie(key, addTitle, addDirector); return Movie; }
//Selects a specific movie record from the dictionary public Movie SelectMovie(TextBox textBox) { int key = Convert.ToInt16(textBox.Text); SelectedMovie = movieTable[key]; return SelectedMovie; }