From d7b0655238a3e5413787a88056687905ebae0430 Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Thu, 5 Oct 2023 03:59:42 +0200 Subject: [PATCH] fix: fix getting series for group returning series not in the group or any sub-groups. --- Shoko.Server/Models/SVR_AnimeGroup.cs | 40 +++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Shoko.Server/Models/SVR_AnimeGroup.cs b/Shoko.Server/Models/SVR_AnimeGroup.cs index ae948c420..aca15a722 100644 --- a/Shoko.Server/Models/SVR_AnimeGroup.cs +++ b/Shoko.Server/Models/SVR_AnimeGroup.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -292,23 +292,35 @@ public void SetMainSeries(SVR_AnimeSeries series) RepoFactory.AnimeGroup.Save(this, false, false); } - public List GetSeries() + public List GetSeries(bool skipSorting = false) { - // Make sure the default/main series is the first, if it's directly within the group - if (DefaultAnimeSeriesID == null && MainAniDBAnimeID == null) - return RepoFactory.AnimeSeries.GetByGroupID(AnimeGroupID).OrderBy(a => a.AirDate).ToList(); + if (skipSorting) + return RepoFactory.AnimeSeries.GetByGroupID(AnimeGroupID); - SVR_AnimeSeries mainSeries = null; - if (DefaultAnimeSeriesID.HasValue) mainSeries = RepoFactory.AnimeSeries.GetByID(DefaultAnimeSeriesID.Value); - if (mainSeries == null && MainAniDBAnimeID.HasValue) mainSeries = RepoFactory.AnimeSeries.GetByAnimeID(MainAniDBAnimeID.Value); + var seriesList = RepoFactory.AnimeSeries + .GetByGroupID(AnimeGroupID) + .OrderBy(a => a.AirDate) + .ToList(); - var seriesList = RepoFactory.AnimeSeries.GetByGroupID(AnimeGroupID).OrderBy(a => a.AirDate).ToList(); - if (mainSeries == null) return seriesList; + // Make sure the default/main series is the first, if it's directly + // within the group. + if (DefaultAnimeSeriesID.HasValue || MainAniDBAnimeID.HasValue) + { + SVR_AnimeSeries mainSeries = null; + if (DefaultAnimeSeriesID.HasValue) + mainSeries = seriesList.Find(series => series.AnimeSeriesID == DefaultAnimeSeriesID.Value); - seriesList.Remove(mainSeries); - seriesList.Insert(0, mainSeries); - return seriesList; + if (mainSeries == null && MainAniDBAnimeID.HasValue) + mainSeries = seriesList.Find(series => series.AniDB_ID == MainAniDBAnimeID.Value); + if (mainSeries != null) + { + seriesList.Remove(mainSeries); + seriesList.Insert(0, mainSeries); + } + } + + return seriesList; } public List GetAllSeries(bool skipSorting = false) @@ -1266,7 +1278,7 @@ public static void GetAnimeSeriesRecursive(int animeGroupID, ref List