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.
32 lines
958 B
32 lines
958 B
using System.Linq;
|
|
using FluentValidation.Validators;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Music;
|
|
|
|
namespace NzbDrone.Core.Validation.Paths
|
|
{
|
|
public class ArtistAncestorValidator : PropertyValidator
|
|
{
|
|
private readonly IArtistService _artistService;
|
|
|
|
public ArtistAncestorValidator(IArtistService artistService)
|
|
{
|
|
_artistService = artistService;
|
|
}
|
|
|
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' is an ancestor of an existing artist";
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
|
|
|
return !_artistService.AllArtistPaths().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value));
|
|
}
|
|
}
|
|
}
|