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.
33 lines
991 B
33 lines
991 B
using System.Linq;
|
|
using FluentValidation.Validators;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Books;
|
|
|
|
namespace NzbDrone.Core.Validation.Paths
|
|
{
|
|
public class AuthorPathValidator : PropertyValidator
|
|
{
|
|
private readonly IAuthorService _authorService;
|
|
|
|
public AuthorPathValidator(IAuthorService authorService)
|
|
{
|
|
_authorService = authorService;
|
|
}
|
|
|
|
protected override string GetDefaultMessageTemplate() => "Path is already configured for another author";
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
dynamic instance = context.ParentContext.InstanceToValidate;
|
|
var instanceId = (int)instance.Id;
|
|
|
|
return !_authorService.AllAuthorPaths().Any(s => s.Value.PathEquals(context.PropertyValue.ToString()) && s.Key != instanceId);
|
|
}
|
|
}
|
|
}
|