コード例 #1
0
        public ActionResult Create([Bind(Include = "ID,Name,Categories,Quantity,Price,Picture,Description")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Categories = new SelectList(db.Categories, "ID", "CategoriesName", product.Categories);
            return(View(product));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "ID,LoginId,Password,FirstName,LastName,Address,Gender,Phonenumber,UserRole")] tblUser tblUser)
        {
            if (ModelState.IsValid)
            {
                db.tblUsers.Add(tblUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserRole = new SelectList(db.tblRoles, "ID", "UserRole", tblUser.UserRole);
            return(View(tblUser));
        }
コード例 #3
0
        public ActionResult AddItemsToCart(int productid)
        {
            using (RHASTOREEntities db = new RHASTOREEntities())
            {
                if (User.Identity.Name == "")
                {
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    var  currentuser_id = Convert.ToInt32(User.Identity.Name);//this is actually the unique user id,the name is misleading
                    var  product_id     = productid;
                    var  quantity       = 1;
                    Cart c = new Cart();

                    c.userid    = currentuser_id;
                    c.ProductId = product_id;
                    c.Quantity  = quantity;
                    db.Carts.Add(c);
                    db.SaveChanges();
                }


                return(RedirectToAction("Index"));
            }
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Cart product = db.Carts.Find(id);

            db.Carts.Remove(product);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }