Example #1
0
        /// <summary>
        /// 数据初始化
        /// </summary>
        /// <param name="allModules"></param>
        /// <param name="IsSpa"></param>
        /// <returns>返回true表示需要进行初始化数据操作,返回false即数据库已经存在或不需要初始化数据</returns>
        public async override Task <bool> DataInit(object allModules, bool IsSpa)
        {
            bool rv = await Database.EnsureCreatedAsync();

            //判断是否存在初始数据
            bool emptydb = false;

            try
            {
                emptydb = Set <FrameworkUserBase>().Count() == 0 && Set <FrameworkUserRole>().Count() == 0 && Set <FrameworkMenu>().Count() == 0;
            }
            catch { }

            if (emptydb == true)
            {
                var AllModules = allModules as List <FrameworkModule>;
                var roles      = new FrameworkRole[]
                {
                    new FrameworkRole {
                        RoleCode = "001", RoleName = Program._localizer["Admin"]
                    }
                };
                var users = new FrameworkUserBase[]
                {
                    new FrameworkUserBase {
                        ITCode = "admin", Password = Utils.GetMD5String("000000"), IsValid = true, Name = Program._localizer["Admin"]
                    }
                };
                var userroles = new FrameworkUserRole[]
                {
                    new FrameworkUserRole {
                        User = users[0], Role = roles[0]
                    }
                };

                var adminRole = roles[0];
                if (Set <FrameworkMenu>().Any() == false)
                {
                    var systemManagement = GetFolderMenu(Program._localizer["SystemManagement"], new List <FrameworkRole> {
                        adminRole
                    }, null);
                    var logList = IsSpa ? GetMenu2(AllModules, "ActionLog", new List <FrameworkRole> {
                        adminRole
                    }, null, 1) : GetMenu(AllModules, "_Admin", "ActionLog", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 1);
                    var userList = IsSpa ? GetMenu2(AllModules, "FrameworkUser", new List <FrameworkRole> {
                        adminRole
                    }, null, 2) : GetMenu(AllModules, "_Admin", "FrameworkUser", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 2);
                    var roleList = IsSpa ? GetMenu2(AllModules, "FrameworkRole", new List <FrameworkRole> {
                        adminRole
                    }, null, 3) : GetMenu(AllModules, "_Admin", "FrameworkRole", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 3);
                    var groupList = IsSpa ? GetMenu2(AllModules, "FrameworkGroup", new List <FrameworkRole> {
                        adminRole
                    }, null, 4) : GetMenu(AllModules, "_Admin", "FrameworkGroup", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 4);
                    var menuList = IsSpa ? GetMenu2(AllModules, "FrameworkMenu", new List <FrameworkRole> {
                        adminRole
                    }, null, 5) : GetMenu(AllModules, "_Admin", "FrameworkMenu", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 5);
                    var dpList = IsSpa ? GetMenu2(AllModules, "DataPrivilege", new List <FrameworkRole> {
                        adminRole
                    }, null, 6) : GetMenu(AllModules, "_Admin", "DataPrivilege", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 6);
                    if (logList != null)
                    {
                        systemManagement.Children.AddRange(new FrameworkMenu[] { logList, userList, roleList, groupList, menuList, dpList });
                        Set <FrameworkMenu>().Add(systemManagement);
                    }

                    if (IsSpa == false)
                    {
                        var apifolder = GetFolderMenu("Api", new List <FrameworkRole> {
                            adminRole
                        }, null);
                        apifolder.ShowOnMenu   = false;
                        apifolder.DisplayOrder = 100;
                        var logList2 = GetMenu2(AllModules, "ActionLog", new List <FrameworkRole> {
                            adminRole
                        }, null, 1);
                        var userList2 = GetMenu2(AllModules, "FrameworkUser", new List <FrameworkRole> {
                            adminRole
                        }, null, 2);
                        var roleList2 = GetMenu2(AllModules, "FrameworkRole", new List <FrameworkRole> {
                            adminRole
                        }, null, 3);
                        var groupList2 = GetMenu2(AllModules, "FrameworkGroup", new List <FrameworkRole> {
                            adminRole
                        }, null, 4);
                        var menuList2 = GetMenu2(AllModules, "FrameworkMenu", new List <FrameworkRole> {
                            adminRole
                        }, null, 5);
                        var dpList2 = GetMenu2(AllModules, "DataPrivilege", new List <FrameworkRole> {
                            adminRole
                        }, null, 6);
                        var apis = new FrameworkMenu[] { logList2, userList2, roleList2, groupList2, menuList2, dpList2 };
                        apis.ToList().ForEach(x => { x.ShowOnMenu = false; x.PageName += $"({Program._localizer["BuildinApi"]})"; });
                        apifolder.Children.AddRange(apis);
                        Set <FrameworkMenu>().Add(apifolder);
                    }
                }
                Set <FrameworkRole>().AddRange(roles);
                Set <FrameworkUserBase>().AddRange(users);
                Set <FrameworkUserRole>().AddRange(userroles);
                await SaveChangesAsync();
            }
            return(rv);
        }
