Exemple #1
0
        public void InitializeMenu()
        {
            MenuService menuService = new MenuService();
            List <Menu> menuList    = new List <Menu>();

            menuList.Add(new Menu
            {
                ParentId = 0,
                Title    = "权限管理",
                Url      = "/action"
            });
            menuList.Add(new Menu
            {
                ParentId = 0,
                Title    = "系统设置",
                Url      = "/system"
            });
            menuList.Add(new Menu
            {
                ParentId = 0,
                Title    = "用户管理",
                Url      = "/user"
            });
            menuService.AddRange(menuList);
            List <Menu> childMenuList = new List <Menu>();
            int         systemId      = menuService.GetEntities(u => u.Title == "系统设置" && u.ParentId == 0).FirstOrDefault().Id;

            childMenuList.Add(new Menu
            {
                ParentId = systemId,
                Title    = "菜单管理",
                Url      = "/menu"
            });
            int menuId = menuService.GetEntities(u => u.Title == "用户管理" && u.ParentId == 0).FirstOrDefault().Id;

            childMenuList.Add(new Menu
            {
                ParentId = menuId,
                Title    = "用户管理",
                Url      = "/user"
            });
            int actionId = menuService.GetEntities(u => u.Title == "权限管理" && u.ParentId == 0).FirstOrDefault().Id;

            childMenuList.Add(new Menu
            {
                ParentId = actionId,
                Title    = "权限管理",
                Url      = "/action"
            });
            childMenuList.Add(new Menu
            {
                ParentId = actionId,
                Title    = "角色管理",
                Url      = "/role"
            });
            childMenuList.Add(new Menu
            {
                ParentId = actionId,
                Title    = "角色权限管理",
                Url      = "/roleaction"
            });
            childMenuList.Add(new Menu
            {
                ParentId = actionId,
                Title    = "角色用户管理",
                Url      = "/roleuser"
            });
            childMenuList.Add(new Menu
            {
                ParentId = actionId,
                Title    = "用户角色管理",
                Url      = "/userrole"
            });
            menuService.AddRange(childMenuList);
        }