using System.Collections.Generic; using System.Linq; using API.Entities; using API.Entities.Enums; namespace API.Extensions { public static class VolumeListExtensions { public static Volume FirstWithChapters(this IList volumes, bool inBookSeries) { return inBookSeries ? volumes.FirstOrDefault(v => v.Chapters.Any()) : volumes.FirstOrDefault(v => v.Chapters.Any() && (v.Number == 1)); } /// /// Selects the first Volume to get the cover image from. For a book with only a special, the special will be returned. /// If there are both specials and non-specials, then the first non-special will be returned. /// /// /// /// public static Volume GetCoverImage(this IList volumes, MangaFormat seriesFormat) { if (seriesFormat is MangaFormat.Epub or MangaFormat.Pdf) { return volumes.OrderBy(x => x.Number).FirstOrDefault(); } if (volumes.Any(x => x.Number != 0)) { return volumes.OrderBy(x => x.Number).FirstOrDefault(x => x.Number != 0); } return volumes.OrderBy(x => x.Number).FirstOrDefault(); } } }