Ejemplo n.º 1
0
        public static AuthorViewModel CreateFromAuthor(Author author,
                                                       bool includeBooks  = false,
                                                       bool includeSeries = false)
        {
            var dto = new AuthorViewModel
            {
                Id           = author.Id,
                Name         = author.Name,
                Surname      = author.Surname,
                Bio          = author.Bio,
                CreationDate = author.CreationDate,
                CreatorId    = author.CreatorId
            };

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

            if (includeSeries)
            {
                dto.Series = SerieViewModel.CreateFromSeries(author.Books.GetSeries(), false, true);
            }

            return(dto);
        }
Ejemplo n.º 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);
        }