public async Task AddPost(ActorAddDto actor) { var newActor = _mapper.Map <Actor>(actor); await _actorRepository.UploadImage(actor.ImageFile, newActor); await _actorRepository.Add(newActor); foreach (var movie in actor.MovieIds) { await _movieActorRepository.Add(new MovieActor() { MovieId = movie, ActorId = newActor.Id }); } //foreach (var movie in actor.MovieIds) //{ // var newMovieActor = new MovieActor() // { // MovieId = movie, // ActorId = newActor.Id // }; // await _movieActorRepository.Add(newMovieActor); //} DO PRZETESTOWANIA Z MAPPEREM }
public async Task AddPost(MovieAddDto movie) { var newMovie = _mapper.Map <Movie>(movie); await _movieRepository.UploadImage(movie.ImageFile, newMovie); await _movieRepository.Add(newMovie); foreach (var newActorDto in movie.NewActors) { var newActor = _mapper.Map <Actor>(newActorDto); await _actorRepository.Add(newActor); await _actorRepository.UploadImage(newActorDto.ImageFile, newActor); await _movieActorRepository.Add(new MovieActor() { MovieId = newMovie.Id, ActorId = newActor.Id }); } foreach (var actor in movie.ActorIds) { await _movieActorRepository.Add(new MovieActor() { MovieId = newMovie.Id, ActorId = actor }); } foreach (var category in movie.CategoryIds) { await _movieCategoryRepository.Add(new MovieCategory() { MovieId = newMovie.Id, CategoryId = category }); } }