public ActionResult Role_Permission_Edit() { bool success = false; string roleGuid = Request.Form["RoleGuid"]; string permissions = Request.Form[2].ToString(); string[] permission = permissions.Split(','); using (NHibernate.ITransaction tran = NhSession.BeginTransaction()) { try { Guid RoleGuid = new Guid(roleGuid); Model.D_Role_Model role = NhSession.Get <Model.D_Role_Model>(RoleGuid); ICriteria ic = NhSession.CreateCriteria(typeof(Model.D_Role_Permissions_Model)); ic.Add(Restrictions.Eq("RoleGuid", role)); IList <Model.D_Role_Permissions_Model> rolePermissionList = ic.List <Model.D_Role_Permissions_Model>(); foreach (var item in rolePermissionList) { item.DataStatus = true; item.ModifyDateTime = DateTime.Now; item.ModifyUserGuid = UserView.UserGuid; item.ModifyUserName = UserView.UserName; NhSession.Update(item); } foreach (var item in permission) { Model.D_Role_Permissions_Model rolePermission = rolePermissionList.SingleOrDefault(m => m.Permissions == item); if (rolePermission == null) { rolePermission = new Model.D_Role_Permissions_Model(); rolePermission.CreateDateTime = DateTime.Now; rolePermission.CreateUserGuid = UserView.UserGuid; rolePermission.CreateUserName = UserView.UserName; rolePermission.RoleGuid = role; rolePermission.Permissions = item; } rolePermission.DataStatus = false; rolePermission.ModifyDateTime = DateTime.Now; rolePermission.ModifyUserGuid = UserView.UserGuid; rolePermission.ModifyUserName = UserView.UserName; NhSession.SaveOrUpdate(rolePermission); } tran.Commit(); return(Json(new { success = success, message = "成功" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = success, message = ex.Message })); } finally { if (!tran.WasCommitted && !tran.WasRolledBack) { tran.Rollback(); } } } }