|
@@ -1,13 +1,25 @@
|
|
|
-using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
+using FluentValidation;
|
|
|
|
|
|
|
|
namespace BlazorEditForms.Model;
|
|
namespace BlazorEditForms.Model;
|
|
|
|
|
|
|
|
public class Employee
|
|
public class Employee
|
|
|
{
|
|
{
|
|
|
- [Required]
|
|
|
|
|
- [MinLength(3)]
|
|
|
|
|
public string Code { get; set; } = string.Empty;
|
|
public string Code { get; set; } = string.Empty;
|
|
|
public string Firstname { get; set; } = string.Empty;
|
|
public string Firstname { get; set; } = string.Empty;
|
|
|
public string Lastname { get; set; } = string.Empty;
|
|
public string Lastname { get; set; } = string.Empty;
|
|
|
public IList<PhoneNumber> PhoneNumbers { get; set; } = [];
|
|
public IList<PhoneNumber> PhoneNumbers { get; set; } = [];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+public class EmployeeValidator : AbstractValidator<Employee>
|
|
|
|
|
+{
|
|
|
|
|
+ public EmployeeValidator()
|
|
|
|
|
+ {
|
|
|
|
|
+ RuleFor(x => x.Code).NotEmpty().MinimumLength(3);
|
|
|
|
|
+ RuleForEach(x => x.PhoneNumbers).SetValidator(new PhoneNumberValidator());
|
|
|
|
|
+ RuleFor(x => x.Firstname).MustAsync(async (value, ct) =>
|
|
|
|
|
+ {
|
|
|
|
|
+ await Task.Delay(500);
|
|
|
|
|
+ return value == "Foo";
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+}
|