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/Paths/RootFolderValidator.cs

31 lines
959 B

using FluentValidation.Validators;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.RootFolders;
namespace NzbDrone.Core.Validation.Paths
{
public class RootFolderValidator : PropertyValidator
{
private readonly IRootFolderService _rootFolderService;
public RootFolderValidator(IRootFolderService rootFolderService)
{
_rootFolderService = rootFolderService;
}
protected override string GetDefaultMessageTemplate() => "Path '{path}' is already configured as a root folder";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return true;
}
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
return !_rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString()));
}
}
}