Employee.cs 751 B

12345678910111213141516171819202122232425
  1. using FluentValidation;
  2. namespace BlazorEditForms.Model;
  3. public class Employee
  4. {
  5. public string Code { get; set; } = string.Empty;
  6. public string Firstname { get; set; } = string.Empty;
  7. public string Lastname { get; set; } = string.Empty;
  8. public IList<PhoneNumber> PhoneNumbers { get; set; } = [];
  9. }
  10. public class EmployeeValidator : AbstractValidator<Employee>
  11. {
  12. public EmployeeValidator()
  13. {
  14. RuleFor(x => x.Code).NotEmpty().MinimumLength(3);
  15. RuleForEach(x => x.PhoneNumbers).SetValidator(new PhoneNumberValidator());
  16. RuleFor(x => x.Firstname).MustAsync(async (value, ct) =>
  17. {
  18. await Task.Delay(500);
  19. return value == "Foo";
  20. });
  21. }
  22. }