Example #1
0
        /// <summary>
        /// 初始化种子数据,添加超级管理组和超级管理员,默认账号:admin 111111
        /// </summary>
        /// <returns></returns>
        public async Task InitSeedDataAsync()
        {
            var defaultRole = await _sysRoleRepository.GetModelAsync(p => p.IsSuper);

            if (defaultRole != null)
            {
                throw new Exception("默认管理员组已存在");
            }

            var defaultUser = await _sysUserRepository.GetCountAsync(p => p.UserId > 0);

            if (defaultUser != 0)
            {
                throw new Exception("已有用户");
            }

            using (var uow = _fsq.CreateUnitOfWork())
            {
                _sysRoleRepository.UnitOfWork = uow;
                _sysUserRepository.UnitOfWork = uow;
                var userRoleRepo = uow.GetRepository <SysRoleUser>();
                userRoleRepo.UnitOfWork = uow;

                var role = new SysRole()
                {
                    IsSuper         = true,
                    RoleName        = "超级管理员组",
                    CreatedUserId   = 0,
                    CreatedUserName = "******",
                    UpdatedUserId   = 0,
                    UpdatedUserName = "******",
                };

                await _sysRoleRepository.InsertAsync(role);

                var user = new SysUser()
                {
                    LoginName       = "admin",
                    Password        = "******".EncryptMD5Encode(),
                    Status          = true,
                    UserName        = "******",
                    CreatedUserId   = 0,
                    CreatedUserName = "******",
                    UpdatedUserId   = 0,
                    UpdatedUserName = "******",
                };

                await _sysUserRepository.InsertAsync(user);

                var roleUser = new SysRoleUser()
                {
                    RoleId = role.RoleId,
                    UserId = user.UserId,
                };

                await userRoleRepo.InsertAsync(roleUser);

                uow.Commit();
            }
        }
        public async Task <IResponseEntity> CreateAsync(UserAddRequest req)
        {
            var item = _mapper.Map <SysUserEntity>(req);

            item.Password = MD5Encrypt.Encrypt32(item.Password);
            var result = await _sysUserRepository.InsertAsync(item);

            return(ResponseEntity.Result(result != null && result?.Id != ""));
        }
Example #3
0
        public async Task <bool> AddUser(CreateUserModel model)
        {
            if (!model.IsEmpty())
            {
                var user = _mapper.Map <SysUser>(model);
                await _userRepository.InsertAsync(user);

                var res = await _uow.CommitAsync();

                return(res > 0);
            }
            return(false);
        }