Esempio n. 1
0
        public ActionResult Edit(int id)
        {
            Product s = db.Products.Find(id);
            if(s==null)
            {
                s = new Product();
            }

            if (!UserInfo.CurUser.HasRight("业务管理-产品修改")) return Redirect("~/content/AccessDeny.htm");
            return View(s);
        }
Esempio n. 2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            if (!UserInfo.CurUser.HasRight("业务管理-产品修改")) return Redirect("~/content/AccessDeny.htm");
            Product s = db.Products.Find(id);
            if(s==null)
            {
                s = new Product();
                db.Products.Add(s);
            }
            //collection.Remove("");
            TryUpdateModel(s, "", new  string[]{}, new string[] {"PicId"} ,collection);
            if(s.BoxNumber==0)
            {
                ModelState.AddModelError("BoxNumber", "Number of box can't be zero");
            }
            if(s.SupplierId<=0)
            {
                ModelState.AddModelError("SupplierId","Please select a supplier");
            }
            if (ModelState.IsValid)
            {
                    db.SaveChanges();
                    if(id==0)
                    {
                        BLL.Utilities.AddLogAndSave(s.Id, Product.LogClass, "创建", "");

                    }
                    else
                    {
                        BLL.Utilities.AddLogAndSave(s.Id, Product.LogClass, "修改", "");
                    }
                return Redirect("../View/" + s.Id);
            }

            return View(s);
        }