Example #1
0
 public ActionResult Index()
 {
     User user = new User();
     user.UserId = 1;
     user.GuestId = "";
     List<Cart> cartList = _cartService.GetCartList(user);
     return View(cartList);
 }
Example #2
0
        public ActionResult RemoveCart()
        {
            User user = new User();
            user.UserId = 1;
            user.GuestId = "";

            string cartIds = RequestHelper.All("CartIds");
            return Json(_cartService.DeleteCart(user, cartIds));
        }
Example #3
0
        public ActionResult Confim()
        {
            User user = new User();
            user.UserId = 1;
            user.GuestId = "";

            OrderConfimModel model = new OrderConfimModel();

            model.CartIds = RequestHelper.All("CartIds");
            model.CartList = _cartService.GetCartList(user.UserId, model.CartIds);

            return View(model);
        }
Example #4
0
        public ActionResult Register(User user)
        {
            ResultInfo resultInfo = new ResultInfo(1, "传递的参数有误");

            if (ModelState.IsValid)
            {
                resultInfo = _userServices.Register(user);

                //成功后登入并跳转
                Response.Redirect("/member/");
            }

            return View(resultInfo);
        }
Example #5
0
        public ActionResult ConfimOrder(OrderConfimModel model)
        {
            User user = new User();
            user.UserId = 1;
            user.GuestId = "";

            ResultInfo resultInfo = _orderService.Confirm(user, model.CartIds);

            if (resultInfo.Status == 0)
            {
                Response.Redirect("/Order/Succeed");
            }

            return View(resultInfo);
        }
Example #6
0
        public ResultInfo Confirm(User user,string cartIds)
        {
            List<Cart> cartList = _cartService.GetCartList(user.UserId, cartIds);

            Order order = new Order();
            List<Snapshot> snapshotList = new List<Snapshot>();

            order.BuyerId = user.UserId;
            order.Quantity = cartList.Count;
            order.OrderNo = "123456";

            foreach (var cart in cartList)
            {
                Snapshot snapshot = new Snapshot();

                snapshot.UserId = cart.Product.UserId;
                snapshot.CateId = cart.CartId;
                snapshot.ProductName = cart.Product.ProductName;
                snapshot.Attr = cart.Attr;
                snapshot.Photo = cart.ProductPhoto.Url;
                snapshot.Price = cart.Sku.Price;
                snapshot.FinalPrice = cart.Sku.Price;
                snapshot.Quantity = cart.Quantity;
                snapshot.TotalPrice = snapshot.FinalPrice * snapshot.Quantity;

                order.Price += snapshot.TotalPrice;

                snapshotList.Add(snapshot);
                _cartService.DeleteCart(user, cart);
            }

            order.Freight = 0;
            order.RealPay = order.Price;

            int orderId = _orderRepository.Add(order).OrderId;

            foreach (var snapshot in snapshotList)
            {
                snapshot.OrderId = orderId;
                _snapshotRepository.Add(snapshot);
            }

            return new ResultInfo("添加成功");
        }
Example #7
0
        /// <summary>
        /// 获取购物车信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public List<Cart> GetCartList(User user)
        {
            var query = _cartRepository.Entities.Include("Product").Include("Sku").Include("ProductPhoto").AsQueryable();

            if (user.UserId > 0)
            {
                query = from c in query
                        where c.UserId == user.UserId
                        select c;
            }
            else if (user.GuestId != string.Empty)
            {
                query = from c in query
                        where c.GuestId == user.GuestId
                        select c;
            }
            else
            {
                return new List<Cart>();
            }

            return query.ToList();
        }
Example #8
0
        public ResultInfo Edit(User user)
        {
            _userRepository.Update(user);

            return new ResultInfo("修改成功");
        }
Example #9
0
        public ResultInfo Register(User user)
        {
            _userRepository.Add(user);

            return new ResultInfo("注册成功");
        }
Example #10
0
        public ActionResult Profile(User user)
        {
            ResultInfo resultInfo = new ResultInfo(1, "传递的参数有误");

            if (ModelState.IsValid)
            {
                var oldUser = _userServices.GetById(1);
                oldUser.RealName = user.RealName;
                oldUser.Nick = user.Nick;
                oldUser.QQ = user.QQ;

                resultInfo = _userServices.Edit(oldUser);
            }

            return Json(resultInfo);
        }
Example #11
0
 public ResultInfo DeleteCart(User user, string cartIds)
 {
     //批量删除以后研究
     _cartRepository.Delete(cartIds);
     return new ResultInfo("删除成功");
 }
Example #12
0
 public void DeleteCart(User user, Cart cart)
 {
     _cartRepository.Delete(cart);
 }