mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-03-10 20:15:26 -04:00
Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com> Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Kavita.Models.DTOs.SeriesDetail;
|
|
using Kavita.Models.Entities;
|
|
using Kavita.Models.Entities.Enums;
|
|
using Kavita.Models.Entities.Metadata;
|
|
|
|
namespace Kavita.Models.Extensions;
|
|
|
|
public static class EnumerableExtensions
|
|
{
|
|
public static IEnumerable<RecentlyAddedSeriesDto> RestrictAgainstAgeRestriction(this IEnumerable<RecentlyAddedSeriesDto> items, AgeRestriction restriction)
|
|
{
|
|
if (restriction.AgeRating == AgeRating.NotApplicable) return items;
|
|
var q = items.Where(s => s.AgeRating <= restriction.AgeRating);
|
|
if (!restriction.IncludeUnknowns)
|
|
{
|
|
return q.Where(s => s.AgeRating != AgeRating.Unknown);
|
|
}
|
|
|
|
return q;
|
|
}
|
|
|
|
public static IEnumerable<SeriesMetadata> RestrictAgainstAgeRestriction(this IEnumerable<SeriesMetadata> items, AgeRestriction restriction)
|
|
{
|
|
if (restriction.AgeRating == AgeRating.NotApplicable) return items;
|
|
var q = items.Where(s => s.AgeRating <= restriction.AgeRating);
|
|
if (!restriction.IncludeUnknowns)
|
|
{
|
|
return q.Where(s => s.AgeRating != AgeRating.Unknown);
|
|
}
|
|
|
|
return q;
|
|
}
|
|
|
|
public static IEnumerable<Chapter> RestrictAgainstAgeRestriction(this IEnumerable<Chapter> items, AgeRestriction restriction)
|
|
{
|
|
if (restriction.AgeRating == AgeRating.NotApplicable) return items;
|
|
var q = items.Where(s => s.AgeRating <= restriction.AgeRating);
|
|
if (!restriction.IncludeUnknowns)
|
|
{
|
|
return q.Where(s => s.AgeRating != AgeRating.Unknown);
|
|
}
|
|
|
|
return q;
|
|
}
|
|
}
|