Radarr/src/NzbDrone.Core/Validation/ProfileExistsValidator.cs

28 lines
769 B
C#

using FluentValidation.Validators;
using NzbDrone.Core.Profiles.Qualities;
namespace NzbDrone.Core.Validation
{
public class ProfileExistsValidator : PropertyValidator
{
private readonly IQualityProfileService _profileService;
public ProfileExistsValidator(IQualityProfileService profileService)
{
_profileService = profileService;
}
protected override string GetDefaultMessageTemplate() => "QualityProfile does not exist";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return true;
}
return _profileService.Exists((int)context.PropertyValue);
}
}
}