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); }
public void LinkActorToExistingMovie(int actorId, int movieId) { var currentActorMovies = _repository.SearchForMovies(x => x.MovieId == movieId).First().ActorsMovies.AsEnumerable(); var currentActors = currentActorMovies.Select(x => x.Actor); var currentActorsIds = currentActors.Select(x => x.ActorId).ToList(); var newActorsIds = currentActorsIds; newActorsIds.Add(actorId); var newActorMovies = newActorsIds.Select(x => new ActorMovie { ActorId = x, MovieId = movieId }); _repository.Update(currentActorMovies, newActorMovies); }