Ejemplo n.º 1
0
        private void AddGoldenGlobeMenuItem_Click(object sender, RoutedEventArgs e)
        {
            AddOscarGoldenGlobe window = new AddOscarGoldenGlobe();

            Prize = "Golden Globe";
            window.ShowDialog();
        }
Ejemplo n.º 2
0
        private void AddOscarMenuItem_Click(object sender, RoutedEventArgs e)
        {
            AddOscarGoldenGlobe window = new AddOscarGoldenGlobe();

            Prize = "Oscar";
            window.ShowDialog();

            if (window.Prize != null)
            {
                using (var context = new MovieContext("MyMovieDB"))
                {
                    var actor    = (from a in context.Actors where a.Id == window.Prize.ActorId select a).ToList().Single();
                    var actress  = (from a in context.Actresses where a.Id == window.Prize.ActressId select a).ToList().Single();
                    var director = (from d in context.Directors where d.Id == window.Prize.DirectorId select d).ToList().Single();
                    try
                    {
                        context.Oscars.Add(new Oscar
                        {
                            Year              = window.Prize.Year,
                            BestActor         = actor,
                            BestActress       = actress,
                            BestDirector      = director,
                            BestMotionPicture = (from m in context.Movies where m.MovieSerial == window.Prize.MovieSerial select m).ToList().Single()
                        });

                        context.SaveChanges();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                MessageBox.Show($"Property: {validationError.PropertyName} Error: {validationError.ErrorMessage}");
                            }
                        }
                    }
                }
            }
        }