| 12345678910111213141516171819202122232425 |
- using FluentValidation;
- namespace BlazorEditForms.Model;
- public class Employee
- {
- public string Code { get; set; } = string.Empty;
- public string Firstname { get; set; } = string.Empty;
- public string Lastname { get; set; } = string.Empty;
- 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";
- });
- }
- }
|