public bool LeaveGroup(int groupId) { int userId = HttpContext.Current.User.Identity.GetUserId <int>(); if (!_groupMemberRepository.IsInGroup(groupId, userId)) { throw new ArgumentException("Wrong groupId or you are not a member of this group"); } if (IsGroupOwner(groupId, userId)) { int ownerRoleId = _roleRepository.Get(r => r.Name.Equals("Owner")).Select(r => r.Id).Single(); int owners = _groupMemberRepository.Get(m => m.GroupId == groupId).Where(r => r.RoleId.Equals(ownerRoleId)).Count(); if (owners > 1) { _groupMemberRepository.RemoveUserFromGroup(groupId, userId); _issueRepository.AssignToNoone(groupId, userId); return(true); } } else { _groupMemberRepository.RemoveUserFromGroup(groupId, userId); _issueRepository.AssignToNoone(groupId, userId); return(true); } return(false); }