public ActionResult MaterialEdit(int id, int mallid) { //if (!UserInfo.CurUser.HasRight("系统管理-用户管理")) return Redirect("~/content/AccessDeny.htm"); var r = (from o in db.Materials where o.Id == id select o).FirstOrDefault(); if (r == null) { r = new Material(); } return View(r); }
public ActionResult MaterialEdit(int id, string departmentid,string name, int catalogId, string spec, string remark, FormCollection collection) { if (!UserInfo.CurUser.HasRight("系统管理-物资名称维护")) return Redirect("~/content/AccessDeny.htm"); Material r = (from o in db.Materials where o.Id == id select o).FirstOrDefault(); if (r == null) { r = new Material { MallId = mallid }; db.Materials.Add(r); } if (name.Length == 0) { ModelState.AddModelError("Name", "名称不能为空"); } int departmentId; if(!int.TryParse(departmentid,out departmentId)) { ModelState.AddModelError("DepartmentId","部门不能为空"); } r.Name = name; r.CatalogId = catalogId; r.Spec = spec; r.Remark = remark; r.DepartmentId = departmentId; if (ModelState.IsValid == false) { return View(r); } else { db.SaveChanges(); if (id == 0) { return Redirect("../MaterialView/" + r.Id); } else { return Redirect("~/content/close.htm"); } } }