Example #2
0
        /// <summary>
        /// 数据初始化
        /// </summary>
        /// <param name="allModules"></param>
        /// <param name="IsSpa"></param>
        /// <returns>返回true表示需要进行初始化数据操作,返回false即数据库已经存在或不需要初始化数据</returns>
        public async override Task <bool> DataInit(object allModules, bool IsSpa)
        {
            bool rv = await Database.EnsureCreatedAsync();

            //判断是否存在初始数据
            bool emptydb = false;

            try
            {
                emptydb = Set <FrameworkUserBase>().Count() == 0 && Set <FrameworkUserRole>().Count() == 0 && Set <FrameworkMenu>().Count() == 0;
            }
            catch { }

            if (emptydb == true)
            {
                var AllModules = allModules as List <FrameworkModule>;
                var roles      = new FrameworkRole[]
                {
                    new FrameworkRole {
                        RoleCode = "001", RoleName = Program._localizer["Admin"]
                    }
                };
                var users = new FrameworkUserBase[]
                {
                    new FrameworkUserBase {
                        ITCode = "admin", Password = Utils.GetMD5String("000000"), IsValid = true, Name = Program._localizer["Admin"]
                    }
                };
                var userroles = new FrameworkUserRole[]
                {
                    new FrameworkUserRole {
                        User = users[0], Role = roles[0]
                    }
                };

                var adminRole = roles[0];
                if (Set <FrameworkMenu>().Any() == false)
                {
                    var systemManagement = GetFolderMenu("SystemManagement", new List <FrameworkRole> {
                        adminRole
                    }, null);
                    var logList = IsSpa ? GetMenu2(AllModules, "ActionLog", new List <FrameworkRole> {
                        adminRole
                    }, null, 1) : GetMenu(AllModules, "_Admin", "ActionLog", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 1);
                    var userList = IsSpa ? GetMenu2(AllModules, "FrameworkUser", new List <FrameworkRole> {
                        adminRole
                    }, null, 2) : GetMenu(AllModules, "_Admin", "FrameworkUser", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 2);
                    var roleList = IsSpa ? GetMenu2(AllModules, "FrameworkRole", new List <FrameworkRole> {
                        adminRole
                    }, null, 3) : GetMenu(AllModules, "_Admin", "FrameworkRole", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 3);
                    var groupList = IsSpa ? GetMenu2(AllModules, "FrameworkGroup", new List <FrameworkRole> {
                        adminRole
                    }, null, 4) : GetMenu(AllModules, "_Admin", "FrameworkGroup", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 4);
                    var menuList = IsSpa ? GetMenu2(AllModules, "FrameworkMenu", new List <FrameworkRole> {
                        adminRole
                    }, null, 5) : GetMenu(AllModules, "_Admin", "FrameworkMenu", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 5);
                    var dpList = IsSpa ? GetMenu2(AllModules, "DataPrivilege", new List <FrameworkRole> {
                        adminRole
                    }, null, 6) : GetMenu(AllModules, "_Admin", "DataPrivilege", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 6);
                    if (logList != null)
                    {
                        var menus = new FrameworkMenu[] { logList, userList, roleList, groupList, menuList, dpList };
                        foreach (var item in menus)
                        {
                            if (item != null)
                            {
                                systemManagement.Children.Add(item);
                            }
                        }
                        Set <FrameworkMenu>().Add(systemManagement);

                        if (IsSpa == false)
                        {
                            systemManagement.ICon = "layui-icon layui-icon-set";
                            logList.ICon          = "layui-icon layui-icon-form";
                            userList.ICon         = "layui-icon layui-icon-friends";
                            roleList.ICon         = "layui-icon layui-icon-user";
                            groupList.ICon        = "layui-icon layui-icon-group";
                            menuList.ICon         = "layui-icon layui-icon-menu-fill";
                            dpList.ICon           = "layui-icon layui-icon-auz";

                            var apifolder = GetFolderMenu("Api", new List <FrameworkRole> {
                                adminRole
                            }, null);
                            apifolder.ShowOnMenu   = false;
                            apifolder.DisplayOrder = 100;
                            var logList2 = GetMenu2(AllModules, "ActionLog", new List <FrameworkRole> {
                                adminRole
                            }, null, 1);
                            var userList2 = GetMenu2(AllModules, "FrameworkUser", new List <FrameworkRole> {
                                adminRole
                            }, null, 2);
                            var roleList2 = GetMenu2(AllModules, "FrameworkRole", new List <FrameworkRole> {
                                adminRole
                            }, null, 3);
                            var groupList2 = GetMenu2(AllModules, "FrameworkGroup", new List <FrameworkRole> {
                                adminRole
                            }, null, 4);
                            var menuList2 = GetMenu2(AllModules, "FrameworkMenu", new List <FrameworkRole> {
                                adminRole
                            }, null, 5);
                            var dpList2 = GetMenu2(AllModules, "DataPrivilege", new List <FrameworkRole> {
                                adminRole
                            }, null, 6);
                            var apis = new FrameworkMenu[] { logList2, userList2, roleList2, groupList2, menuList2, dpList2 };
                            //apis.ToList().ForEach(x => { x.ShowOnMenu = false;x.PageName += $"({Program._localizer["BuildinApi"]})"; });
                            foreach (var item in apis)
                            {
                                if (item != null)
                                {
                                    apifolder.Children.Add(item);
                                }
                            }
                            Set <FrameworkMenu>().Add(apifolder);
                        }
                        else
                        {
                            systemManagement.ICon = " _wtmicon _wtmicon-icon_shezhi";
                            logList.ICon          = " _wtmicon _wtmicon-chaxun";
                            userList.ICon         = " _wtmicon _wtmicon-zhanghaoquanxianguanli";
                            roleList.ICon         = " _wtmicon _wtmicon-quanxianshenpi";
                            groupList.ICon        = " _wtmicon _wtmicon-zuzhiqunzu";
                            menuList.ICon         = " _wtmicon _wtmicon--lumingpai";
                            dpList.ICon           = " _wtmicon _wtmicon-anquan";
                        }
                    }
                }
                Set <FrameworkRole>().AddRange(roles);
                Set <FrameworkUserBase>().AddRange(users);
                Set <FrameworkUserRole>().AddRange(userroles);
                await SaveChangesAsync();
            }
            return(rv);
        }
