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.
Sonarr/src/Sonarr.Api.V3/Profiles/Language/LanguageValidator.cs

43 lines
1.1 KiB

using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using FluentValidation.Validators;
namespace Sonarr.Api.V3.Profiles.Language
{
public static class LanguageValidation
{
public static IRuleBuilderOptions<T, IList<LanguageProfileItemResource>> MustHaveAllowedLanguage<T>(this IRuleBuilder<T, IList<LanguageProfileItemResource>> ruleBuilder)
{
ruleBuilder.SetValidator(new NotEmptyValidator(null));
return ruleBuilder.SetValidator(new LanguageValidator<T>());
}
}
public class LanguageValidator<T> : PropertyValidator
{
public LanguageValidator()
: base("Must have at least one allowed language")
{
}
protected override bool IsValid(PropertyValidatorContext context)
{
var list = context.PropertyValue as IList<LanguageProfileItemResource>;
if (list == null)
{
return false;
}
if (!list.Any(c => c.Allowed))
{
return false;
}
return true;
}
}
}