// 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)); }
// GET: Book/Create public ActionResult Create() { var listAuthorsDto = authorService.GetAuthors(); var mapperAuthor = new MapperConfiguration(cfg => cfg.CreateMap <AuthorDTO, AuthorViewModel>()).CreateMapper(); var listThemesDto = bookService.GetAllTheme(); var mapperTheme = new MapperConfiguration(cfg => cfg.CreateMap <ThemeDTO, ThemeViewModel>()).CreateMapper(); var book = new BookViewModel() { Authors = mapperAuthor.Map <IEnumerable <AuthorDTO>, List <AuthorViewModel> >(listAuthorsDto), Themes = mapperTheme.Map <List <ThemeDTO>, List <ThemeViewModel> >(listThemesDto) }; return(View(book)); }
public IEnumerable <AuthorDto> GetAuthors() { return(_authorManager.GetAuthors()); }