Ejemplo n.º 1
0
        public bool CreateMovieActor(MovieActorsDTO movieActorsDTO)
        {
            bool isCreated = true;
            var  movie     = _movieRepository.FindById(movieActorsDTO.MovieId);
            var  actor     = _actorRepository.FindById(movieActorsDTO.ActorId);

            if (movie == null || actor == null)
            {
                isCreated = false;
                return(isCreated);
            }
            var movieActors = _movieActorsRepository.FindByMovieIdAndActorId(movieActorsDTO.MovieId, movieActorsDTO.ActorId);

            if (movieActors.Count() >= 1)
            {
                throw new Exception("Actor already exists for this movie");
            }
            MovieActors movieActor = new MovieActors
            {
                Id      = Guid.NewGuid().ToString(),
                MovieId = movieActorsDTO.MovieId,
                ActorId = movieActorsDTO.ActorId
            };

            _movieActorsRepository.Create(movieActor);
            return(isCreated);
        }
Ejemplo n.º 2
0
        public IEnumerable <Actor> All()
        {
            var actors = _context.Actors.ToList();
            var movies = _context.MovieActors.ToList();

            var result = actors.GroupJoin(movies,
                                          actor => actor.ActorId,
                                          movie => movie.ActorId,
                                          (actor, movieColletion) =>
                                          new Actor
            {
                ActorId     = actor.ActorId,
                Name        = actor.Name,
                Age         = actor.Age,
                MovieActors = movieColletion.Select(movie => {
                    var mv = new MovieActors
                    {
                        MovieId = movie.MovieId,
                        ActorId = actor.ActorId,
                    };
                    return(mv);
                })
            });

            return(result);
        }
Ejemplo n.º 3
0
        public IEnumerable <Movie> All()
        {
            var movies = _context.Movies.ToList();

            var actors = _context.MovieActors.ToList();

            var result = movies.GroupJoin(actors,
                                          actor => actor.MovieId,
                                          movie => movie.MovieId,
                                          (movie, actorColletion) =>
                                          new Movie
            {
                MovieId     = movie.MovieId,
                Title       = movie.Title,
                ReleasYear  = movie.ReleasYear,
                Genre       = movie.Genre,
                MovieActors = actorColletion.Select(actor => {
                    var mv = new MovieActors
                    {
                        MovieId = movie.MovieId,
                        ActorId = actor.ActorId,
                    };
                    return(mv);
                })
            });

            return(result);
        }
