//-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Add the Director -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ private void AddDirector_Click(object sender, RoutedEventArgs e) { AddDirector window = new AddDirector(); window.ShowDialog(); if (window.director != null) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { ctx.Directors.Add(window.director); ctx.SaveChanges(); } catch (Exception) { MessageBox.Show("This Director is already exist."); } } } }
private void Button_Click(object sender, RoutedEventArgs e) { if (isFilled() == true) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theActor = (from m in ctx.Actors where m.FirstName == tbActorFN.Text.Trim() && m.LastName == tbActorLN.Text.Trim() select m).First(); Actor = theActor; } catch (Exception) { AddActor window = new AddActor(); window.tbFN.Text = tbActorFN.Text; window.tbLN.Text = tbActorLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actor != null) { ctx.Actors.Add(window.actor); ctx.SaveChanges(); } var aActor = (from m in ctx.Actors where m.FirstName == window.tbFN.Text.Trim() select m).First(); Actor = aActor; } try { var theActress = (from m in ctx.Actresses where m.FirstName == tbActressFN.Text.Trim() && m.LastName == tbActressLN.Text.Trim() select m).First(); Actress = theActress; } catch (Exception) { AddActress window = new AddActress(); window.tbFN.Text = tbActressFN.Text; window.tbLN.Text = tbActressLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actress != null) { ctx.Actresses.Add(window.actress); ctx.SaveChanges(); } var aActress = (from m in ctx.Actresses where m.FirstName == window.tbFN.Text.Trim() select m).First(); Actress = aActress; } try { var theDirector = (from m in ctx.Directors where m.FirstName == tbDirectorFN.Text.Trim() && m.FirstName == tbDirectorFN.Text.Trim() select m).First(); Director = theDirector; } catch (Exception) { AddDirector window = new AddDirector(); window.tbFN.Text = tbDirectorFN.Text; window.tbLN.Text = tbDirectorLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.director != null) { ctx.Directors.Add(window.director); ctx.SaveChanges(); } var aDirector = (from m in ctx.Directors where m.FirstName == window.tbFN.Text.Trim() select m).First(); Director = aDirector; } try { var theMovie = (from m in ctx.Movies where m.Title == tbMovie.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { AddMovie window = new AddMovie(); window.tbTitle.Text = tbMovie.Text; window.tbTitle.IsEnabled = false; window.ShowDialog(); if (window.movie != null) { ctx.Movies.Add(window.movie); ctx.SaveChanges(); } var aMovie = (from m in ctx.Movies where m.Title == window.tbTitle.Text.Trim() select m).First(); Movie = aMovie; } try { GoldenGlobe = new GoldenGlobe { ActressId_Id = Actress.Id, ActorId_Id = Actor.Id, DirectorId_Id = Director.Id, MovieId_MovieSerial = Movie.MovieSerial, Year = Convert.ToInt32(tbYear.Text.Trim()) }; } catch (FormatException) { MessageBox.Show("Invalid Input."); this.Close(); } ctx.SaveChanges(); this.Close(); } } else { MessageBox.Show("Fill all...."); } }
private void Button_Click(object sender, RoutedEventArgs e) { if ((bool)rbActor.IsChecked) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theActor = (from m in ctx.Actors where m.FirstName == tbFN.Text.Trim() && m.LastName == tbLN.Text.Trim() select m).First(); Actor = theActor; } catch (Exception) { AddActor window = new AddActor(); window.tbFN.Text = tbFN.Text; window.tbLN.Text = tbLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actor != null) { ctx.Actors.Add(window.actor); ctx.SaveChanges(); } var theActor = (from m in ctx.Actors where m.FirstName == window.tbFN.Text.Trim() && m.LastName == window.tbLN.Text.Trim() select m).First(); Actor = theActor; } try { var theMovie = (from m in ctx.Movies where m.Title == tbAM.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { MessageBox.Show("Your movie doesn't exist"); this.Close(); } Movie.Actors.Add(Actor); Actor.Movies.Add(Movie); ctx.SaveChanges(); this.Close(); } } else if ((bool)rbActress.IsChecked) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theActress = (from m in ctx.Actresses where m.FirstName == tbFN.Text.Trim() && m.LastName == tbLN.Text.Trim() select m).First(); Actress = theActress; } catch (Exception) { AddActress window = new AddActress(); window.tbFN.Text = tbFN.Text; window.tbLN.Text = tbLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.actress != null) { ctx.Actresses.Add(window.actress); ctx.SaveChanges(); } var theActress = (from m in ctx.Actresses where m.FirstName == window.tbFN.Text.Trim() && m.LastName == window.tbLN.Text.Trim() select m).First(); Actress = theActress; } try { var theMovie = (from m in ctx.Movies where m.Title == tbAM.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { MessageBox.Show("Your movie doesn't exist"); this.Close(); } Movie.Actresses.Add(Actress); Actress.Movies.Add(Movie); ctx.SaveChanges(); this.Close(); } } else if ((bool)rbDirector.IsChecked) { using (MoviesDBEntities ctx = new MoviesDBEntities()) { try { var theDirector = (from m in ctx.Directors where m.FirstName == tbFN.Text.Trim() && m.LastName == tbLN.Text.Trim() select m).First(); Director = theDirector; } catch (Exception) { AddDirector window = new AddDirector(); window.tbFN.Text = tbFN.Text; window.tbLN.Text = tbLN.Text; window.tbFN.IsEnabled = false; window.tbLN.IsEnabled = false; window.ShowDialog(); if (window.director != null) { ctx.Directors.Add(window.director); ctx.SaveChanges(); } var theDirector = (from m in ctx.Directors where m.FirstName == window.tbFN.Text.Trim() && m.LastName == window.tbLN.Text.Trim() select m).First(); Director = theDirector; } try { var theMovie = (from m in ctx.Movies where m.Title == tbAM.Text.Trim() select m).First(); Movie = theMovie; } catch (Exception) { MessageBox.Show("Your movie doesn't exist"); this.Close(); } Movie.Director = Director; Director.Movies.Add(Movie); ctx.SaveChanges(); this.Close(); } } }