示例#1
0
        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));
        }
示例#2
0
        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));
        }