Пример #1
0
        public Movie Map(MovieDTO dto, bool recursive = true)
        {
            Movie dbMovie = null;
            if ((dbMovie = _repo.Find<Movie>(dto.Id)) == null) {
                dbMovie = new Movie();
            }
            dbMovie.Title = dto.Title;
            dbMovie.ReleaseDate = dto.ReleaseDate;
            if (dto.Actors != null) {
                dbMovie.Actors = (from a in _repo.Query<Person>()
                                  where dto.Actors.Any(actor => actor.Id == a.Id)
                                  select a).ToList();
            }
            if (dto.Directors != null) {
                dbMovie.Directors = (from a in _repo.Query<Person>()
                                     where dto.Directors.Any(actor => actor.Id == a.Id)
                                     select a).ToList();
            }
            if (dto.Producers != null) {
                dbMovie.Producers = (from a in _repo.Query<Person>()
                                     where dto.Producers.Any(actor => actor.Id == a.Id)
                                     select a).ToList();
            }
            if (dto.Genres != null) {
                dbMovie.Genres = (from g in _repo.Query<Genre>()
                                  where dto.Genres.Any(genre => genre.Id == g.Id)
                                  select g).ToList();
            }

            return dbMovie;
        }
Пример #2
0
        public MovieDTO Map(Movie movie, bool recursive = true)
        {
            MovieDTO dto = new MovieDTO();
            dto.Id = movie.Id;
            dto.Title = movie.Title;
            dto.ReleaseDate = movie.ReleaseDate;

            if (recursive && movie.Actors != null) {
                dto.Actors = (from a in movie.Actors
                              select Map(a, false)).ToList();
            }
            if (recursive && movie.Directors != null) {
                dto.Directors = (from a in movie.Directors
                                 select Map(a, false)).ToList();
            }
            if (recursive && movie.Producers != null) {
                dto.Producers = (from a in movie.Producers
                                 select Map(a, false)).ToList();
            }
            if (recursive && movie.Genres != null) {
                dto.Genres = (from g in movie.Genres
                              select Map(g)).ToList();
            }
            return dto;
        }