Beispiel #1
0
        public async Task <string> Create(CreateUserInput input)
        {
            input.CheckDataAnnotations().CheckValidResult();
            _session.CheckLoginUserDataPermision(input.OrgId, "您没有新增该部门用户的权限");
            var existUser = await _userRepository.FirstOrDefaultAsync(p => p.UserName == input.UserName, false);

            if (existUser != null)
            {
                throw new UserFriendlyException($"已经存在用户名为{input.UserName}的用户");
            }
            existUser = await _userRepository.FirstOrDefaultAsync(p => p.Phone == input.Phone, false);

            if (existUser != null)
            {
                throw new UserFriendlyException($"已经存在手机号码为{input.Phone}的用户");
            }
            existUser = await _userRepository.FirstOrDefaultAsync(p => p.Email == input.Email, false);

            if (existUser != null)
            {
                throw new UserFriendlyException($"已经存在Email为{input.Email}的用户");
            }

            await _userDomainService.Create(input);

            return("新增员工成功");
        }
Beispiel #2
0
        public async Task Delete(long roleid)
        {
            var role = await _roleRepository.SingleOrDefaultAsync(p => p.Id == roleid);

            if (role == null)
            {
                throw new BusinessException($"不存在Id为{roleid}的角色信息");
            }
            _session.CheckLoginUserDataPermision(role.DataPermissionType, "您设置的角色的数据权限大于您拥有数据权限,系统不允许该操作");
            var userRoleCount = await _userRoleRepository.GetCountAsync(p => p.RoleId == roleid);

            if (userRoleCount > 0)
            {
                throw new BusinessException($"{role.Name}被分配用户,请先删除相关授权的用户信息");
            }
            var userGroupRoleCount = await _userGroupRoleRepository.GetCountAsync(p => p.RoleId == roleid);

            if (userGroupRoleCount > 0)
            {
                throw new BusinessException($"{role.Name}被分配用户组,请先删除相关授权的用户组信息");
            }
            using (var locker = await _lockerProvider.CreateLockAsync("DeleteRole"))
            {
                await locker.Lock(async() =>
                {
                    await UnitOfWorkAsync(async(conn, trans) =>
                    {
                        await _roleRepository.DeleteAsync(p => p.Id == roleid, conn, trans);
                        await _rolePermissionRepository.DeleteAsync(p => p.RoleId == roleid, conn, trans);
                        await _roleDataPermissionOrgRelationRepository.DeleteAsync(p => p.RoleId == roleid, conn,
                                                                                   trans);
                        await _roleOrganizationRepository.DeleteAsync(p => p.RoleId == roleid, conn, trans);
                        await RemoveRoleCheckPemissionCache(roleid);
                    }, Connection);
                });
            }
        }
Beispiel #3
0
 public static void CheckLoginUserDataPermision(this ISurgingSession session, string message)
 {
     session.CheckLoginUserDataPermision(session.OrgId, message);
 }
Beispiel #4
0
 public static void CheckLoginUserDataPermision(this ISurgingSession session)
 {
     session.CheckLoginUserDataPermision("您没有插入数据的权限");
 }