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.
Readarr/src/NzbDrone.Core/Validation/Paths/AuthorExistsValidator.cs

28 lines
808 B

using FluentValidation.Validators;
using NzbDrone.Core.Books;
namespace NzbDrone.Core.Validation.Paths
{
public class AuthorExistsValidator : PropertyValidator
{
private readonly IAuthorService _authorService;
public AuthorExistsValidator(IAuthorService authorService)
{
_authorService = authorService;
}
protected override string GetDefaultMessageTemplate() => "This author has already been added";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return true;
}
return !_authorService.GetAllAuthors().Exists(s => s.Metadata.Value.ForeignAuthorId == context.PropertyValue.ToString());
}
}
}