Exemplo n.º 1
0
 private static void AddCategories(BookViewModel bookView, ICollection<Category> categories)
 {
     foreach (var category in categories)
     {
         bookView.Categories.Add(category.Name);
     }
 }
Exemplo n.º 2
0
        public static BookViewModel Create(Book book)
        {
            var bookView = new BookViewModel
            {
                Id = book.Id,
                Title = book.Title,
                Description = book.Description,
                Edition = book.Edition,
                Price = book.Price,
                Copies = book.Copies,
                ReleaseDate = book.ReleaseDate,
                AgeRestriction = book.AgeRestriction,
                Author = book.Author != null ? book.Author.FirstName + " " + book.Author.LastName : "",
                Categories = new List<string>()
            };

            AddCategories(bookView, book.Categories);

            return bookView;
        }