|
@@ -1,14 +1,18 @@
|
|
using Exam.Infrastructure.Extensions;
|
|
using Exam.Infrastructure.Extensions;
|
|
using Exam.Infrastructure.Validation.Validation;
|
|
using Exam.Infrastructure.Validation.Validation;
|
|
|
|
+using Exam.Repository.Sqlsugar.Repositories.Trains;
|
|
using Exam.Trains;
|
|
using Exam.Trains;
|
|
using FluentValidation;
|
|
using FluentValidation;
|
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Interfaces.Trains;
|
|
using Hotline.Repository.SqlSugar.Validate;
|
|
using Hotline.Repository.SqlSugar.Validate;
|
|
|
|
|
|
namespace Exam.Repository.Sqlsugar.Validators.Trains
|
|
namespace Exam.Repository.Sqlsugar.Validators.Trains
|
|
{
|
|
{
|
|
public class TrainTemplateValidator:BaseValidator<TrainTemplate>
|
|
public class TrainTemplateValidator:BaseValidator<TrainTemplate>
|
|
{
|
|
{
|
|
- public TrainTemplateValidator()
|
|
|
|
|
|
+ private readonly ITrainTemplateRepository _trainTemplateRepository;
|
|
|
|
+
|
|
|
|
+ public TrainTemplateValidator(ITrainTemplateRepository trainTemplateRepository)
|
|
{
|
|
{
|
|
RuleSet(ValidatorTypeConstants.Create, () =>
|
|
RuleSet(ValidatorTypeConstants.Create, () =>
|
|
{
|
|
{
|
|
@@ -23,6 +27,7 @@ namespace Exam.Repository.Sqlsugar.Validators.Trains
|
|
|
|
|
|
ValidateRuleWithModify();
|
|
ValidateRuleWithModify();
|
|
});
|
|
});
|
|
|
|
+ this._trainTemplateRepository = trainTemplateRepository;
|
|
}
|
|
}
|
|
|
|
|
|
protected override void BaseValidateRule()
|
|
protected override void BaseValidateRule()
|
|
@@ -34,12 +39,16 @@ namespace Exam.Repository.Sqlsugar.Validators.Trains
|
|
{
|
|
{
|
|
base.ValidateRuleWithAdd();
|
|
base.ValidateRuleWithAdd();
|
|
RuleFor(m => m.CreationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(TrainTemplate.CreationTime))));
|
|
RuleFor(m => m.CreationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(TrainTemplate.CreationTime))));
|
|
|
|
+ RuleFor(m => m.Name).Must(v => !_trainTemplateRepository.Queryable().Any(x => x.Name == v)).WithMessage(x => string.Format(ErrorMessage.IsRepeat, x.GetType().GetDescription(nameof(TrainPlan.Name))));
|
|
|
|
+ RuleFor(m => m.Code).Must(v => !_trainTemplateRepository.Queryable().Any(x => x.Code == v)).WithMessage(x => string.Format(ErrorMessage.IsRepeat, x.GetType().GetDescription(nameof(TrainPlan.Code))));
|
|
}
|
|
}
|
|
|
|
|
|
protected override void ValidateRuleWithModify()
|
|
protected override void ValidateRuleWithModify()
|
|
{
|
|
{
|
|
base.ValidateRuleWithModify();
|
|
base.ValidateRuleWithModify();
|
|
RuleFor(m => m.LastModificationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(TrainTemplate.LastModificationTime))));
|
|
RuleFor(m => m.LastModificationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(TrainTemplate.LastModificationTime))));
|
|
|
|
+ RuleFor(m => m.Name).Must((t, v) => !_trainTemplateRepository.Queryable().Any(x => x.Name == v && x.Id != t.Id)).WithMessage(x => string.Format(ErrorMessage.IsRepeat, x.GetType().GetDescription(nameof(TrainPlan.Name))));
|
|
|
|
+ RuleFor(m => m.Code).Must((t, v) => !_trainTemplateRepository.Queryable().Any(x => x.Code == v && x.Id != t.Id)).WithMessage(x => string.Format(ErrorMessage.IsRepeat, x.GetType().GetDescription(nameof(TrainPlan.Code))));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|