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.
28 lines
809 B
28 lines
809 B
using FluentValidation.Validators;
|
|
using NzbDrone.Core.Music;
|
|
|
|
namespace NzbDrone.Core.Validation.Paths
|
|
{
|
|
public class ArtistExistsValidator : PropertyValidator
|
|
{
|
|
private readonly IArtistService _artistService;
|
|
|
|
public ArtistExistsValidator(IArtistService artistService)
|
|
{
|
|
_artistService = artistService;
|
|
}
|
|
|
|
protected override string GetDefaultMessageTemplate() => "This artist has already been added.";
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return !_artistService.GetAllArtists().Exists(s => s.Metadata.Value.ForeignArtistId == context.PropertyValue.ToString());
|
|
}
|
|
}
|
|
}
|