diff options
author | HombreLaser <sebastian-440@live.com> | 2022-11-06 17:04:29 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-11-06 17:04:29 -0600 |
commit | 8b40d27710e532a43aaf1eb198be64af1a2e576e (patch) | |
tree | cd2264d249e7cb4d1a9e3407d36d0db9680ef913 /Validators | |
parent | 08819c6738a4f82ccf07ae5ed60835b087f7bb34 (diff) |
Diffstat (limited to 'Validators')
-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()); + } } } |