Ejemplo n.º 4
0
        private void tbActors_TextChanged(object sender, EventArgs e)
        {
            IsLoadedActors = false;
            string text = tbActors.Text;

            lvActors.Clear();
            ColumnHeader header = new ColumnHeader();

            header.Text = "";
            header.Name = "col1";
            lvActors.Columns.Add(header);
            lvActors.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            lvActors.HeaderStyle = ColumnHeaderStyle.None;
            try
            {
                using (MovieDB context = new MovieDB())
                {
                    lvActors.CheckBoxes = true;
                    List <actor> actors = null;
                    if (text.Equals(""))
                    {
                        actors = (from c in context.actors
                                  where c.member_of_cast_and_crew.active == 1
                                  orderby c.member_of_cast_and_crew.first_name
                                  select c).ToList();
                    }
                    else
                    {
                        actors = (from c in context.actors
                                  where (c.member_of_cast_and_crew.first_name.ToLower().Contains(text.ToLower()) ||
                                         c.member_of_cast_and_crew.last_name.ToLower().Contains(text.ToLower())) &&
                                  c.member_of_cast_and_crew.active == 1
                                  orderby c.member_of_cast_and_crew.first_name
                                  select c).ToList();
                    }
                    foreach (var actor in actors)
                    {
                        var item = new ListViewItem(actor.member_of_cast_and_crew.first_name + " " + actor.member_of_cast_and_crew.last_name);
                        item.Tag = actor;
                        lvActors.Items.Add(item);
                        if (MovieActors.Contains(actor))
                        {
                            item.Checked = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            IsLoadedActors = true;
        }
Ejemplo n.º 5
0
 private void lvActors_ItemChecked(object sender, ItemCheckedEventArgs e)
 {
     if (IsLoadedActors)
     {
         if (e.Item.Checked)
         {
             MovieActors.Add((actor)(e.Item as ListViewItem).Tag);
             checkedActors.Add(((actor)(e.Item as ListViewItem).Tag));
         }
         else
         {
             MovieActors.Remove((actor)(e.Item as ListViewItem).Tag);
             checkedActors.Remove((actor)(e.Item as ListViewItem).Tag);
         }
     }
 }
        private void AddActorsInMovie(ICollection <int> selectedActorIds, int movieId)
        {
            var collectionToAdd = new List <MovieActors>();

            foreach (var actorId in selectedActorIds.Distinct().ToList())
            {
                //check if person exists and relation doesn't
                if (DbContext.People.Any(p => p.Id == actorId) &&
                    !DbContext.MovieActors.Any(ma => ma.PersonId == actorId && ma.MovieId == movieId))
                {
                    var item = new MovieActors
                    {
                        PersonId = actorId,
                        MovieId  = movieId
                    };

                    collectionToAdd.Add(item);
                }
            }

            DbContext.MovieActors.AddRange(collectionToAdd);
            DbContext.SaveChanges();
        }
Ejemplo n.º 7
0
        private void AddMovieForm_Load(object sender, EventArgs e)
        {
            tbName.Text          = MovieName;
            tbRuntime.Text       = Runtime == 0 ? "" : Runtime.ToString();
            dtpReleaseDate.Value = ReleaseDate;
            tbBudget.Text        = Budget == 0 ? "" : Budget.ToString();
            tbGross.Text         = Gross == 0 ? "" : Gross.ToString();
            tbTagline.Text       = Tagline;
            rtbPlotSummary.Text  = PlotSummary;
            if (Poster.StartsWith("\\"))
            {
                Poster = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + Poster;
            }
            try
            {
                pbPoster.Image = Image.FromFile(Poster);
            }
            catch (FileNotFoundException ex)
            {
                pbPoster.Image = Image.FromFile(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\Posters\\default.png");
            }
            var genreItems = lvGenres.Items;

            foreach (var genre in Genres.ToList())
            {
                foreach (var item in genreItems)
                {
                    genre genreItem = (genre)(item as ListViewItem).Tag;
                    if (genreItem.id == genre.id)
                    {
                        (item as ListViewItem).Checked = true;
                    }
                }
                checkedGenres.Add(genre);
            }
            var languageItems = lvLanguages.Items;

            foreach (var language in Languages.ToList())
            {
                foreach (var item in languageItems)
                {
                    language languageItem = (language)(item as ListViewItem).Tag;
                    if (languageItem.id == language.id)
                    {
                        (item as ListViewItem).Checked = true;
                    }
                }
                checkedLanguages.Add(language);
            }
            var actorItems = lvActors.Items;

            foreach (var actor in MovieActors.ToList())
            {
                foreach (var item in actorItems)
                {
                    actor actorItem = (actor)(item as ListViewItem).Tag;
                    if (actorItem.id == actor.id)
                    {
                        (item as ListViewItem).Checked = true;
                    }
                }
                checkedActors.Add(actor);
            }
            var directorItems = lvDirectors.Items;

            foreach (var director in MovieDirectors.ToList())
            {
                foreach (var item in directorItems)
                {
                    director directorItem = (director)(item as ListViewItem).Tag;
                    if (directorItem.id == director.id)
                    {
                        (item as ListViewItem).Checked = true;
                    }
                }
                checkedDirectors.Add(director);
            }
        }
Ejemplo n.º 8
0
        private void btnAddDirector_Click(object sender, EventArgs e)
        {
            AddMemberOfCastAndCrewForm addMemberOfCastAndCrew = new AddMemberOfCastAndCrewForm("director");

            if (DialogResult.OK == addMemberOfCastAndCrew.ShowDialog())
            {
                try
                {
                    using (MovieDB context = new MovieDB())
                    {
                        DateTime?died = addMemberOfCastAndCrew.Dead ? addMemberOfCastAndCrew.Died : (DateTime?)null;
                        var      memberOfCastAndCrew = new member_of_cast_and_crew()
                        {
                            first_name = addMemberOfCastAndCrew.FirstName,
                            last_name  = addMemberOfCastAndCrew.LastName,
                            birthplace = addMemberOfCastAndCrew.Birthplace,
                            born       = addMemberOfCastAndCrew.Born,
                            died       = died,
                            bio        = addMemberOfCastAndCrew.Bio,
                            image      = addMemberOfCastAndCrew.MemberImage,
                            active     = 1
                        };
                        var director = new director()
                        {
                            member_of_cast_and_crew = memberOfCastAndCrew
                        };
                        context.directors.Add(director);
                        if (addMemberOfCastAndCrew.DoubleMember)
                        {
                            var actor = new actor()
                            {
                                member_of_cast_and_crew = memberOfCastAndCrew
                            };
                            context.actors.Add(actor);
                        }
                        context.SaveChanges();
                        FillDirectorsList();
                        var directorItems = lvDirectors.Items;
                        foreach (var checkedDirector in MovieDirectors.ToList())
                        {
                            foreach (var item in directorItems)
                            {
                                director directorItem = (director)(item as ListViewItem).Tag;
                                if (directorItem.id == checkedDirector.id)
                                {
                                    (item as ListViewItem).Checked = true;
                                }
                            }
                        }
                        FillActorsList();
                        var actorItems = lvActors.Items;
                        foreach (var checkedActor in MovieActors.ToList())
                        {
                            foreach (var item in actorItems)
                            {
                                actor actorItem = (actor)(item as ListViewItem).Tag;
                                if (actorItem.id == checkedActor.id)
                                {
                                    (item as ListViewItem).Checked = true;
                                }
                            }
                        }
                        MoviesUcl.Instance.RefreshTableAndFilters();
                        ActorsUcl.Instance.RefreshTableAndFilters();
                        DirectorsUcl.Instance.RefreshTableAndFilters();
                        MessageBox.Show("Director successfully added.", "Success", MessageBoxButtons.OK);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
Ejemplo n.º 9
0
        public static void Seed(ModelBuilder modelBuilder)
        {
            //seeding data klaarzetten
            //denk aan de volgorde!!
            //companies
            var companies = new Company[]
            {
                new Company {
                    Id = 1, Name = "Warner Bros"
                },
                new Company {
                    Id = 2, Name = "Universal"
                },
                new Company {
                    Id = 3, Name = "Pixar"
                }
            };
            //users
            var users = new User[]
            {
                new User {
                    Id = 1, FirstName = "Slash", LastName = "Slash", Username = "******"
                },
                new User {
                    Id = 2, FirstName = "John", LastName = "Frusciante", Username = "******"
                }
            };
            //Actors
            var actors = new Actor[]
            {
                new Actor {
                    Id = 1, FirstName = "Keanu", LastName = "Reeves"
                },
                new Actor {
                    Id = 2, FirstName = "Kim", LastName = "Basinger"
                },
                new Actor {
                    Id = 3, FirstName = "Robert", LastName = "De Niro"
                },
                new Actor {
                    Id = 4, FirstName = "Walter", LastName = "Capiau"
                },
            };
            //Directors
            var directors = new Director[]
            {
                new Director {
                    Id = 1, FirstName = "Steven", LastName = "Spielberg"
                },
                new Director {
                    Id = 2, FirstName = "Sly", LastName = "Stallone"
                },
                new Director {
                    Id = 3, FirstName = "Kathryn", LastName = "Bigelow"
                }
            };
            //movies
            var movies = new Movie[]
            {
                new Movie {
                    Id = 1, Title = "Point Break", CompanyId = 1
                },
                new Movie {
                    Id = 2, Title = "Rocky", CompanyId = 2
                },
                new Movie {
                    Id = 3, Title = "Rambo", CompanyId = 1
                }
            };
            //MovieActors
            var movieActors = new MovieActors[]
            {
                new MovieActors {
                    ActorId = 1, MovieId = 1
                },
                new MovieActors {
                    ActorId = 2, MovieId = 3
                },
                new MovieActors {
                    ActorId = 2, MovieId = 2
                },
                new MovieActors {
                    ActorId = 3, MovieId = 3
                }
            };
            //movieDirectors
            var movieDirectors = new MovieDirectors[]
            {
                new MovieDirectors {
                    MovieId = 1, DirectorId = 1
                },
                new MovieDirectors {
                    MovieId = 2, DirectorId = 2
                },
                new MovieDirectors {
                    MovieId = 3, DirectorId = 3
                }
            };
            //Ratings
            var ratings = new Rating[]
            {
                new Rating {
                    Id = 1, UserId = 1, MovieId = 1, Score = 10, Review = "Very good! Loved it!"
                },
                new Rating {
                    Id = 2, UserId = 2, MovieId = 3, Score = 4, Review = "Sucks monkeyballs!"
                },
                new Rating {
                    Id = 3, UserId = 2, MovieId = 3, Score = 10, Review = "Effing awesome!!"
                }
            };

            //call the hasdata methods for each entity
            //mind the volgorde!!
            modelBuilder.Entity <Company>().HasData(companies);
            modelBuilder.Entity <Actor>().HasData(actors);
            modelBuilder.Entity <Director>().HasData(directors);
            modelBuilder.Entity <User>().HasData(users);
            modelBuilder.Entity <Movie>().HasData(movies);
            modelBuilder.Entity <MovieDirectors>().HasData(movieDirectors);
            modelBuilder.Entity <MovieActors>().HasData(movieActors);
            modelBuilder.Entity <Rating>().HasData(ratings);
        }
Ejemplo n.º 10
0
        public async Task EditActorAsync(EditMovieInputModel input)
        {
            var entity = this.moviesRepository.All()
                         .Where(x => x.Id == input.Id)
                         .FirstOrDefault();

            entity.Actors = this.actorsMovieRepository.All()
                            .Where(x => x.MovieId == input.Id)
                            .ToList();
            entity.Directors = this.directorMovieRepository.All()
                               .Where(x => x.MovieId == input.Id)
                               .ToList();
            entity.Genres = this.genreMoviesRepository.All()
                            .Where(x => x.MovieId == input.Id)
                            .ToList();

            ICollection <MovieActors> inputActors = new HashSet <MovieActors>();

            foreach (var actor in input.Actors)
            {
                var actorMovie = new MovieActors
                {
                    ActorId = actor,
                    MovieId = entity.Id,
                };

                if (entity.Actors.Contains(actorMovie))
                {
                    continue;
                }

                if (!input.Actors.Contains(actorMovie.ActorId))
                {
                    entity.Actors.Remove(actorMovie);
                }

                inputActors.Add(actorMovie);
            }

            ICollection <MovieGenre> inputGenres = new HashSet <MovieGenre>();

            foreach (var genre in input.Genres)
            {
                var parsedGenreId = int.Parse(genre);
                var genreMovie    = new MovieGenre
                {
                    GenreId = parsedGenreId,
                    MovieId = entity.Id,
                };

                if (entity.Genres.Contains(genreMovie))
                {
                    continue;
                }

                if (!input.Genres.Contains(genreMovie.GenreId.ToString()))
                {
                    entity.Genres.Remove(genreMovie);
                }

                inputGenres.Add(genreMovie);
            }

            ICollection <MovieDirector> inputDirectors = new HashSet <MovieDirector>();

            foreach (var director in input.Directors)
            {
                var directorMovie = new MovieDirector
                {
                    DirectorId = director,
                    MovieId    = entity.Id,
                };

                if (entity.Directors.Contains(directorMovie))
                {
                    continue;
                }

                if (!input.Directors.Contains(directorMovie.DirectorId))
                {
                    entity.Directors.Remove(directorMovie);
                }

                inputDirectors.Add(directorMovie);
            }

            entity.Actors    = inputActors;
            entity.Genres    = inputGenres;
            entity.Directors = inputDirectors;

            entity.IMDBLink    = input.IMDBLink;
            entity.Language    = input.Language;
            entity.Name        = input.Name;
            entity.PosterUrl   = input.PosterUrl;
            entity.Rating      = input.Rating;
            entity.ReleaseDate = input.ReleaseDate;
            entity.TrailerLink = input.TrailerLink;
            entity.Summary     = input.Summary;

            this.moviesRepository.Update(entity);
            await this.moviesRepository.SaveChangesAsync();
        }