public static List <AnimeGroup> GetRelatedGroupsFromAnimeID(ISession session, int animeid) { // TODO we need to recusrive list at all relations and not just the first one AniDB_AnimeRepository repAniAnime = new AniDB_AnimeRepository(); AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeGroupRepository repGroups = new AnimeGroupRepository(); List <AnimeGroup> grps = new List <AnimeGroup>(); AniDB_Anime anime = repAniAnime.GetByAnimeID(session, animeid); if (anime == null) { return(grps); } // first check for groups which are directly related List <AniDB_Anime_Relation> relations = anime.GetRelatedAnime(session); foreach (AniDB_Anime_Relation rel in relations) { string relationtype = rel.RelationType.ToLower(); if ((relationtype == "same setting") || (relationtype == "alternative setting") || (relationtype == "character") || (relationtype == "other")) { //Filter these relations these will fix messes, like Gundam , Clamp, etc. continue; } // we actually need to get the series, because it might have been added to another group already AnimeSeries ser = repSeries.GetByAnimeID(session, rel.RelatedAnimeID); if (ser != null) { AnimeGroup grp = repGroups.GetByID(session, ser.AnimeGroupID); if (grp != null) { grps.Add(grp); } } } if (grps.Count > 0) { return(grps); } // if nothing found check by all related anime List <AniDB_Anime> relatedAnime = anime.GetAllRelatedAnime(session); foreach (AniDB_Anime rel in relatedAnime) { // we actually need to get the series, because it might have been added to another group already AnimeSeries ser = repSeries.GetByAnimeID(session, rel.AnimeID); if (ser != null) { AnimeGroup grp = repGroups.GetByID(session, ser.AnimeGroupID); if (grp != null) { grps.Add(grp); } } } return(grps); }