Example #3
0
        /// <summary>
        /// 数据初始化
        /// </summary>
        /// <param name="allModules"></param>
        /// <returns>返回true即数据新建完成,进入初始化操作,返回false即数据库已经存在</returns>
        public async virtual Task <bool> DataInit(object allModules)
        {
            if (await Database.EnsureCreatedAsync())
            {
                var AllModules = allModules as List <FrameworkModule>;
                foreach (var module in AllModules)
                {
                    module.CreateTime = DateTime.Now;
                    module.CreateBy   = "admin";
                    Set <FrameworkModule>().Add(module);
                }

                var roles = new FrameworkRole[]
                {
                    new FrameworkRole {
                        RoleCode = "001", RoleName = "超级管理员"
                    }
                };
                var users = new FrameworkUserBase[]
                {
                    new FrameworkUserBase {
                        ITCode = "admin", Password = Utils.GetMD5String("000000"), IsValid = true, Name = "超级管理员"
                    }
                };
                var userroles = new FrameworkUserRole[]
                {
                    new FrameworkUserRole {
                        User = users[0], Role = roles[0]
                    }
                };

                var adminRole = roles[0];
                if (Set <FrameworkMenu>().Any() == false)
                {
                    var systemManagement = GetFolderMenu("系统管理", new List <FrameworkRole> {
                        adminRole
                    }, null);
                    var logList = GetMenu(AllModules, "_Admin", "ActionLog", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 1);
                    var userList = GetMenu(AllModules, "_Admin", "FrameworkUser", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 2);
                    var roleList = GetMenu(AllModules, "_Admin", "FrameworkRole", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 3);
                    var groupList = GetMenu(AllModules, "_Admin", "FrameworkGroup", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 4);
                    var menuList = GetMenu(AllModules, "_Admin", "FrameworkMenu", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 5);
                    var dpList = GetMenu(AllModules, "_Admin", "DataPrivilege", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 6);
                    if (logList != null)
                    {
                        systemManagement.Children.AddRange(new FrameworkMenu[] { logList, userList, roleList, groupList, menuList, dpList });
                        Set <FrameworkMenu>().Add(systemManagement);
                    }
                }
                Set <FrameworkRole>().AddRange(roles);
                Set <FrameworkUserBase>().AddRange(users);
                Set <FrameworkUserRole>().AddRange(userroles);
                await SaveChangesAsync();

                return(true);
            }
            return(false);
        }
