添加项目文件。
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class AddressModelValidator : AbstractValidator<AddressModel>
|
||||
{
|
||||
public AddressModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写收件人信息");
|
||||
RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage("请填写你常用的邮箱地址");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class AdminModelValidator : AbstractValidator<AdminModel>
|
||||
{
|
||||
public AdminModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
|
||||
RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间");
|
||||
RuleFor(p => p.Password).NotEmpty().When(p => p.Id == 0).WithMessage("登录密码不能为空");
|
||||
RuleFor(p => p.Password).Length(6, 32).When(p => !string.IsNullOrEmpty(p.Password)).WithMessage("登录密码长度必须在6-32个字符之间");
|
||||
RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage("请填写你常用的邮箱地址");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using Atomx.Common.Enums;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class AppVersionModelValidator : AbstractValidator<AppVersionModel>
|
||||
{
|
||||
public AppVersionModelValidator()
|
||||
{
|
||||
RuleFor(p => p.AppName).NotEmpty().WithMessage("应用名不能为空");
|
||||
RuleFor(p => p.Title).NotEmpty().WithMessage("版本标题不能为空");
|
||||
RuleFor(p => p.VersionX).GreaterThanOrEqualTo(0).WithMessage("请填写正确的主版本号");//大于或等于0
|
||||
RuleFor(p => p.VersionY).GreaterThanOrEqualTo(0).WithMessage("请填写正确的次版本号");//大于或等于0
|
||||
RuleFor(p => p.VersionZ).GreaterThanOrEqualTo(0).WithMessage("请填写正确的修订版本号");//大于或等于0
|
||||
RuleFor(p => p.Platform).GreaterThan(0).WithMessage("请选择运行平台");
|
||||
RuleFor(p => p.VersionState).GreaterThan(0).WithMessage("请选择版本状态");
|
||||
RuleFor(p => p.Status).Must(ValidateStatus).WithMessage("请选择发布状态");
|
||||
}
|
||||
|
||||
private bool ValidateStatus(int status)
|
||||
{
|
||||
if (status != (int)DataStatus.Enable && status != (int)DataStatus.Disable)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<AppVersionModel>.CreateWithOptions((AppVersionModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using Atomx.Common.Enums;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class CategoryModelValidator : AbstractValidator<CategoryModel>
|
||||
{
|
||||
public CategoryModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
|
||||
RuleFor(p => p.ParentId).Must((p,id)=> ValidateParent(id,p)).WithMessage("不能选择自己做上级分类");
|
||||
}
|
||||
|
||||
private bool ValidateParent(long parentId, CategoryModel model)
|
||||
{
|
||||
if (model.Id == parentId && model.Id > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CategoryModel>.CreateWithOptions((CategoryModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class CorporationModelValidator : AbstractValidator<CorporationModel>
|
||||
{
|
||||
public CorporationModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("公司名称不能为空");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<CorporationModel>.CreateWithOptions((CorporationModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class CorporationStaffModelValidator : AbstractValidator<CorporationStaffModel>
|
||||
{
|
||||
public CorporationStaffModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
|
||||
RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间");
|
||||
RuleFor(p => p.Password).NotEmpty().When(p => p.Id == 0).WithMessage("登录密码不能为空");
|
||||
RuleFor(p => p.Password).Length(6, 32).When(p => !string.IsNullOrEmpty(p.Password)).WithMessage("登录密码长度必须在6-32个字符之间");
|
||||
RuleFor(p => p.Password).Length(6, 32).When(p => p.SetPassword).WithMessage("登录密码长度必须在6-32个字符之间");
|
||||
RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage("请填写你常用的邮箱地址");
|
||||
RuleFor(p => p.CorporationId).GreaterThan(0).WithMessage("必须设置一个归属企业");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class CurrencyModelValidator : AbstractValidator<CurrencyModel>
|
||||
{
|
||||
public CurrencyModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写货币名称");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Common.Configuration;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class GeneralConfigValidator : AbstractValidator<GeneralConfig>
|
||||
{
|
||||
public GeneralConfigValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("网站名称不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class LanguageModelValidator : AbstractValidator<LanguageModel>
|
||||
{
|
||||
public LanguageModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写语言名称");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class LocaleResourceModelValidator : AbstractValidator<LocaleResourceModel>
|
||||
{
|
||||
public LocaleResourceModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("本地化多语言信息不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class LoginModelValidator : AbstractValidator<LoginModel>
|
||||
{
|
||||
public LoginModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Account).NotEmpty().WithMessage("登录账号不能为空");
|
||||
RuleFor(p => p.Account).Length(2, 100).When(p => !string.IsNullOrEmpty(p.Account)).WithMessage("用户名长度必须再2-100个字符之间");
|
||||
//RuleFor(p => p.Account).EmailAddress().When(p => !p.Account.Contains("@") && !string.IsNullOrEmpty(p.Account)).WithMessage("电子邮件地址不正确");
|
||||
|
||||
//RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
|
||||
//RuleFor(p => p.Username).Length(2, 50).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-50个字符之间");
|
||||
//RuleFor(p => p.Account).NotEmpty().WithMessage("电子邮件地址不能为空");
|
||||
//RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage(p => localizer["Form.Email.Invalid"]);
|
||||
//RuleFor(p => p.Email).MaximumLength(128).When(p => !string.IsNullOrEmpty(p.Email)).WithMessage(p => localizer["Form.Email.LengthInvalid"]);
|
||||
RuleFor(p => p.Password).NotEmpty().WithMessage("请输入登录密码");
|
||||
RuleFor(p => p.Password).Length(6, 32).When(p => !string.IsNullOrEmpty(p.Password)).WithMessage("登录密码必须在6-32位长度之间");
|
||||
//RuleFor(p => p.ConfirmPassword).NotEmpty().WithMessage(p => localizer["Form.ConfirmPassword.Empty"]);
|
||||
//RuleFor(p => p.ConfirmPassword).Equal(p => p.Password).When(p => !string.IsNullOrEmpty(p.Password) && !string.IsNullOrEmpty(p.ConfirmPassword)).WithMessage(p => localizer["Form.ConfirmPassword.Different"]);
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<LoginModel>.CreateWithOptions((LoginModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class ManufacturerModelValidator : AbstractValidator<ManufacturerModel>
|
||||
{
|
||||
public ManufacturerModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<ManufacturerModel>.CreateWithOptions((ManufacturerModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Common.Entities;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class MaterialBatchValidator : AbstractValidator<MaterialBatch>
|
||||
{
|
||||
public MaterialBatchValidator()
|
||||
{
|
||||
RuleFor(p => p.Price).NotEmpty().WithMessage("价格不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Common.Entities;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class MaterialRecordValidator : AbstractValidator<MaterialRecord>
|
||||
{
|
||||
public MaterialRecordValidator()
|
||||
{
|
||||
RuleFor(p => p.UserId).NotEmpty().WithMessage("名称不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Common.Entities;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class MaterialValidator : AbstractValidator<Material>
|
||||
{
|
||||
public MaterialValidator()
|
||||
{
|
||||
//RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using Atomx.Common.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class MenuModelValidator : AbstractValidator<MenuModel>
|
||||
{
|
||||
public MenuModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
|
||||
}
|
||||
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<MenuModel>.CreateWithOptions((MenuModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class MessageTemplateModelValidator : AbstractValidator<MessageTemplateModel>
|
||||
{
|
||||
public MessageTemplateModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("消息模板名称不能为空");
|
||||
RuleFor(p => p.Title).NotEmpty().WithMessage("消息模板标题不能为空");
|
||||
RuleFor(p => p.Key).NotEmpty().WithMessage("消息模板KEY不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class ProductAddStockModelValidator : AbstractValidator<ProductAddStockModel>
|
||||
{
|
||||
public ProductAddStockModelValidator()
|
||||
{
|
||||
//RuleFor(p => p.Username).NotEmpty().WithMessage("用户名不能为空");
|
||||
//RuleFor(p => p.Username).Length(2, 64).When(p => !string.IsNullOrEmpty(p.Username)).WithMessage("用户名长度必须再2-64个字符之间");
|
||||
//RuleFor(p => p.Password).NotEmpty().When(p => p.Id == 0).WithMessage("登录密码不能为空");
|
||||
//RuleFor(p => p.Password).Length(6, 32).When(p => !string.IsNullOrEmpty(p.Password)).WithMessage("登录密码长度必须在6-32个字符之间");
|
||||
//RuleFor(p => p.Email).EmailAddress().When(p => !string.IsNullOrEmpty(p.Email)).WithMessage("请填写你常用的邮箱地址");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class ProductAttributeModelValidator : AbstractValidator<ProductAttributeModel>
|
||||
{
|
||||
public ProductAttributeModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
|
||||
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");
|
||||
RuleFor(p => p.CategoryId).GreaterThan(0).WithMessage("请设置属性归属分类");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<ProductAttributeModel>.CreateWithOptions((ProductAttributeModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class ProductAttributeOptionModelValidator : AbstractValidator<ProductAttributeOptionModel>
|
||||
{
|
||||
public ProductAttributeOptionModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Value).NotEmpty().WithMessage("数值不能为空");
|
||||
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<ProductAttributeOptionModel>.CreateWithOptions((ProductAttributeOptionModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class RoleModelValidator : AbstractValidator<RoleModel>
|
||||
{
|
||||
public RoleModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("角色名称不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Atomx.Admin/Atomx.Admin.Client/Validators/RoleValidator.cs
Normal file
13
Atomx.Admin/Atomx.Admin.Client/Validators/RoleValidator.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Atomx.Common.Entities;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class RoleValidator : AbstractValidator<Role>
|
||||
{
|
||||
public RoleValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("角色名称不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class SiteAppModelValidator : AbstractValidator<SiteAppModel>
|
||||
{
|
||||
public SiteAppModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("请填写网站应用名称");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class SpecificationAttributeModelValidator : AbstractValidator<SpecificationAttributeModel>
|
||||
{
|
||||
public SpecificationAttributeModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
|
||||
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<SpecificationAttributeModel>.CreateWithOptions((SpecificationAttributeModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class SpecificationAttributeOptionModelValidator : AbstractValidator<SpecificationAttributeOptionModel>
|
||||
{
|
||||
public SpecificationAttributeOptionModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Value).NotEmpty().WithMessage("数值不能为空");
|
||||
RuleFor(p => p.Status).GreaterThan(0).WithMessage("请设置正确的状态");
|
||||
}
|
||||
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<SpecificationAttributeOptionModel>.CreateWithOptions((SpecificationAttributeOptionModel)model, x => { x.IncludeProperties(propertyName); }));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class UploadFileModelValidator : AbstractValidator<UploadFileModel>
|
||||
{
|
||||
public UploadFileModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("文件名称不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Atomx.Admin/Atomx.Admin.Client/Validators/UserValidator.cs
Normal file
13
Atomx.Admin/Atomx.Admin.Client/Validators/UserValidator.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Atomx.Common.Entities;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class UserValidator : AbstractValidator<User>
|
||||
{
|
||||
public UserValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("名称不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Atomx.Admin.Client.Validators
|
||||
{
|
||||
public class WarehouseModelValidator : AbstractValidator<WarehouseModel>
|
||||
{
|
||||
public WarehouseModelValidator()
|
||||
{
|
||||
RuleFor(p => p.Name).NotEmpty().WithMessage("用户名不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user