Created
September 4, 2020 14:00
-
-
Save bjornmicallef/9fe86a1315aa4bf232127e42072e931e to your computer and use it in GitHub Desktop.
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
public class PurchasePlaystationGameDto | |
{ | |
public int ID { get; set; } | |
public int UserID { get; set; } | |
public decimal Price { get; set; } | |
public bool PlaystationPlusMember { get; set; } | |
} | |
public class PurchasePlaystationGameDtoValidator : AbstractValidator | |
{ | |
public PurchasePlaystationGameDtoValidator() | |
{ | |
RuleFor(x => x.ID).NotNull().GreaterThan(0).WithMessage("ID must be greater than 0."); | |
RuleFor(x => x.UserID).NotNull().GreaterThan(0).WithMessage("UserID must be greater than 0."); | |
RuleFor(x => x.Price).Must(BeGreaterThanZeroForNonMembers).WithMessage("Price must be greater than 0"); | |
} | |
private bool BeGreaterThanZeroForNonMembers(PurchasePlaystationGameDto dtoInstance, decimal price) | |
{ | |
// game is free for members :) | |
if (!dtoInstance.PlaystationPlusMember & price <= 0) | |
{ | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment