示例#1
0
        public static GenreViewModel CreateFromGenre(Genre genre, bool includeBooks = false)
        {
            var dto = new GenreViewModel
            {
                Id           = genre.Id,
                Name         = genre.Name,
                CreationDate = genre.CreationDate,
                CreatorId    = genre.CreatorId
            };

            if (includeBooks)
            {
                dto.Books = BookViewModel.CreateFromBooks(genre.Books.Select(gb => gb.Book).ToList(), true, true, true);
            }

            return(dto);
        }
示例#2
0
        public static BookViewModel CreateFromBook(Book book,
                                                   bool includeGenres   = false,
                                                   bool includeAuthors  = false,
                                                   bool includeEditions = false,
                                                   bool includeSeries   = false)
        {
            var dto = new BookViewModel
            {
                Id           = book.Id,
                Title        = book.Title,
                Description  = book.Description,
                CreationDate = book.CreationDate,
                CreatorId    = book.CreatorId
            };

            if (includeGenres)
            {
                dto.Genres = GenreViewModel.CreateFromGenres(book.Genres.Select(bg => bg.Genre).ToList());
            }

            if (includeAuthors)
            {
                dto.Authors = AuthorViewModel.CreateFromAuthors(book.Authors.Select(ba => ba.Author).ToList());
            }

            if (includeEditions)
            {
                dto.Editions = BookEditionViewModel.CreateFromBookEditions(book.Editions, false, true, true);
            }

            if (includeSeries)
            {
                dto.Series = SerieViewModel.CreateFromSeries(book.Series.Select(sb => sb.Serie).ToList(), true);
            }

            return(dto);
        }