예제 #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));
        }
예제 #2
0
        // AJAX: /ShoppingCart/RemoveFromShoppingCart/
        public JsonResult RemoveFromShoppingCart(string name)
        {
            // Check if there's a cart for this session
            ShoppingCart shoppingCart = _shoppingCartService.GetShoppingCart(CookieFactory.GetShoppingCartCookie(Request, Response));

            if (shoppingCart != null)
            {
                bool success = _shoppingCartItemService.DeleteShoppingCartItemByName(name);
                _shoppingCartService.SaveShoppingCart();

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

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

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public ActionResult Index()
        {
            IEnumerable <Item> items = _itemService.GetItems().ToList();

            IEnumerable <ItemViewModel> modelItems = Mapper.Map <IEnumerable <Item>, IEnumerable <ItemViewModel> >(items);

            // Check if there's a cart for this session
            ShoppingCart shoppingCart = _shoppingCartService.GetShoppingCart(CookieFactory.GetShoppingCartCookie(Request, Response));

            _shoppingCartService.SaveShoppingCart();

            ShoppingCartViewModel cartModel = Mapper.Map <ShoppingCart, ShoppingCartViewModel>(shoppingCart);

            return(View(new ItemsAndCartViewModel
            {
                Items = modelItems,
                ShoppingCart = cartModel,
                Total = _offerService.GetTotal(shoppingCart, items)
            }));
        }