// POST api/values
        public async Task <IActionResult> Put([FromBody] CartItem value)
        {
            if (null == value)
            {
                return(NoContent());
            }
            CartItem cartItem = await _cartItemRepository.GetByID(value.CartID);

            if (null == cartItem)
            {
                await _cartItemRepository.AddAsync(value);
            }
            else
            {
                cartItem.CreatedDateTime     = value.CreatedDateTime;
                cartItem.LastUpdatedDateTime = value.LastUpdatedDateTime;
                cartItem.ProductID           = value.ProductID;
                cartItem.ProductName         = value.ProductName;
                cartItem.Quantity            = value.Quantity;
                cartItem.SessionID           = value.SessionID;
                cartItem.SubTotal            = value.SubTotal;
                cartItem.ThumbImagePath      = value.ThumbImagePath;
                cartItem.UnitPrice           = cartItem.UnitPrice;

                await _cartItemRepository.UpdateAsync(cartItem);
            }
            return(Ok());
        }
        public async Task <ActionResult> AddToShoppingCart([FromQuery] Guid productID, [FromQuery] int amount)
        {
            // Get current user session id.
            string sessionID = HttpContext.Session.Id;
            // Get current user name
            string userID = "anonymous";

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                userID = HttpContext.User.Identity.Name;
            }

            int count = await _cartItemRepository.AddAsync(sessionID, userID, productID, amount);

            JsonResult result = null;

            if (count > 0)
            {
                result = new JsonResult(
                    new
                {
                    success = true,
                    message = "商品已经被添加进<a href=\"/ShoppingCart\">购物车</a>",
                });
            }
            else
            {
                result = new JsonResult(
                    new
                {
                    success = true,
                    message = "添加购物车失败,请重试",
                });
            }
            return(result);
        }