public int CheckAuth(List <Role> roles) { //验证有没有权限访问 var attr = ServiceSession.Current.Method.GetCustomAttribute <BaseActionAttribute>(true); if (attr != null) { ISqlMapper mapper = Common.GetMapperFromSession(); string actionName = attr.Action; var servicelayer = ServiceSession.Current.Method.DeclaringType.GetCustomAttribute <ServiceLayer>(true); if (servicelayer != null) { string moduleName = servicelayer.Module; var modules = TableCacheHelper.GetDataFromCache <Module>(typeof(ModuleDao)); var actions = TableCacheHelper.GetDataFromCache <RiskMgr.Model.Action>(typeof(ActionDao)); Role_Module_ActionDao dao = new Role_Module_ActionDao(mapper); var module = modules.Find(t => t.Name == moduleName); var action = actions.Find(t => t.Name == actionName); if (module == null || action == null) { return(-1); } string actionID = action.ID; string moduleID = module.ID; Role_Module_ActionQueryForm query = new Role_Module_ActionQueryForm { ActionID = actionID, ModuleID = moduleID }; //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "action id:" + actionID + ";module id:" + moduleID }, SOAFramework.Library.CacheEnum.FormMonitor); var role_module_action = dao.Query(query); bool hasRight = false; foreach (var item in role_module_action) { if (roles != null && roles.Exists(t => t.ID == item.RoleID)) { hasRight = true; break; } } if (!hasRight) { return(4); } } } return(-1); }
private void button21_Click(object sender, EventArgs e) { Workflow wf = new Workflow(); //RoleBLL bll = new RoleBLL(); //bll.AddRole(new AddRoleServiceForm //{ // Name = "testrole", // ParentID = "2", // CanManageEmployeeAndAuth = true, // CanApply = true, // CanManageAsset = true, //}); //var roles = bll.Query(new RoleQueryForm { Name = "testrole" }); RoleBLL rolebll = new RoleBLL(); var roles = rolebll.Query(new RoleQueryForm { ID = "14" }).ToList <Role>(); Role_Module_ActionDao dao = new Role_Module_ActionDao(); string actionID = "3"; string moduleID = "4"; Role_Module_ActionQueryForm query = new Role_Module_ActionQueryForm { ActionID = actionID, ModuleID = moduleID }; var role_module_action = dao.Query(query); bool hasRight = false; foreach (var item in role_module_action) { if (roles != null && roles.Exists(t => t.ID == item.RoleID)) { hasRight = true; break; } } }