public static void Initialize(ParkAdminContext 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();

            GetRolePowers(context).ForEach(rp => context.RolePowers.Add(rp));
            GetRoleUsers(context).ForEach(ru => context.RoleUsers.Add(ru));
            context.SaveChanges();

            GetMenus(context).ForEach(m => context.Menus.Add(m));
            context.SaveChanges();
        }
        private static List <RoleUser> GetRoleUsers(ParkAdminContext db)
        {
            var rus = new List <RoleUser>()
            {
                new RoleUser()
                {
                    UserID = db.Users.FirstOrDefault(p => p.Name == "park").ID,
                    RoleID = db.Roles.FirstOrDefault(p => p.Name == "停车场管理员").ID,
                },
                new RoleUser()
                {
                    UserID = db.Users.FirstOrDefault(p => p.Name == "car").ID,
                    RoleID = db.Roles.FirstOrDefault(p => p.Name == "业务管理员").ID,
                }
            };

            return(rus);
        }
        private static List <RolePower> GetRolePowers(ParkAdminContext db)
        {
            var rps = new List <RolePower>()
            {
                new RolePower()
                {
                    PowerID = db.Powers.FirstOrDefault(p => p.Name == "ParkPower").ID,
                    RoleID  = db.Roles.FirstOrDefault(p => p.Name == "停车场管理员").ID,
                },
                new RolePower()
                {
                    PowerID = db.Powers.FirstOrDefault(p => p.Name == "CarAndOwnerPower").ID,
                    RoleID  = db.Roles.FirstOrDefault(p => p.Name == "停车场管理员").ID,
                },
                new RolePower()
                {
                    PowerID = db.Powers.FirstOrDefault(p => p.Name == "CarAndOwnerPower").ID,
                    RoleID  = db.Roles.FirstOrDefault(p => p.Name == "业务管理员").ID,
                }
            };

            return(rps);
        }
        private static List <Menu> GetMenus(ParkAdminContext context)
        {
            var menus = new List <Menu> {
                new Menu
                {
                    Name      = "车与车主",
                    SortIndex = 10,
                    Children  = new List <Menu> {
                        new Menu
                        {
                            Name        = "车主管理",
                            SortIndex   = 11,
                            NavigateUrl = "~/CarAndOwner/CarOwnerList",
                            ViewPower   = context.Powers.Where(p => p.Name == "CarAndOwnerPower").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "车辆管理",
                            SortIndex   = 12,
                            NavigateUrl = "~/CarAndOwner/CarList",
                            ViewPower   = context.Powers.Where(p => p.Name == "CarAndOwnerPower").FirstOrDefault <Power>()
                        },
                        new Menu {
                            Name        = "停车记录",
                            SortIndex   = 13,
                            NavigateUrl = "~/CarAndOwner/ParkRecordList",
                            ViewPower   = context.Powers.Where(p => p.Name == "CarAndOwnerPower").FirstOrDefault <Power>()
                        },
                        new Menu {
                            Name        = "交易记录",
                            SortIndex   = 14,
                            NavigateUrl = "~/CarAndOwner/TransactionRecordList",
                            ViewPower   = context.Powers.Where(p => p.Name == "CarAndOwnerPower").FirstOrDefault <Power>()
                        },
                    }
                },
                new Menu
                {
                    Name      = "停车场",
                    SortIndex = 20,
                    Children  = new List <Menu> {
                        new Menu
                        {
                            Name        = "停车区管理",
                            SortIndex   = 21,
                            NavigateUrl = "~/Parking/ParkAreaList",
                            ViewPower   = context.Powers.Where(p => p.Name == "ParkPower").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "停车位管理",
                            SortIndex   = 12,
                            NavigateUrl = "~/Parking/ParkingSpaceList",
                            ViewPower   = context.Powers.Where(p => p.Name == "ParkPower").FirstOrDefault <Power>()
                        },
                    }
                },
                new Menu
                {
                    Name        = "业务模拟",
                    SortIndex   = 30,
                    NavigateUrl = "~/Overview/Simulate",
                    ViewPower   = context.Powers.Where(p => p.Name == "ParkPower").FirstOrDefault <Power>()
                },
                new Menu
                {
                    Name        = "统计图表",
                    SortIndex   = 40,
                    NavigateUrl = "~/Overview/Charts",
                },
                new Menu {
                    Name        = "数据库管理",
                    SortIndex   = 50,
                    NavigateUrl = "~/Overview/DatabaseManage",
                },
                new Menu
                {
                    Name      = "系统管理",
                    SortIndex = 100,
                    Remark    = "顶级菜单",
                    ImageUrl  = "~/res/icon/cog.png",
                    Children  = new List <Menu> {
                        new Menu
                        {
                            Name        = "用户管理",
                            SortIndex   = 101,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/UserList",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreUserView").FirstOrDefault <Power>()
                        },
                        //new Menu
                        //{
                        //    Name = "职称管理",
                        //    SortIndex = 102,
                        //    Remark = "二级菜单",
                        //    NavigateUrl = "~/Admin/Title",
                        //    ImageUrl = "~/res/icon/tag_blue.png",
                        //    ViewPower = context.Powers.Where(p => p.Name == "CoreTitleView").FirstOrDefault<Power>()
                        //},
                        //new Menu
                        //{
                        //    Name = "职称用户管理",
                        //    SortIndex = 103,
                        //    Remark = "二级菜单",
                        //    NavigateUrl = "~/Admin/TitleUser",
                        //    ImageUrl = "~/res/icon/tag_blue.png",
                        //    ViewPower = context.Powers.Where(p => p.Name == "CoreTitleUserView").FirstOrDefault<Power>()
                        //},
                        //new Menu
                        //{
                        //    Name = "部门管理",
                        //    SortIndex = 104,
                        //    Remark = "二级菜单",
                        //    NavigateUrl = "~/Admin/Dept",
                        //    ImageUrl = "~/res/icon/tag_blue.png",
                        //    ViewPower = context.Powers.Where(p => p.Name == "CoreDeptView").FirstOrDefault<Power>()
                        //},
                        //new Menu
                        //{
                        //    Name = "部门用户管理",
                        //    SortIndex = 105,
                        //    Remark = "二级菜单",
                        //    NavigateUrl = "~/Admin/DeptUser",
                        //    ImageUrl = "~/res/icon/tag_blue.png",
                        //    ViewPower = context.Powers.Where(p => p.Name == "CoreDeptUserView").FirstOrDefault<Power>()
                        //},
                        new Menu
                        {
                            Name        = "角色管理",
                            SortIndex   = 106,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Role",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreRoleView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "角色用户管理",
                            SortIndex   = 107,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/RoleUser",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreRoleUserView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "权限管理",
                            SortIndex   = 108,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Power",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CorePowerView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "角色权限管理",
                            SortIndex   = 109,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/RolePower",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreRolePowerView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "菜单管理",
                            SortIndex   = 110,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Menu",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreMenuView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "在线统计",
                            SortIndex   = 111,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Online",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreOnlineView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "系统配置",
                            SortIndex   = 112,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/Config",
                            ImageUrl    = "~/res/icon/tag_blue.png",
                            ViewPower   = context.Powers.Where(p => p.Name == "CoreConfigView").FirstOrDefault <Power>()
                        },
                        new Menu
                        {
                            Name        = "修改密码",
                            SortIndex   = 113,
                            Remark      = "二级菜单",
                            NavigateUrl = "~/Admin/ChangePassword",
                            ImageUrl    = "~/res/icon/tag_blue.png"
                        }
                    }
                },
            };

            return(menus);
        }