Ejemplo n.º 1
0
        public void UpdateMovie(Movie movie)
        {
            using (MovieDBContext db = new MovieDBContext())
            {
                var updMovie = db.Movies.Include("Actors")
                               .Where(c => c.Id == movie.Id)
                               .FirstOrDefault();

                updMovie.Title       = movie.Title;
                updMovie.Description = movie.Description;
                updMovie.Cover       = movie.Cover;
                updMovie.Duration    = movie.Duration;
                updMovie.Year        = movie.Year;

                IEnumerable <Actor> AddedActors   = movie.Actors.Where(actor => !updMovie.Actors.Contains(actor));
                IEnumerable <Actor> RemovedActors = new List <Actor>(updMovie.Actors.Where(actor => !movie.Actors.Contains(actor)));

                foreach (Actor a in AddedActors)
                {
                    updMovie.Actors.Add(db.Actors.Find(a.Id));
                }

                foreach (Actor a in RemovedActors)
                {
                    updMovie.Actors.Remove(db.Actors.Find(a.Id));
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void AddOrUpdate(object entity)
        {
            using (MovieDBContext db = new MovieDBContext())
            {
                object obj = null;

                switch (entity)
                {
                case Movie m:
                    obj = db.Movies.Find(m.Id);
                    break;

                case Actor a:
                    obj = db.Actors.Find(a.Id);
                    break;

                case Director d:
                    obj = db.Directors.Find(d.Id);
                    break;
                }

                if (obj == null)
                {
                    RecordEntity(entity);
                }
                else
                {
                    UpdateEntity(entity);
                }
            }
        }
Ejemplo n.º 3
0
 private void GetDirectorsFromDB_NoMTM()
 {
     using (MovieDBContext db = new MovieDBContext())
     {
         ShowDirectors(db.Directors.ToList());
     }
     BtnEnabled?.Invoke();
 }
Ejemplo n.º 4
0
 private void GetMoviesFromDB_NoMTM()
 {
     using (MovieDBContext db = new MovieDBContext())
     {
         ShowMovies(db.Movies.ToList());
     }
     BtnEnabled?.Invoke();
 }
Ejemplo n.º 5
0
 private void GetDirectorsFromDB()
 {
     using (MovieDBContext db = new MovieDBContext())
     {
         ShowDirectors(db.Directors.Include("Movies").ToList());
     }
     BtnEnabled?.Invoke();
 }
Ejemplo n.º 6
0
 private void GetMoviesFromDB()
 {
     using (MovieDBContext db = new MovieDBContext())
     {
         ShowMovies(db.Movies.Include("Actors").Include("Directors").Include("Genres").ToList());
     }
     BtnEnabled?.Invoke();
 }
Ejemplo n.º 7
0
 public void RecordMovie(Movie movie)
 {
     using (MovieDBContext db = new MovieDBContext())
     {
         movie.Actors = movie.Actors.Select(a => a = db.Actors.Find(a.Id)).ToList();
         db.Movies.Add(movie);
         db.SaveChanges();
     }
 }
Ejemplo n.º 8
0
        public void RemoveMovie(Movie movie)
        {
            using (MovieDBContext db = new MovieDBContext())
            {
                Movie delMovie = db.Movies
                                 .Include("Actors")
                                 .Where(item => item.Id == movie.Id)
                                 .FirstOrDefault();

                db.Movies.Remove(delMovie);
                db.SaveChanges();
            }
        }
Ejemplo n.º 9
0
 public void RecordPerson(IPerson person)
 {
     using (MovieDBContext db = new MovieDBContext())
     {
         person.Movies = person.Movies.Select(m => m = db.Movies.Find(m.Id)).ToList();
         if (person is Actor)
         {
             db.Actors.Add((Actor)person);
         }
         else if (person is Director)
         {
             db.Directors.Add((Director)person);
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 10
0
        public void UpdatePerson(IPerson person)
        {
            using (MovieDBContext db = new MovieDBContext())
            {
                IPerson updActor = null;

                if (person is Actor)
                {
                    updActor = db.Actors
                               .Where(c => c.Id == person.Id)
                               .FirstOrDefault();
                }
                else if (person is Director)
                {
                    updActor = db.Directors
                               .Where(c => c.Id == person.Id)
                               .FirstOrDefault();
                }

                //updActor = db.Actors
                //        .Where(c => c.Id == person.Id)
                //        .FirstOrDefault();

                updActor.Photo      = person.Photo;
                updActor.Name       = person.Name;
                updActor.Surname    = person.Surname;
                updActor.Patronymic = person.Patronymic;
                updActor.Country    = person.Country;
                updActor.Birth_Date = person.Birth_Date;

                IEnumerable <Movie> AddedMovies   = person.Movies.Where(movie => !updActor.Movies.Contains(movie));
                IEnumerable <Movie> RemovedMovies = new List <Movie>(updActor.Movies.Where(movie => !person.Movies.Contains(movie)));

                foreach (Movie m in AddedMovies)
                {
                    updActor.Movies.Add(db.Movies.Find(m.Id));
                }

                foreach (Movie m in RemovedMovies)
                {
                    updActor.Movies.Remove(db.Movies.Find(m.Id));
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public void RemovePerson(IPerson person)
        {
            using (MovieDBContext db = new MovieDBContext())
            {
                if (person is Actor)
                {
                    Actor delActor = db.Actors
                                     .Include("Movies")
                                     .Where(a => a.Id == person.Id)
                                     .FirstOrDefault();
                    db.Actors.Remove(delActor);
                }
                else if (person is Director)
                {
                    Director delActor = db.Directors
                                        .Include("Movies")
                                        .Where(a => a.Id == person.Id)
                                        .FirstOrDefault();
                    db.Directors.Remove(delActor);
                }

                db.SaveChanges();
            }
        }