public ActionResult Add() { var categoryTypes = _context.CategoryTypes.ToList(); var authors = _context.Authors.ToList(); var viewModel = new ManageBookViewModel { BookDto = Mapper.Map <Book, BookDto>(new Book()), CategoryTypeDtos = categoryTypes.Select(Mapper.Map <CategoryType, CategoryTypeDto>), AuthorDtos = authors.Select(Mapper.Map <Author, AuthorDto>) }; return(View(viewModel)); }
public ActionResult Edit(int id) { var book = _context.Books.SingleOrDefault(x => x.Id == id); if (book == null) { return(HttpNotFound()); } var categoryTypes = _context.CategoryTypes.ToList(); var authors = _context.Authors.ToList(); var viewModel = new ManageBookViewModel { BookDto = Mapper.Map <Book, BookDto>(book), CategoryTypeDtos = categoryTypes.Select(Mapper.Map <CategoryType, CategoryTypeDto>), AuthorDtos = authors.Select(Mapper.Map <Author, AuthorDto>) }; return(View("Add", viewModel)); }