private IEnumerable <AchievementStatus> AddCriteriaToAchievementStages(int achievementId, int faction) { var achievementStages = new List <AchievementStatus>(); var achievementName = _achievementRepository.GetAchievementName(achievementId); var opposingFaction = GetOpposingFaction(faction); IEnumerable <Stage> stages = _achievementRepository.GetStagesForAchievement(achievementId).Where(s => s.Faction != opposingFaction); achievementStages.Add( new AchievementStatus { Achievement = achievementName, Stages = stages }); // if any of the stages has an AchievementId these also must be included var SubAchievements = stages .Where(s => s.AchievementId != null) .Select(s => s.AchievementId); foreach (int subAchievementId in SubAchievements) { achievementStages.AddRange(AddCriteriaToAchievementStages((int)subAchievementId, faction)); } ; return(achievementStages); }