Exemple #1
0
        //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Add the Actor -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

        private void AddActor_Click(object sender, RoutedEventArgs e)
        {
            AddActor window = new AddActor();

            window.ShowDialog();
            if (window.actor != null)
            {
                using (MoviesDBEntities ctx = new MoviesDBEntities())
                {
                    try {
                        ctx.Actors.Add(window.actor);
                        ctx.SaveChanges();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("This Actress 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....");
            }
        }
Exemple #3
0
 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();
         }
     }
 }