Example #1
0
        public async Task RemoveProjectMember(int projectId, int userId, int currentUserId = 0, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var projectMemberByProjectSpec = new ProjectMemberFilterSpecification(projectId, userId);
            var projectMember = await _projectMemberRepository.GetSingleBySpec(projectMemberByProjectSpec, cancellationToken);

            if (projectMember.ProjectMemberRoleId == MemberRole.OwnerId && currentUserId > 0)
            {
                var currentUserOwnerSpec = new ProjectMemberFilterSpecification(projectId, currentUserId, null, MemberRole.OwnerId);
                if (await _projectMemberRepository.CountBySpec(currentUserOwnerSpec) == 0)
                {
                    throw new RemoveProjectOwnerException(currentUserId);
                }
            }

            var projectMemberId = projectMember?.Id;

            if (projectMemberId > 0)
            {
                await _projectMemberRepository.Delete(projectMemberId.GetValueOrDefault(), cancellationToken);
            }
        }