Пример #1
0
        //-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Add the Novie -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

        private void AddMovie_Click(object sender, RoutedEventArgs e)
        {
            AddMovie window = new AddMovie();

            window.ShowDialog();
            if (window.movie != null)
            {
                using (MoviesDBEntities ctx = new MoviesDBEntities())
                {
                    try
                    {
                        ctx.Movies.Add(window.movie);
                        ctx.SaveChanges();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("This Movie 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....");
            }
        }
Пример #3
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     using (MoviesDBEntities ctx = new MoviesDBEntities())
     {
         try
         {
             var movies = (from m in ctx.Movies
                           where m.Title == tbAM.Text
                           select m).First();
             Movie = movies;
         }
         catch (Exception)
         {
             AddMovie window = new AddMovie();
             window.ShowDialog();
             window.tbTitle.Text      = tbAM.Text;
             window.tbTitle.IsEnabled = false;
             var movies = (from m in ctx.Movies
                           where m.Title == window.tbTitle.Text
                           select m).First();
             Movie = movies;
         }
         if ((bool)rbActor.IsChecked)
         {
             try
             {
                 var actor = (from m in ctx.Actors
                              where m.FirstName == tbFN.Text && m.LastName == tbLN.Text
                              select m).First();
                 actor.Movies.Add(Movie);
                 Movie.Actors.Add(actor);
                 ctx.SaveChanges();
                 this.Close();
             }
             catch (Exception)
             {
                 MessageBox.Show("Actor dosen't exist.");
                 this.Close();
             }
         }
         else if ((bool)rbActress.IsChecked)
         {
             try
             {
                 var actress = (from m in ctx.Actresses
                                where m.FirstName == tbFN.Text && m.LastName == tbLN.Text
                                select m).First();
                 actress.Movies.Add(Movie);
                 Movie.Actresses.Add(actress);
                 ctx.SaveChanges();
                 this.Close();
             }
             catch (Exception)
             {
                 MessageBox.Show("Actress dosen't exist.");
                 this.Close();
             }
         }
         else if ((bool)rbDirector.IsChecked)
         {
             try
             {
                 var director = (from m in ctx.Directors
                                 where m.FirstName == tbFN.Text && m.LastName == tbLN.Text
                                 select m).First();
                 director.Movies.Add(Movie);
                 Movie.Director = director;
                 ctx.SaveChanges();
                 this.Close();
             }
             catch (Exception)
             {
                 MessageBox.Show("Director dosen't exist.");
                 this.Close();
             }
         }
     }
 }