Example #4
0
        /// <summary>
        /// 数据初始化
        /// </summary>
        /// <param name="allModules"></param>
        /// <param name="IsSpa"></param>
        /// <returns>返回true表示需要进行初始化数据操作,返回false即数据库已经存在或不需要初始化数据</returns>
        public async virtual Task <bool> DataInit(object allModules, bool IsSpa)
        {
            bool rv = await Database.EnsureCreatedAsync();

            //判断是否存在初始数据
            bool emptydb = Set <FrameworkUserBase>().Count() == 0 && Set <FrameworkUserRole>().Count() == 0 && Set <FrameworkMenu>().Count() == 0;

            if (emptydb == true)
            {
                var AllModules = allModules as List <FrameworkModule>;
                var roles      = new FrameworkRole[]
                {
                    new FrameworkRole {
                        RoleCode = "001", RoleName = "超级管理员"
                    }
                };
                var users = new FrameworkUserBase[]
                {
                    new FrameworkUserBase {
                        ITCode = "admin", Password = Utils.GetMD5String("000000"), IsValid = true, Name = "超级管理员"
                    }
                };
                var userroles = new FrameworkUserRole[]
                {
                    new FrameworkUserRole {
                        User = users[0], Role = roles[0]
                    }
                };

                var adminRole = roles[0];
                if (Set <FrameworkMenu>().Any() == false)
                {
                    var systemManagement = GetFolderMenu("系统管理", new List <FrameworkRole> {
                        adminRole
                    }, null);
                    var logList = IsSpa ? GetMenu2(AllModules, "ActionLog", new List <FrameworkRole> {
                        adminRole
                    }, null, 1) : GetMenu(AllModules, "_Admin", "ActionLog", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 1);
                    var userList = IsSpa ? GetMenu2(AllModules, "FrameworkUser", new List <FrameworkRole> {
                        adminRole
                    }, null, 2) : GetMenu(AllModules, "_Admin", "FrameworkUser", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 2);
                    var roleList = IsSpa ? GetMenu2(AllModules, "FrameworkRole", new List <FrameworkRole> {
                        adminRole
                    }, null, 3) : GetMenu(AllModules, "_Admin", "FrameworkRole", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 3);
                    var groupList = IsSpa ? GetMenu2(AllModules, "FrameworkGroup", new List <FrameworkRole> {
                        adminRole
                    }, null, 4) : GetMenu(AllModules, "_Admin", "FrameworkGroup", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 4);
                    var menuList = IsSpa ? GetMenu2(AllModules, "FrameworkMenu", new List <FrameworkRole> {
                        adminRole
                    }, null, 5) : GetMenu(AllModules, "_Admin", "FrameworkMenu", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 5);
                    var dpList = IsSpa ? GetMenu2(AllModules, "DataPrivilege", new List <FrameworkRole> {
                        adminRole
                    }, null, 6) : GetMenu(AllModules, "_Admin", "DataPrivilege", "Index", new List <FrameworkRole> {
                        adminRole
                    }, null, 6);
                    if (logList != null)
                    {
                        systemManagement.Children.AddRange(new FrameworkMenu[] { logList, userList, roleList, groupList, menuList, dpList });
                        Set <FrameworkMenu>().Add(systemManagement);
                    }
                }
                Set <FrameworkRole>().AddRange(roles);
                Set <FrameworkUserBase>().AddRange(users);
                Set <FrameworkUserRole>().AddRange(userroles);
                await SaveChangesAsync();

                rv = false;
            }
            return(rv);
        }