Exemple #1
0
        // AJAX: /ShoppingCart/AddItemToShoppingCart/
        public JsonResult AddItemToShoppingCart(ShoppingCartItemViewModel itemModel)
        {
            // Check if there's a cart for this session
            ShoppingCart shoppingCart = _shoppingCartService.GetShoppingCart(CookieFactory.GetShoppingCartCookie(Request, Response));

            ShoppingCartItem item    = Mapper.Map <ShoppingCartItemViewModel, ShoppingCartItem>(itemModel);
            ShoppingCartItem retItem = _shoppingCartItemService.AddOrUpdateShoppingCartItem(item, shoppingCart.Guid);

            _shoppingCartItemService.SaveShoppingCartItem();

            ShoppingCartItemViewModel newModel = Mapper.Map <ShoppingCartItem, ShoppingCartItemViewModel>(retItem);

            decimal total = _offerService.GetTotal(shoppingCart, _itemService.GetItems());

            return(Json(new { newModel, total = total }, JsonRequestBehavior.AllowGet));
        }