Exemplo n.º 1
0
        /// <summary>
        /// 根据用户id获取角色菜单
        /// </summary>
        /// <returns></returns>
        public List <SysMenuModel> GetRoleMenuByUserId(string userid)
        {
            List <SysMenuModel> result = new List <SysMenuModel>();

            DataTable menus = menu_dal.GetRoleMenuByUserId(userid);

            if (menus.Rows.Count == 0)
            {
                return(result);
            }


            foreach (DataRow item in menus.Rows)
            {
                var tmp = result.Find(m => m.mid == Convert.ToInt32(item["mPID"]));
                if (tmp == null)
                {
                    tmp = new SysMenuModel()
                    {
                        mid      = Convert.ToInt32(item["mPID"]),
                        menuName = item["menuName_p"].ToString(),
                        menuIco  = item["menuIco_p"].ToString()
                    };
                    tmp.cmList.Add(new SysMenuModel()
                    {
                        mid      = Convert.ToInt32(item["mid"]),
                        menuName = item["menuName"].ToString(),
                        menuIco  = item["menuIco"].ToString(),
                        menuUrl  = item["menuUrl"].ToString(),
                        mPID     = Convert.ToInt32(item["mPID"]),
                        isDel    = Convert.ToBoolean(item["isDel"]),
                        mSort    = Convert.ToInt32(item["mSort"]),
                        cmList   = new List <SysMenuModel>()
                    });
                    result.Add(tmp);
                }
                else
                {
                    tmp.cmList.Add(new SysMenuModel()
                    {
                        mid      = Convert.ToInt32(item["mid"]),
                        menuName = item["menuName"].ToString(),
                        menuIco  = item["menuIco"].ToString(),
                        menuUrl  = item["menuUrl"].ToString(),
                        mPID     = Convert.ToInt32(item["mPID"]),
                        isDel    = Convert.ToBoolean(item["isDel"]),
                        mSort    = Convert.ToInt32(item["mSort"]),
                        cmList   = new List <SysMenuModel>()
                    });
                }
            }
            return(result);
        }