Beispiel #1
0
 //Updatebutton click event
 private void updateBtn_Click(object sender, RoutedEventArgs e)
 {
     //If statement that prevents updating a row if the inputs are empty
     if (!(movieName.Text == "" || movieReleaseYear.Text == null || movieGenre.Text == "" || movieInstructor.Text == "" || movieActors.Text == ""))
     {
         //Updatemovie is an action where m is a movie entity
         //in the Movies table
         //It selects a movie which has the same id as the variable we made earlier
         //And only selects one movie*
         Entities.Movies updateMovie = (from m in _db.Movies
                                        where m.Id == id
                                        select m).Single();
         //Updating the movie columns with the text that is written in the input fields of the updatepage
         updateMovie.MovieName   = movieName.Text;
         updateMovie.ReleaseYear = int.Parse(movieReleaseYear.Text);
         updateMovie.Genre       = movieGenre.Text;
         updateMovie.Instructor  = movieInstructor.Text;
         updateMovie.Actors      = movieActors.Text;
     }
     //Saving the changes to the database
     _db.SaveChanges();
     //Adding the changes to the list of movies
     MainWindow.datagrid.ItemsSource = _db.Movies.ToList();
     //Hiding the window
     this.Hide();
 }
Beispiel #2
0
 //Insertbutton click event
 private void insertBtn_Click(object sender, RoutedEventArgs e)
 {
     //Making a new movie entity
     Entities.Movies newMovie = new Entities.Movies()
     {
         //Making the columns equal the input fields text
         MovieName   = movieName.Text,
         ReleaseYear = int.Parse(movieReleaseYear.Text),
         Genre       = movieGenre.Text,
         Instructor  = movieInstructor.Text,
         Actors      = movieActors.Text
     };
     //Adding the new movie to the Movies table
     _db.Movies.Add(newMovie);
     //Saving the changes made to the database entity
     _db.SaveChanges();
     //Adding the changes and all other table data to the datagrid
     MainWindow.datagrid.ItemsSource = _db.Movies.ToList();
     //Hiding the window
     this.Hide();
 }