예제 #1
0
        public async Task <ActionResult> AddWishItemsInCart(int productId, int quantity)
        {
            var cart = new CartService(HttpContext);

            cart.MakeProxyCreationFalse();
            await cart.AddItemsInCart(productId, quantity);

            var wish = new CartService(HttpContext, true);

            wish.MakeProxyCreationFalse();
            await wish.RemoveWishList(productId);

            var items = await cart.GetCartItemsAsync();

            //wish.MakeProxyCreation();

            var viewModel = new ProductItemsViewModel
            {
                WishLists = await wish.GetWishListAsync(),
                Items     = items,
                Sum       = CalculateCart(items)
            };
            var result = JsonConvert.SerializeObject(viewModel, Formatting.Indented,
                                                     new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public async Task <ActionResult> AddToCart(int id, int quantity)
        {
            var cart = new CartService(HttpContext);

            cart.MakeProxyCreationFalse();
            await cart.AddItemsInCart(id, quantity);

            var items = await cart.GetCartItemsAsync();

            var totalsum = CalculateCart(items);

            var model = new CartItemsViewModel
            {
                Items = items,
                Sum   = totalsum
            };

            var result = JsonConvert.SerializeObject(model, Formatting.Indented,
                                                     new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }