Esempio n. 1
0
        /// <summary>
        /// 从购物车中删除商品
        /// </summary>
        /// <param name="sellerId"></param>
        /// <param name="productId"></param>
        /// <returns></returns>
        public JsonResult DeleteGoodsFromCart(int sellerId, int productId)
        {
            CustomWebResult result = new CustomWebResult();
            var             user   = GetUser();

            if (user == null)
            {
                result.IsSuccess = false;
                result.Msg       = "请重新登陆";
                return(new JsonResult()
                {
                    Data = result
                });
            }

            string msg;

            if (BuyerShoppingCartBll.Delete(sellerId, user.BuyerId, productId, out msg))
            {
                result.IsSuccess = true;
                result.Msg       = "删除成功";
            }
            else
            {
                result.IsSuccess = false;
                result.Msg       = msg;
            }

            return(new JsonResult()
            {
                Data = result
            });
        }
Esempio n. 2
0
        /// <summary>
        /// 从购物车中删除商品
        /// </summary>
        /// <param name="sellerId"></param>
        /// <param name="productId"></param>
        /// <returns></returns>
        public JsonResult DeleteGoodsFromCart(int sellerId, int productId)
        {
            if (Session["IsGuest"] != null)
            {
                bool isGuest = (bool)Session["IsGuest"];
                if (isGuest)
                {
                    return(new JsonResult()
                    {
                        Data = new JsonResponseData()
                        {
                            IsSuccess = false, Msg = "该功能暂未开通"
                        }
                    });
                }
            }

            JsonResponseData result = new JsonResponseData();
            var user = GetUser();

            if (user == null)
            {
                result.IsSuccess = false;
                result.Msg       = "请重新登陆";
                return(new JsonResult()
                {
                    Data = result
                });
            }

            string msg;

            if (BuyerShoppingCartBll.Delete(sellerId, user.BuyerId, productId, out msg))
            {
                result.IsSuccess = true;
                result.Msg       = "删除成功";
            }
            else
            {
                result.IsSuccess = false;
                result.Msg       = msg;
            }

            return(new JsonResult()
            {
                Data = result
            });
        }
Esempio n. 3
0
        /// <summary>
        /// 更新购物车一条信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetCartCount(int sellerId = 0)
        {
            string           msg;
            JsonResponseData result = new JsonResponseData()
            {
                IsSuccess = true
            };
            var user = GetUser();

            if (user == null)
            {
                result.IsSuccess = false;
                result.Msg       = "请重新登陆";
                return(new JsonResult()
                {
                    Data = result
                });
            }



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

            return(new JsonResult()
            {
                Data = result
            });
        }
Esempio n. 4
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
            });
        }
Esempio n. 5
0
        public JsonResult AddSellerOrdersToDb(string orderdetail)
        {
            if (Session["IsGuest"] != null)
            {
                bool isGuest = (bool)Session["IsGuest"];
                if (isGuest)
                {
                    return(new JsonResult()
                    {
                        Data = new JsonResponseData()
                        {
                            IsSuccess = false, Msg = "该功能暂未开通"
                        }
                    });
                }
            }


            JsonResponseData result = new JsonResponseData();
            var user = GetUser();

            if (user == null)
            {
                result.IsSuccess = false;
                result.Msg       = "请重新登陆";
                return(new JsonResult()
                {
                    Data = result
                });
            }


            var models =
                JsonConvert.DeserializeObject <List <SellerOrderDetailTinyViewModel> >(orderdetail);


            if (models == null)
            {
                result.IsSuccess = false;
                result.Msg       = "订单无效,无法提交";
                return(new JsonResult()
                {
                    Data = result
                });
            }

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


            if (models.Count == 0)
            {
                result.IsSuccess = false;
                result.Msg       = "什么也没有买~";
                return(new JsonResult()
                {
                    Data = result
                });
            }



            SellerOrderRun run = new SellerOrderRun()
            {
                Amount          = models.Sum(m => m.ProductQuantity * m.Price),
                BuyerId         = user.BuyerId,
                SellerId        = models.First().SellerId,
                OrderDate       = DateTime.Now,
                Code            = "",
                Config          = "",
                LDate           = DateTime.Now,
                RDate           = DateTime.Now,
                LMan            = user.BuyerId,
                RMan            = user.BuyerId,
                ProductQuantity = models.Sum(m => m.ProductQuantity)
            };

            int    orderId;
            string code;
            string msg;



            if (SellerOrderRunBll.Insert(run, out orderId, out code, out msg))
            {
                int index = 0;
                foreach (SellerOrderDetailTinyViewModel detailTinyViewModel in models)
                {
                    SellerOrderDetail detail = new SellerOrderDetail()
                    {
                        SellerId        = detailTinyViewModel.SellerId,
                        BuyerId         = user.BuyerId,
                        LMan            = user.BuyerId,
                        RMan            = user.BuyerId,
                        LDate           = DateTime.Now,
                        RDate           = DateTime.Now,
                        Index           = index++,
                        OrderId         = orderId,
                        ProductId       = detailTinyViewModel.ProductId,
                        ProductQuantity = detailTinyViewModel.ProductQuantity,
                        ProductName     = detailTinyViewModel.ProductName,
                        ProductPrice    = detailTinyViewModel.Price,
                        TotalPrice      = detailTinyViewModel.Price * detailTinyViewModel.ProductQuantity,
                        ProductUnit     = detailTinyViewModel.ProductUnit
                    };

                    SellerOrderDetailBll.Insert(detail);
                    BuyerShoppingCartBll.Delete(detail.SellerId, detail.BuyerId, detail.ProductId, out msg);
                }

                result.Msg       = "订单生成成功";
                result.IsSuccess = true;
            }
            else
            {
                result.Msg = "通讯异常,订单创建失败";
            }



            return(new JsonResult()
            {
                Data = result
            });
        }
Esempio n. 6
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
            });
        }