コード例 #1
0
        public static AjaxResult AddToShoppingCart(UpdateCartReqModel req)
        {
            AjaxResult result = new AjaxResult();

            result.Success = false;
            int totalProduct = 0;

            #region Check
            string checkResultMessage = "";
            if (req.SysNo <= 0)
            {
                if (req.IsPackage)
                {
                    checkResultMessage = "请输入正确的套餐编号!";
                }
                else
                {
                    checkResultMessage = "请输入正确的商品编号!";
                }
            }
            else if (req.Qty <= 0)
            {
                checkResultMessage = "请输入正确的商品数量";
            }

            #endregion

            #region 加入购物车
            if (string.IsNullOrWhiteSpace(checkResultMessage))
            {
                result.Success     = true;
                checkResultMessage = "加入购物车失败";
                ShoppingItemGroup shoppingItemGroup = ShoppingFacade.BuildShoppingItemGroup(req.IsPackage ? "package" : "product", req.SysNo, req.Qty);
                ShoppingCart      shoppingCart      = ShoppingStorageManager.GetShoppingCartFromCookieOrCreateNew();

                if (shoppingItemGroup != null)
                {
                    ShoppingFacade.AddToShoppingCart(shoppingItemGroup, shoppingCart);
                    ShoppingStorageManager.SaveShoppingCart(shoppingCart);
                    checkResultMessage = "加入购物车成功";
                }
                //计算购物商品数量
                if (shoppingCart != null && shoppingCart.ShoppingItemGroupList != null)
                {
                    foreach (var itemGroup in shoppingCart.ShoppingItemGroupList)
                    {
                        foreach (var item in itemGroup.ShoppingItemList)
                        {
                            totalProduct += itemGroup.Quantity * item.UnitQuantity;
                        }
                    }
                }
            }
            result.Data    = totalProduct;
            result.Message = checkResultMessage;

            #endregion

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 修改数量
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static CartResultModel UpdateCart(UpdateCartReqModel req, string proSysNos = null, string packSysNos = null)
        {
            if (req != null)
            {
                if (req.IsPackage)
                {
                    return(UpdatePackage(req.SysNo, req.Qty, proSysNos, packSysNos));
                }
                else
                {
                    return(UpdateProduct(req.SysNo, req.Qty, proSysNos, packSysNos));
                }
            }

            return(null);
        }