public ActionResult AddRoleModule(List<int> data, int roleId) { this.Internationalization(); TugDataEntities db = new TugDataEntities(); foreach (int id in data) { System.Linq.Expressions.Expression<Func<RoleModule, bool>> exp = u => u.ModuleID == id && u.RoleID == roleId; RoleModule tmpUserModule = db.RoleModule.Where(exp).FirstOrDefault(); if (tmpUserModule != null) continue; //判断该模块是否已存在 RoleModule roleModule = new RoleModule(); roleModule.ModuleID = id; roleModule.RoleID = roleId; roleModule.IsAdmin = "否"; roleModule.OwnerID = -1; roleModule.CreateDate = roleModule.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); roleModule.UserID = Session.GetDataFromSession<int>("userid"); roleModule.System = "Role"; roleModule.UserDefinedCol1 = Request.Form["UserDefinedCol1"]; roleModule.UserDefinedCol2 = Request.Form["UserDefinedCol2"]; roleModule.UserDefinedCol3 = Request.Form["UserDefinedCol3"]; roleModule.UserDefinedCol4 = Request.Form["UserDefinedCol4"]; if (Request.Form["UserDefinedCol5"] != "") roleModule.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); if (Request.Form["UserDefinedCol6"] != "") roleModule.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); if (Request.Form["UserDefinedCol7"] != "") roleModule.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); if (Request.Form["UserDefinedCol8"] != "") roleModule.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); roleModule.UserDefinedCol9 = Request.Form["UserDefinedCol9"]; roleModule.UserDefinedCol10 = Request.Form["UserDefinedCol10"]; roleModule = db.RoleModule.Add(roleModule); db.SaveChanges(); } return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }); }
public ActionResult AddEditRowModule(int rolId) { //this.Internationalization(); #region Add if (Request.Form["oper"].Equals("add")) { try { TugDataEntities db = new TugDataEntities(); { TugDataModel.RoleModule userRole = new RoleModule(); userRole.RoleID = rolId; userRole.ModuleID = Util.toint(Request.Form["ModuleID"]); userRole.IsAdmin = Request.Form["IsAdmin"]; userRole.System = "Role"; userRole.CreateDate = userRole.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; userRole.OwnerID = -1; userRole.UserID = Session.GetDataFromSession<int>("userid"); userRole.UserDefinedCol1 = Request.Form["UserDefinedCol1"]; userRole.UserDefinedCol2 = Request.Form["UserDefinedCol2"]; userRole.UserDefinedCol3 = Request.Form["UserDefinedCol3"]; userRole.UserDefinedCol4 = Request.Form["UserDefinedCol4"]; if (Request.Form["UserDefinedCol5"] != "") userRole.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); if (Request.Form["UserDefinedCol6"] != "") userRole.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); if (Request.Form["UserDefinedCol7"] != "") userRole.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); if (Request.Form["UserDefinedCol8"] != "") userRole.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); userRole.UserDefinedCol9 = Request.Form["UserDefinedCol9"]; userRole.UserDefinedCol10 = Request.Form["UserDefinedCol10"]; userRole = db.RoleModule.Add(userRole); db.SaveChanges(); var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; //Response.Write(@Resources.Common.SUCCESS_MESSAGE); return Json(ret); } } catch (Exception) { var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }; //Response.Write(@Resources.Common.EXCEPTION_MESSAGE); return Json(ret); } } #endregion Add #region Edit if (Request.Form["oper"].Equals("edit")) { try { TugDataEntities db = new TugDataEntities(); int idx = Util.toint(Request.Form["IDX"]); RoleModule userRole = db.RoleModule.Where(u => u.IDX == idx).FirstOrDefault(); if (userRole == null) { return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); } else { userRole.RoleID = rolId; userRole.ModuleID = Util.toint(Request.Form["ModuleID"]); userRole.IsAdmin = Request.Form["IsAdmin"]; userRole.System = "Role"; userRole.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; userRole.OwnerID = -1; userRole.UserID = Session.GetDataFromSession<int>("userid"); userRole.UserDefinedCol1 = Request.Form["UserDefinedCol1"]; userRole.UserDefinedCol2 = Request.Form["UserDefinedCol2"]; userRole.UserDefinedCol3 = Request.Form["UserDefinedCol3"]; userRole.UserDefinedCol4 = Request.Form["UserDefinedCol4"]; if (Request.Form["UserDefinedCol5"] != "") userRole.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"]); if (Request.Form["UserDefinedCol6"] != "") userRole.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"]); if (Request.Form["UserDefinedCol7"] != "") userRole.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"]); if (Request.Form["UserDefinedCol8"] != "") userRole.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"]); userRole.UserDefinedCol9 = Request.Form["UserDefinedCol9"]; userRole.UserDefinedCol10 = Request.Form["UserDefinedCol10"]; db.Entry(userRole).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }); } } catch (Exception exp) { return Json(new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE }); } } #endregion Edit return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); }