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
813 B
30 lines
813 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;
|
|
}
|
|
|
|
var foreignArtistId = context.PropertyValue.ToString();
|
|
|
|
return _artistService.FindById(foreignArtistId) == null;
|
|
}
|
|
}
|
|
}
|