26 lines
1.0 KiB
C#
26 lines
1.0 KiB
C#
|
|
using FluentValidation;
|
||
|
|
using CMSMicroservice.Protobuf.Protos.UserWalletChangeLog;
|
||
|
|
namespace CMSMicroservice.Protobuf.Validator.UserWalletChangeLog;
|
||
|
|
|
||
|
|
public class CreateNewUserWalletChangeLogRequestValidator : AbstractValidator<CreateNewUserWalletChangeLogRequest>
|
||
|
|
{
|
||
|
|
public CreateNewUserWalletChangeLogRequestValidator()
|
||
|
|
{
|
||
|
|
RuleFor(model => model.WalletId)
|
||
|
|
.NotNull();
|
||
|
|
RuleFor(model => model.CurrentBalance)
|
||
|
|
.NotNull();
|
||
|
|
RuleFor(model => model.ChangeValue)
|
||
|
|
.NotNull();
|
||
|
|
RuleFor(model => model.IsIncrease)
|
||
|
|
.NotNull();
|
||
|
|
}
|
||
|
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||
|
|
{
|
||
|
|
var result = await ValidateAsync(ValidationContext<CreateNewUserWalletChangeLogRequest>.CreateWithOptions((CreateNewUserWalletChangeLogRequest)model, x => x.IncludeProperties(propertyName)));
|
||
|
|
if (result.IsValid)
|
||
|
|
return Array.Empty<string>();
|
||
|
|
return result.Errors.Select(e => e.ErrorMessage);
|
||
|
|
};
|
||
|
|
}
|