Exemplo n.º 1
0
        public String AddToCart(int id)
        {
            if (Session["ID"] != null)
            {
                int userId = ((int)Session["ID"]);

                var cfs = from v in db.CartFlowers
                          where v.FlowerId == id && v.UserId == userId
                          select v;

                CartFlower c = cfs.FirstOrDefault();
                if (c == null)
                {
                    CartFlower cf = new CartFlower();
                    cf.FlowerId = id;
                    cf.UserId   = userId;
                    cf.Count    = 1;
                    Flower f = db.Flowers.Find(id);
                    cf.Price       = f.Price;
                    cf.Img         = f.Img;
                    cf.ProductName = f.ProductName;
                    db.CartFlowers.Add(cf);
                }
                else
                {
                    c.Count          += 1;
                    db.Entry(c).State = EntityState.Modified;
                }
                db.SaveChanges();
                return("添加购物车成功");
            }
            return("请先登录");
        }
Exemplo n.º 2
0
        public ActionResult EditCart(int?id)
        {
            CartFlower cf = db.CartFlowers.Find(id);

            if (cf == null)
            {
                return(HttpNotFound());
            }
            return(View(cf));
        }
Exemplo n.º 3
0
        public ActionResult CartDelete(int?id)
        {
            CartFlower cf = db.CartFlowers.Find(id);

            if (cf != null)
            {
                db.CartFlowers.Remove(cf);
                db.SaveChanges();
            }
            return(RedirectToAction("Cart"));
        }
Exemplo n.º 4
0
        public String ChangeCount(int id, int count)
        {
            CartFlower cf = db.CartFlowers.Find(id);

            if (cf != null)
            {
                if (cf.Count != count)
                {
                    cf.Count           = count;
                    db.Entry(cf).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return("OK");
            }
            return("ERROR");
        }