示例#1
0
        /// <summary>
        /// 创建测试用户
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static async Task InitAdminUsers(this IServiceProvider app)
        {
            using var s = app.CreateScope();
            var roleRepository = s.ServiceProvider.Resolve_ <IRoleRepository>();
            var _permission    = s.ServiceProvider.Resolve_ <IPermissionService>();

            var role = roleRepository.QueryOne(x => x.Id == admin_role_uid);

            if (role == null)
            {
                var admin_role = new RoleEntity()
                {
                    NodeName        = "超级管理员",
                    RoleDescription = "具有所有权限的超级管理员"
                };

                admin_role.AsFirstLevel().InitEntity();
                admin_role.SetId(admin_role_uid);
                admin_role.PermissionJson = _permission.AllPermissions().ToJson();

                await roleRepository.InsertAsync(admin_role);
            }
            else
            {
                role.PermissionJson = _permission.AllPermissions().ToJson();
                await roleRepository.UpdateAsync(role);
            }

            await roleRepository.SetUserRoles(admin_uid, new[] { admin_role_uid });
        }
示例#2
0
        public void CreateAdminRole()
        {
            var db = this._repo.Database;

            var role_set = db.Set <RoleEntity>();

            role_set.RemoveRange(role_set.Where(x => x.UID == admin_role_uid));
            db.SaveChanges();

            var admin_role = new RoleEntity()
            {
                NodeName        = "超级管理员",
                RoleDescription = "具有所有权限的超级管理员"
            };

            admin_role.AsFirstLevel().InitSelf("role");
            admin_role.UID            = admin_role_uid;
            admin_role.PermissionJson = this._permission.AllPermissions().ToJson();

            role_set.Add(admin_role);

            db.SaveChanges();
        }