public ActionResult CreateModelBinding([Bind(Include = "name")] ShoppingCartModel model)
        {
            if (ModelState.IsValid) {
                shopping_cart n = new shopping_cart();
                n.name = model.name;
                db.shopping_cart.Add(n);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View("Create", model);
        }
 public ActionResult CreateParameter(String name_item)
 {
     var x = name_item;
     if (String.IsNullOrEmpty(name_item)) {
         shopping_cart temp = new shopping_cart();
         temp.name = name_item;
         db.shopping_cart.Add(temp);
         db.SaveChanges();
     }
     ViewBag.Error = 1;
     ViewBag.ErrorMessage = "Please try again";
     return RedirectToAction("Index");
 }
        public ActionResult CreateTraditional()
        {
            var name_item = Request["name_item"];

            if (!String.IsNullOrEmpty(name_item)) {
                shopping_cart temp = new shopping_cart();
                temp.name = name_item;
                db.shopping_cart.Add(temp);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.Error = 1;
            ViewBag.ErrorMessage = "Please try again";
            return View("Create");
        }
示例#4
0
        public ActionResult AddCart(string productNo, int qantity, string productName)
        {
            var user = appClass.Member;

            if (appClass.Member == "")
            {
                //ViewBag.Alert = "請先登入!";
                return(RedirectToAction("Login"));
            }
            else
            {
                shopping_cart newItem = new shopping_cart();
                //var buyer = db.member.Where(m => m.member_name == user).FirstOrDefault();

                var item = db.shopping_cart.Where(m => m.member_account == appClass.Account && m.product_no == productNo).FirstOrDefault();

                //若購物車內已有相同商品則只更改數量
                if (item == null)
                {
                    newItem.member_account   = appClass.Account;
                    newItem.product_no       = productNo;
                    newItem.product_quantity = qantity;
                    db.shopping_cart.Add(newItem);
                    db.SaveChanges();
                }
                else
                {
                    item.product_quantity = qantity;
                    db.SaveChanges();
                }


                //加入購物車後回傳狀態給jquery執行提示視窗
                //TempData["Bought"] = "true";
                return(RedirectToAction("ProductDetail", new { productName = productName, productNo = productNo, showPrompt = "true" }));
            }
        }