Пример #1
0
        // GET: Author
        public ActionResult Index()
        {
            IEnumerable <AuthorDTO> authorDtos = authorService.GetAuthors();
            var mapper       = new MapperConfiguration(cfg => cfg.CreateMap <AuthorDTO, AuthorViewModel>()).CreateMapper();
            var authors      = mapper.Map <IEnumerable <AuthorDTO>, List <AuthorViewModel> >(authorDtos);
            var authorMapper = new MapperConfiguration(cfg => cfg.CreateMap <BookDTO, BookViewModel>()).CreateMapper();

            for (int i = 0; i < authors.Count; i++)
            {
                IEnumerable <BookDTO> booksDtos = authorService.GetBooks(authors[i].Id).ToList();
                authors[i].Books = authorMapper.Map <IEnumerable <BookDTO>, List <BookViewModel> >(booksDtos);
            }
            return(View(authors));
        }