Exemple #1
0
        public bool RemoveMember(RemoveMemberViewModel viewModel)
        {
            string userRole = _groupMemberRepository.GetRole(viewModel.GroupId, viewModel.UserId);

            if (!userRole.Equals(RoleNames.ROLE_OWNER) ||
                !_groupMemberRepository.IsInGroup(viewModel.GroupId, viewModel.UserToRemove))
            {
                throw new ArgumentException("User does not belong to this group");
            }

            if (IsGroupOwner(viewModel.GroupId, viewModel.UserToRemove))
            {
                int owners = _groupMemberRepository.CountOwners(viewModel.GroupId);

                if (owners > 1)
                {
                    _groupMemberRepository.RemoveUserFromGroup(viewModel.GroupId, viewModel.UserToRemove);
                    _issueRepository.AssignToNoone(viewModel.GroupId, viewModel.UserToRemove);

                    return(true);
                }
                return(false);
            }

            _groupMemberRepository.RemoveUserFromGroup(viewModel.GroupId, viewModel.UserToRemove);
            _issueRepository.AssignToNoone(viewModel.GroupId, viewModel.UserToRemove);

            return(true);
        }