using EntrustSettle.Model.Dtos; using FluentValidation; namespace EntrustSettle.Model.Validator { public class OrderSubmitDtoValidator : AbstractValidator { public OrderSubmitDtoValidator() { RuleFor(x => x.MblnoList).NotEmpty(); RuleFor(x => x.CompanyId).NotNull().NotEmpty(); RuleFor(x => x.CompanyName).NotNull().NotEmpty(); RuleFor(x => x.ServiceType).InclusiveBetween(1, 3).WithMessage("服务类型错误"); RuleFor(x => x.ProjectType).NotNull().NotEmpty().WithMessage("项目类型不能为空"); RuleFor(x => x.ProjectType).Must(x => { if (!string.IsNullOrWhiteSpace(x)) { var projects = x.Split(','); foreach (var project in projects) { if (!int.TryParse(project, out int _)) { return false; } } } return true; }).WithMessage("项目类型错误"); RuleFor(x => x.AnnexIdList).Must(x => x == null || x.Count <= 5).WithMessage("附件数量不能超过5个"); //RuleFor(x => x.Remark).MaximumLength(2000).WithMessage("备注过长"); } } public class FileTypeEnumValidator : AbstractValidator { public FileTypeEnumValidator() { RuleFor(x => x).IsInEnum(); } } public class ChangeStatusDtoValidator : AbstractValidator { public ChangeStatusDtoValidator() { RuleFor(x => x.Status).IsInEnum(); } } }