Skip to content

Commit

Permalink
Merge pull request #94 from Brixel/email-phone-validation
Browse files Browse the repository at this point in the history
fix: Change validation to require either email or phone number, not both
  • Loading branch information
BerendWouters authored Sep 13, 2022
2 parents f3c6ef3 + 16716fb commit 9a602c3
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Commands/Handlers/Member/AddMember/AddMemberCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public AddMemberCommandValidator()
.MaximumLength(50);

RuleFor(x => x.Email)
.NotEmpty()
.NotEmpty().When(x => string.IsNullOrWhiteSpace(x.PhoneNumber))
.MaximumLength(100)
.EmailAddress();

RuleFor(x => x.PhoneNumber)
.NotEmpty()
.NotEmpty().When(x => string.IsNullOrWhiteSpace(x.Email))
.MaximumLength(50);

RuleFor(x => x.Address)
Expand Down
7 changes: 4 additions & 3 deletions Commands/Handlers/Member/EditMember/EditMemberCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public EditMemberCommandValidator()
.MaximumLength(50);

RuleFor(x => x.Email)
.NotEmpty()
.MaximumLength(100);
.NotEmpty().When(x => string.IsNullOrWhiteSpace(x.PhoneNumber))
.MaximumLength(100)
.EmailAddress();

RuleFor(x => x.PhoneNumber)
.NotEmpty()
.NotEmpty().When(x => string.IsNullOrWhiteSpace(x.Email))
.MaximumLength(50);

RuleFor(x => x.Address)
Expand Down
4 changes: 2 additions & 2 deletions Domain/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ private Member() { } // Make EFCore happy
public Guid Id { get; private set; }
public string FirstName { get; private set; }
public string LastName { get; private set; }
public string Email { get; private set; }
public string PhoneNumber { get; private set; }
public string? Email { get; private set; }
public string? PhoneNumber { get; private set; }
public Address Address { get; private set; }
public DateTimeOffset? MembershipExpiryDate { get; private set; }
public double MembershipFee { get; private set; }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9a602c3

Please sign in to comment.