public static List <SMS.Model.Permission> GetRolePermissions(string role) { StringBuilder strSql = new StringBuilder(); strSql.Append("select p.* from plat_RolePermission as rp left join plat_Permission as p on rp.PermissionCode=p.PermissionCode and rp.RoleID=@RoleID"); strSql.Append(" where RoleID=@RoleID"); MySqlParameter[] parameters = { new MySqlParameter("@RoleID", MySqlDbType.VarChar, 32) }; parameters[0].Value = role; DataSet ds = DBUtility.MySqlHelper.Query(strSql.ToString(), parameters); List <SMS.Model.Permission> list = new List <SMS.Model.Permission>(); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow row in ds.Tables[0].Rows) { string menuCode = row["MenuCode"].ToString(); SMS.Model.PermissionAction action = DataRowToModel(row); if (list.FirstOrDefault <SMS.Model.Permission>(c => c.MenuID == menuCode) != null) { SMS.Model.Permission permission = list.FirstOrDefault <SMS.Model.Permission>(c => c.MenuID == menuCode); permission.Actions.Add(action); } else { SMS.Model.Permission permission = new SMS.Model.Permission(); permission.MenuID = menuCode; permission.Actions = new List <SMS.Model.PermissionAction>(); permission.Actions.Add(action); list.Add(permission); } } } return(list); }
static SMS.Model.PermissionAction DataRowToModel(DataRow row) { SMS.Model.PermissionAction model = new SMS.Model.PermissionAction(); if (row != null) { if (row["PermissionCode"] != null) { model.PermissionCode = row["PermissionCode"].ToString(); } if (row["PermissionTitle"] != null) { model.PermissionTitle = row["PermissionTitle"].ToString(); } if (row["OperateType"] != null && row["OperateType"].ToString() != "") { model.OperateType = (SMS.Model.PermissionOperateType)((ushort)row["OperateType"]); } if (row["OperateContent"] != null) { model.Content = row["OperateContent"].ToString(); } } return(model); }