添加项目文件。
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class ProductModelValidator : AbstractValidator<ProductModel>
|
||||
{
|
||||
public ProductModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Title).NotEmpty().WithMessage("商品标题不能为空");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<ProductModel>.CreateWithOptions((ProductModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user