diff options
Diffstat (limited to 'Validators/NameAttribute.cs')
-rw-r--r-- | Validators/NameAttribute.cs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Validators/NameAttribute.cs b/Validators/NameAttribute.cs index 2f1a5ae..39f0264 100644 --- a/Validators/NameAttribute.cs +++ b/Validators/NameAttribute.cs @@ -4,17 +4,15 @@ using LibraryAPI.Models; namespace LibraryAPI.Validators { public class NameAttribute : ValidationAttribute { public string[] valid_names = { "regular", "librarian" }; - public string GetErrorMessage() { + public string GetErrorMessage() { return "Group name must be \"regular\" or \"librarian\""; } - protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) { - var group = (Group) validationContext.ObjectInstance; + protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) { + if(Array.Exists(valid_names, s => s == value.ToString())) + return ValidationResult.Success; - if(Array.Exists(valid_names, s => s == group.Name)) - return ValidationResult.Success; - - return new ValidationResult(GetErrorMessage()); - } + return new ValidationResult(GetErrorMessage()); + } } } |