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.
Lidarr/src/NzbDrone.Core/Validation/DownloadClientExistsValidat...

28 lines
845 B

using FluentValidation.Validators;
using NzbDrone.Core.Download;
namespace NzbDrone.Core.Validation
{
public class DownloadClientExistsValidator : PropertyValidator
{
private readonly IDownloadClientFactory _downloadClientFactory;
public DownloadClientExistsValidator(IDownloadClientFactory downloadClientFactory)
{
_downloadClientFactory = downloadClientFactory;
}
protected override string GetDefaultMessageTemplate() => "Download Client does not exist";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context?.PropertyValue == null || (int)context.PropertyValue == 0)
{
return true;
}
return _downloadClientFactory.Exists((int)context.PropertyValue);
}
}
}