-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reverted ValidateField to use FieldIdentifier.Model (#132)
- Loading branch information
1 parent
583b903
commit f8eff24
Showing
8 changed files
with
59 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using FluentValidation; | ||
using System.Threading.Tasks; | ||
|
||
namespace SharedModels | ||
{ | ||
public class Person | ||
{ | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
public string? FirstName { get; set; } | ||
public string? LastName { get; set; } | ||
public int? Age { get; set; } | ||
public string EmailAddress { get; set; } | ||
public Address Address { get; set; } = new Address(); | ||
public string? EmailAddress { get; set; } | ||
public Address Address { get; set; } = new(); | ||
} | ||
|
||
public class PersonValidator : AbstractValidator<Person> | ||
|
@@ -35,12 +34,12 @@ public PersonValidator() | |
RuleFor(p => p.EmailAddress) | ||
.NotEmpty().WithMessage("You must enter a email address") | ||
.EmailAddress().WithMessage("You must provide a valid email address") | ||
.MustAsync(async (email, cancellationToken) => await IsUniqueAsync(email)).WithMessage("Email address must be unique").When(p => !string.IsNullOrEmpty(p.EmailAddress)); | ||
.MustAsync(async (email, _) => await IsUniqueAsync(email)).WithMessage("Email address must be unique").When(p => !string.IsNullOrEmpty(p.EmailAddress)); | ||
|
||
RuleFor(p => p.Address).SetValidator(new AddressValidator()); | ||
} | ||
|
||
private async Task<bool> IsUniqueAsync(string email) | ||
private static async Task<bool> IsUniqueAsync(string email) | ||
{ | ||
await Task.Delay(300); | ||
return email.ToLower() != "[email protected]"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters