Exemplo n.º 1
0
        /// <summary>
        /// 获取用户的权限
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public static List <SMS.Model.Permission> GetAccountPermissions(List <string> roles)
        {
            List <SMS.Model.Permission> accountPermission = new List <SMS.Model.Permission>();

            foreach (var v in roles)
            {
                List <SMS.Model.Permission> list = DAL.Permission.GetRolePermissions(v);
                foreach (var p in list)
                {
                    if (accountPermission.FirstOrDefault <SMS.Model.Permission>(c => c.MenuID == p.MenuID) != null)
                    {
                        SMS.Model.Permission model = accountPermission.FirstOrDefault <SMS.Model.Permission>(c => c.MenuID == p.MenuID);
                        model.Actions = model.Actions.Union(p.Actions).ToList <SMS.Model.PermissionAction>();
                    }
                    else
                    {
                        accountPermission.Add(p);
                    }
                }
            }
            return(accountPermission);
        }
Exemplo n.º 2
0
        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);
        }