You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
853 B
30 lines
853 B
using System.Linq;
|
|
using FluentValidation.Validators;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Tv;
|
|
|
|
namespace NzbDrone.Core.Validation.Paths
|
|
{
|
|
public class SeriesAncestorValidator : PropertyValidator
|
|
{
|
|
private readonly ISeriesService _seriesService;
|
|
|
|
public SeriesAncestorValidator(ISeriesService seriesService)
|
|
{
|
|
_seriesService = seriesService;
|
|
}
|
|
|
|
protected override string GetDefaultMessageTemplate() => "Path is an ancestor of an existing series";
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return !_seriesService.GetAllSeriesPaths().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value));
|
|
}
|
|
}
|
|
}
|