Exemplo n.º 1
0
        /// <summary>
        /// 保存买家购物车信息
        /// </summary>
        /// <param name="model"></param>
        /// <param name="connectionString"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool Save(BuyerShoppingCart model, string connectionString, out string errMsg)
        {
            var old = GetModel(model.BuyerId, model.SellerId, model.ProductId, connectionString, out errMsg);

            if (old == null)
            {
                return(Insert(model, connectionString, out errMsg));
            }
            else
            {
                model.RDate = old.RDate;
                model.RMan  = old.RMan;
                return(Update(model, connectionString, out errMsg));
            }
        }
Exemplo n.º 2
0
        public BuyerShoppingCart GetModel(int buyerId, int sellerId, int productId, string connectionString, out string errMsg)
        {
            BuyerShoppingCart model = null;

            errMsg = string.Empty;
            try
            {
                PredicateGroup pdg = new PredicateGroup();
                pdg.Predicates = new List <IPredicate>();
                pdg.Predicates.Add(Predicates.Field <BuyerShoppingCart>(o => o.BuyerId, Operator.Eq, buyerId));
                pdg.Predicates.Add(Predicates.Field <BuyerShoppingCart>(o => o.ProductId, Operator.Eq, productId));
                pdg.Predicates.Add(Predicates.Field <BuyerShoppingCart>(o => o.SellerId, Operator.Eq, sellerId));

                model = GetModel(pdg, connectionString, out errMsg);
            }
            catch (Exception ex)
            {
                Logger.LogError4Exception(ex, "AppLogger");
            }
            return(model);
        }
Exemplo n.º 3
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
            });
        }