public ActionResult AddRole(string RoleName, string Dept, string System, string Remark) { this.Internationalization(); try { TugDataEntities db = new TugDataEntities(); { System.Linq.Expressions.Expression<Func<Role, bool>> exp = u => u.RoleName == RoleName; Role tmprole = db.Role.Where(exp).FirstOrDefault(); if (tmprole != null) { //Response.StatusCode = 404; //return Json(new { message = RoleName + "已存在!" }); throw new Exception(RoleName + "已存在!"); } TugDataModel.Role role = new Role(); role.RoleName = RoleName; role.Dept = Dept; role.System = System; role.Remark = Remark; role.OwnerID = -1; role.CreateDate = role.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ;//.ToString("yyyy-MM-dd"); role.UserID = Session.GetDataFromSession<int>("userid"); role.UserDefinedCol1 = ""; role.UserDefinedCol2 = ""; role.UserDefinedCol3 = ""; role.UserDefinedCol4 = ""; //if (Request.Form["UserDefinedCol5"].Trim() != "") // role.UserDefinedCol5 = Convert.ToDouble(Request.Form["UserDefinedCol5"].Trim()); //if (Request.Form["UserDefinedCol6"].Trim() != "") // role.UserDefinedCol6 = Util.toint(Request.Form["UserDefinedCol6"].Trim()); //if (Request.Form["UserDefinedCol7"].Trim() != "") // role.UserDefinedCol7 = Util.toint(Request.Form["UserDefinedCol7"].Trim()); //if (Request.Form["UserDefinedCol8"].Trim() != "") // role.UserDefinedCol8 = Util.toint(Request.Form["UserDefinedCol8"].Trim()); role.UserDefinedCol9 = ""; role.UserDefinedCol10 = ""; role = db.Role.Add(role); db.SaveChanges(); var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE }; return Json(ret); } } catch (Exception ex) { throw ex; } }
public ActionResult AddEditRole() { this.Internationalization(); #region Add if (Request.Form["oper"].Equals("add")) { try { TugDataEntities db = new TugDataEntities(); { TugDataModel.Role userRole = new Role(); userRole.RoleName = Request.Form["RoleName"]; userRole.Dept = Request.Form["Dept"]; userRole.System = Request.Form["System"]; userRole.Remark = Request.Form["Remark"]; userRole.OwnerID = -1; userRole.CreateDate = userRole.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; 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.Role.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"]); Role userRole = db.Role.Where(u => u.IDX == idx).FirstOrDefault(); if (userRole == null) { return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE }); } else { userRole.RoleName = Request.Form["RoleName"]; userRole.Dept = Request.Form["Dept"]; userRole.System = Request.Form["System"]; userRole.Remark = Request.Form["Remark"]; userRole.OwnerID = -1; userRole.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ; 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 }); }