示例#1
0
        /// <summary>
        /// 更新购物车一条信息
        /// </summary>
        /// <param name="cartLineInfo"></param>
        /// <returns></returns>
        public JsonResult UpdateCartLine(string cartLineInfo)
        {
            if (Session["IsGuest"] != null)
            {
                bool isGuest = (bool)Session["IsGuest"];
                if (isGuest)
                {
                    return(new JsonResult()
                    {
                        Data = new JsonResponseData()
                        {
                            IsSuccess = false, Msg = "该功能暂未开通"
                        }
                    });
                }
            }

            string           msg;
            JsonResponseData result = new JsonResponseData()
            {
                IsSuccess = true
            };
            var user = GetUser();

            if (user == null)
            {
                result.IsSuccess = false;
                result.Msg       = "请重新登陆";
                return(new JsonResult()
                {
                    Data = result
                });
            }
            BuyerShoppingCart line = JsonConvert.DeserializeObject <BuyerShoppingCart>(cartLineInfo);


            int count;


            try
            {
                BuyerShoppingCartBll.DeleteCertLine(user.BuyerId, line.SellerId, line.ProductId, out msg);


                if (line.ProductQuantity > 0)
                {
                    line.LMan    = user.BuyerId;
                    line.RMan    = user.BuyerId;
                    line.BuyerId = user.BuyerId;

                    if (BuyerShoppingCartBll.Insert(line))
                    {
                        result.IsSuccess = result.IsSuccess && true;
                        result.Msg       = "修改成功";



                        if (BuyerShoppingCartBll.GetCertCount(user.BuyerId, line.SellerId, out count, out msg))
                        {
                            result.IsSuccess = result.IsSuccess && true;
                            result.Msg       = count + "";
                        }
                        else
                        {
                            result.Msg = count + "";
                        }
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Msg       = "修改失败";
                    }
                }
                else
                {
                    if (BuyerShoppingCartBll.GetCertCount(user.BuyerId, line.SellerId, out count, out msg))
                    {
                        result.IsSuccess = result.IsSuccess && true;
                        result.Msg       = count + "";
                    }
                    else
                    {
                        result.Msg = count + "";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("更新购物车失败" + ex.Message);
            }

            return(new JsonResult()
            {
                Data = result
            });
        }
示例#2
0
        /// <summary>
        /// 添加商品到购物车
        /// </summary>
        /// <param name="sellerId"></param>
        /// <param name="productId"></param>
        /// <param name="cartLines"></param>
        /// <returns></returns>
        public JsonResult AddGoodsToCart(string cartLines)
        {
            if (Session["IsGuest"] != null)
            {
                bool isGuest = (bool)Session["IsGuest"];
                if (isGuest)
                {
                    return(new JsonResult()
                    {
                        Data = new JsonResponseData()
                        {
                            IsSuccess = false, Msg = "该功能暂未开通"
                        }
                    });
                }
            }


            string           msg;
            JsonResponseData result = new JsonResponseData()
            {
                IsSuccess = true
            };
            var user = GetUser();

            if (user == null)
            {
                result.IsSuccess = false;
                result.Msg       = "请重新登陆";
                return(new JsonResult()
                {
                    Data = result
                });
            }
            List <BuyerShoppingCart> lines = JsonConvert.DeserializeObject <List <BuyerShoppingCart> >(cartLines);

            int sellerId = 0;

            if (lines.Count > 0)
            {
                sellerId = lines.FirstOrDefault().SellerId;
            }


            try
            {
                BuyerShoppingCartBll.DeleteBySellerId(user.BuyerId, sellerId, out msg);


                lines = lines.Where(m => m.ProductQuantity > 0).ToList();

                foreach (BuyerShoppingCart line in lines)
                {
                    line.LMan    = user.BuyerId;
                    line.RMan    = user.BuyerId;
                    line.BuyerId = user.BuyerId;

                    if (BuyerShoppingCartBll.Insert(line))
                    {
                        result.IsSuccess = result.IsSuccess && true;
                        result.Msg       = "添加成功";
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Msg       = "添加失败";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("更新购物车失败" + ex.Message);
            }

            return(new JsonResult()
            {
                Data = result
            });
        }