May 2015
Intermediate to advanced
278 pages
5h 35m
English
To complete a usable shopping cart experience, this chapter will extend upon the previous examples to add functionality that will allow the user to increase the quantity of an item purchased or to remove the item completely.
When the cart summary was created, a link was added to view the full details. That link defined the action as the Index of the CartsController. Example 18-1 updates the CartsController to add the new Index method.
usingShoppingCart.Models;usingShoppingCart.Services;usingShoppingCart.ViewModels;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Mvc;namespaceShoppingCart.Controllers{publicclassCartsController:Controller{privatereadonlyCartService_cartService=newCartService();publicCartsController(){AutoMapper.Mapper.CreateMap<Cart,CartViewModel>();AutoMapper.Mapper.CreateMap<CartItem,CartItemViewModel>();AutoMapper.Mapper.CreateMap<Book,BookViewModel>();AutoMapper.Mapper.CreateMap<Author,AuthorViewModel>();AutoMapper.Mapper.CreateMap<Category,CategoryViewModel>();}// GET: CartspublicActionResultIndex(){varcart=_cartService.GetBySessionId(HttpContext.Session.SessionID);returnView(AutoMapper.Mapper.Map<Cart,CartViewModel>(cart));}[ChildActionOnly]publicPartialViewResultSummary(){varcart=_cartService.GetBySessionId(HttpContext ...
Read now
Unlock full access