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;
                }
            }

  • 相关阅读:
    TLE: poj 1011 Sticks
    UVa 116 Unidirectional TSP
    csuoj 1215 稳定排序
    UVa 103 Stacking Boxes
    UVa 147 Dollars
    UVa 111 History Grading
    怎么在ASP.NET 2.0中使用Membership
    asp.net中如何删除cookie?
    ASP.NET中的HTTP模块和处理程序[收藏]
    NET开发中的一些小技巧
  • 原文地址:https://www.cnblogs.com/recent/p/3792262.html
Copyright © 2011-2022 走看看