diff options
author | HombreLaser <sebastian-440@live.com> | 2022-11-06 02:10:44 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-11-06 02:10:44 -0600 |
commit | 08819c6738a4f82ccf07ae5ed60835b087f7bb34 (patch) | |
tree | 9c0c77626587136d41002769fb5a030e1be2f5b8 /Validators | |
parent | f060c4f88f635af3295ea7652cbbbd08dbf1c6cf (diff) |
Añadidos grupos y usuarios
Diffstat (limited to 'Validators')
-rw-r--r-- | Validators/NameAttribute.cs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Validators/NameAttribute.cs b/Validators/NameAttribute.cs new file mode 100644 index 0000000..2f1a5ae --- /dev/null +++ b/Validators/NameAttribute.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using LibraryAPI.Models; + +namespace LibraryAPI.Validators { + public class NameAttribute : ValidationAttribute { + public string[] valid_names = { "regular", "librarian" }; + public string GetErrorMessage() { + return "Group name must be \"regular\" or \"librarian\""; + } + + protected override ValidationResult? IsValid(object? value, ValidationContext validationContext) { + var group = (Group) validationContext.ObjectInstance; + + if(Array.Exists(valid_names, s => s == group.Name)) + return ValidationResult.Success; + + return new ValidationResult(GetErrorMessage()); + } + } +} |