Exemplo n.º 1
0
        public void Add(ActorViewModel actorVm)
        {
            var moviesIds = actorVm.FilmographyIds;
            var actor     = new Actor();
            var movies    = new List <Movie>();

            actor.Update(actorVm);

            foreach (var movieId in moviesIds)
            {
                var movie = _repository.SearchForMovies(x => x.MovieId == movieId).First();
                movies.Add(movie);
            }

            if (movies.Any())
            {
                movies.ForEach(x => _repository.Add(new ActorMovie()
                {
                    Movie = x, Actor = actor
                }));
            }
            else
            {
                _repository.AddActor(actor);
            }
        }
Exemplo n.º 2
0
        public void Update(int id, MovieViewModel movieVm)
        {
            var newActorsIds = movieVm.StarringActorsIds;
            var movie        = _repository.SearchForMovies(x => x.MovieId == id).First();

            movie.Update(movieVm);

            var currentActorMovies = _repository.SearchForMovies(x => x.MovieId == id).First().ActorsMovies.AsEnumerable();
            var newActorMovies     = newActorsIds.Select(x => new ActorMovie {
                ActorId = x, MovieId = id
            });

            _repository.Update(currentActorMovies, newActorMovies);
        }