public static void Initialize(AppPlatContext context)
        {
            context.Database.EnsureCreated();

            // 已经初始化
            if (context.Users.Any())
            {
                return;
            }

            GetConfigs().ForEach(c => context.Configs.Add(c));
            GetDepts().ForEach(d => context.Depts.Add(d));
            GetUsers().ForEach(u => context.Users.Add(u));
            GetRoles().ForEach(r => context.Roles.Add(r));
            GetPowers().ForEach(p => context.Powers.Add(p));
            GetTitles().ForEach(t => context.Titles.Add(t));
            context.SaveChanges();

            // 添加菜单时需要指定ViewPower,所以上面需要先保存到数据库
            GetMenus(context).ForEach(m => context.Menus.Add(m));
            context.SaveChanges();
        }
        private static List <Menu> GetMenus(AppPlatContext context)
        {
            var menus = new List <Menu> {
                new Menu
                {
                    Name      = "系统管理",
                    SortIndex = 10,
                    Remark    = "顶级菜单",
                    ImageUrl  = "~/res/icon/cog.png",
                    Children  = new List <Menu> {
                        new Menu
                        {
                            Name        = "用户管理",
                            SortIndex   = 10,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/UserList",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreUserView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "职称管理",
                            SortIndex   = 20,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Title",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreTitleView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "职称用户管理",
                            SortIndex   = 30,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/TitleUser",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreTitleUserView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "部门管理",
                            SortIndex   = 40,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Dept",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreDeptView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "部门用户管理",
                            SortIndex   = 50,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/DeptUser",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreDeptUserView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "角色管理",
                            SortIndex   = 60,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Role",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreRoleView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "角色用户管理",
                            SortIndex   = 70,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/RoleUser",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreRoleUserView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "权限管理",
                            SortIndex   = 80,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Power",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CorePowerView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "角色权限管理",
                            SortIndex   = 90,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/RolePower",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreRolePowerView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "菜单管理",
                            SortIndex   = 100,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Menu",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreMenuView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "在线统计",
                            SortIndex   = 110,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Online",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreOnlineView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "系统配置",
                            SortIndex   = 120,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Config",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreConfigView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "修改密码",
                            SortIndex   = 130,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/ChangePassword",
                            ImageUrl    = "~/res/icon/tag_blue.png"
                        }
                    }
                },
                new Menu
                {
                    Name      = "测试菜单",
                    SortIndex = 20,
                    Remark    = "顶级菜单",
                    ImageUrl  = "~/res/icon/folder.png",
                    Children  = new List <Menu> {
                        new Menu {
                            Name      = "测试目录1",
                            SortIndex = 10,
                            Remark    = "二级菜单",
                            ImageUrl  = "~/res/icon/folder.png",
                            Children  = new List <Menu> {
                                new Menu
                                {
                                    Name        = "测试页面1",
                                    SortIndex   = 10,
                                    Remark      = "三级菜单",
                                    NavigateUrl = "~/Test/Test1",
                                    ImageUrl    = "~/res/icon/page.png",
                                    ViewPower   = context.Powers.Where(p => p.Name == "TestPage1View").FirstOrDefault <Power>()
                                }
                            }
                        },
                        new Menu
                        {
                            Name        = "测试页面2",
                            SortIndex   = 20,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Test/Test2",
                            ImageUrl    = "~/res/icon/page.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "TestPage2View").FirstOrDefault <Power>()
                        }
                    }
                }
            };

            return(menus);
        }