zoukankan      html  css  js  c++  java
  • EF获取菜单权限

    Model类

        public class MenuModel    

    {         public int Id { get; set; }        

         public string Title { get; set; }        

         public string Url { get; set; }        

         public string Icon { get; set; }        

         public DateTime CreateDate { get; set; }        

         public MenuModel Parent { get; set; }        

         public int SortId { get; set; }        

         public bool IsDisabled { get; set; }        

         public int? ParentId { get; set; }        

         public string Buttoms { get; set; }

            public virtual List<MenuModel> Childs { get; set; }    

    }

    //方法

    //获取所有菜单权限
            public static List<Model.MenuModel> GetUserMenu()
            {
                using (var db = new MLContext())
                {
                    var list = new List<Model.MenuModel>();
                    var menus = db.SYS_Menu.Where(m => m.IsDisabled == false).OrderBy(m => m.Id).ToList();
                    if (menus == null) return null;
                    foreach (var poco in menus.Where(m => !m.ParentId.HasValue).OrderBy(m => m.Id))
                    {
                        var model = ConvertHelper.ToMenuModel(poco);  //父级
                        list.Add(model);
                        var childs = menus.Where(m => m.ParentId == poco.Id).OrderBy(m => m.Id).ToList();
                        if (childs == null || childs.Count == 0) continue;
                        model.Childs = new List<Model.MenuModel>();
                        foreach (var cpoco in childs)
                        {
                            var child = ConvertHelper.ToMenuModel(cpoco);  //子级
                            child.Parent = model;
                            model.Childs.Add(child);
                        }
                    }
                    return list;
                }
            }

  • 相关阅读:
    详细解释ISupportInitialize接口
    微软发布了VS2005 IDE增强工具
    Oracle中无法解析TNS的陷阱
    Oracle临时表空间为何暴涨?
    欧洲游回来
    树比较的一个另类方法
    控件的Archor属性没有作用,是.Net的BUG?
    Oracle中取字段唯一值的一个sql语句的写法
    Qt程序的翻译
    Qt程序运行到Symbian手机上
  • 原文地址:https://www.cnblogs.com/recent/p/3792262.html
Copyright © 2011-2022 走看看