public async Task <bool> SetCart(ShoppingCartInputDto input)
 {
     if (input.CartCheck != null && input.BuyNum == 0)
     {
         return(await SetCartChecked(input));
     }
     else
     {
         return(await SetCartNum(input));
     }
 }
        public string AddCart(ShoppingCartInputDto shoppingCartInput)
        {
            shoppingCartInput.CustomerNo = UserNo;
            var addType = _cartService.AddCarts(shoppingCartInput);

            if (addType.Item1 > 0)
            {
                return(addType.Item2);
            }
            else
            {
                HttpContext.Response.StatusCode = 204;
                return("");
            }
        }
        /// <summary>
        /// 添加购物车
        /// </summary>
        /// <param name="shoppingCartInput"></param>
        /// <returns></returns>
        public (int, string) AddCarts(ShoppingCartInputDto shoppingCartInput)
        {
            int    rowCount = 1;
            string addType  = null;

            try {
                //var carts = ListShoppingCartByCustomerNo (shoppingCartInput.CustomerNo);
                //var currCart = carts.Find (m => m.ProductNo == shoppingCartInput.ProductNo);
                var carts    = RedisHelper.GetHashMemory <ShoppingCarts> ($"carts:{shoppingCartInput.CustomerNo}:*");
                var currCart = carts.Find(m => m.ProductNo == shoppingCartInput.ProductNo);
                //如果存在购物车则说明是添加数量 ,如果不存在 则添加新的购物车信息
                if (currCart != null)
                {
                    currCart.ProductNum += shoppingCartInput.BuyNum;
                    //rowCount = _cartRepository.Update (currCart);
                    addType = "u"; //"u"代表update
                }
                else
                {
                    currCart = new ShoppingCarts {
                        CartGuid     = Guid.NewGuid().ToString(),
                        CustomerNo   = shoppingCartInput.CustomerNo,
                        ProductNo    = shoppingCartInput.ProductNo,
                        ProductNum   = shoppingCartInput.BuyNum,
                        CartSelected = false
                    };
                    //rowCount = _cartRepository.Insert (currCart);
                    addType = "i"; //"i"代表insert
                }
                RedisHelper.SetHashMemory($"carts:{currCart.CustomerNo}:{currCart.CartGuid}", currCart);
                return(rowCount, addType);
            } catch (System.Exception) {
                return(0, addType);

                throw;
            }
        }
 private async Task <bool> SetCartNum(ShoppingCartInputDto input)
 {
     return(await _cartService.SetCartNum(input.CartGuids.FirstOrDefault(), input.BuyNum));
 }
 private async Task <bool> SetCartChecked(ShoppingCartInputDto input)
 {
     return(await _cartService.SetCartCheck(input.CartGuids, input.CartCheck ?? false));
 }