May 2015
Intermediate to advanced
278 pages
5h 35m
English
As my product owner at work likes to say, this is the chapter where “the rubber meets the road.” The previous chapters have been providing the necessary setup before building the “why,” and when it comes to shopping carts, the “why” is adding the item to the cart.
Before a book can be added to the cart, the book details page needs to be created. In the last chapter when the book listings were created, the link to the book sent the user to Books/Details/id. To start, the BooksController needs to be updated to add this new action. Example 17-1 contains an updated BooksController.
usingShoppingCart.Models;usingShoppingCart.Services;usingShoppingCart.ViewModels;usingSystem;usingSystem.Collections.Generic;usingSystem.Web;usingSystem.Web.Mvc;namespaceShoppingCart.Controllers{publicclassBooksController:Controller{privatereadonlyBookService_bookService=newBookService();publicBooksController(){AutoMapper.Mapper.CreateMap<Book,BookViewModel>();AutoMapper.Mapper.CreateMap<Author,AuthorViewModel>();AutoMapper.Mapper.CreateMap<Category,CategoryViewModel>();}// GET: BookspublicActionResultIndex(intcategoryId){varbooks=_bookService.GetByCategoryId(categoryId);ViewBag.SelectedCategoryId=categoryId;returnView(AutoMapper.Mapper.Map<List<Book>,List<BookViewModel>>(books));}publicActionResultDetails(intid){var
Read now
Unlock full access