|
@@ -2,13 +2,16 @@ using Exam.Infrastructure.Extensions;
|
|
|
using Exam.Infrastructure.Validation.Validation;
|
|
|
using Exam.Trains;
|
|
|
using FluentValidation;
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Interfaces.Trains;
|
|
|
using Hotline.Repository.SqlSugar.Validate;
|
|
|
|
|
|
namespace Exam.Repository.Sqlsugar.Validators.Trains
|
|
|
{
|
|
|
public class TrainPlanValidator:BaseValidator<TrainPlan>
|
|
|
{
|
|
|
- public TrainPlanValidator()
|
|
|
+ private readonly ITrainPlanRepository _trainPlanRepository;
|
|
|
+
|
|
|
+ public TrainPlanValidator(ITrainPlanRepository trainPlanRepository)
|
|
|
{
|
|
|
RuleSet(ValidatorTypeConstants.Create, () =>
|
|
|
{
|
|
@@ -23,6 +26,7 @@ namespace Exam.Repository.Sqlsugar.Validators.Trains
|
|
|
|
|
|
ValidateRuleWithModify();
|
|
|
});
|
|
|
+ this._trainPlanRepository = trainPlanRepository;
|
|
|
}
|
|
|
|
|
|
protected override void BaseValidateRule()
|
|
@@ -34,12 +38,18 @@ namespace Exam.Repository.Sqlsugar.Validators.Trains
|
|
|
{
|
|
|
base.ValidateRuleWithAdd();
|
|
|
RuleFor(m => m.CreationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(TrainPlan.CreationTime))));
|
|
|
+ RuleFor(m => m.Name).Must((t, v) => !_trainPlanRepository.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(v =>!_trainPlanRepository.Queryable().Any(x=>x.Code == v)).WithMessage(x => string.Format(ErrorMessage.IsRepeat, x.GetType().GetDescription(nameof(TrainPlan.Code))));
|
|
|
}
|
|
|
|
|
|
protected override void ValidateRuleWithModify()
|
|
|
{
|
|
|
base.ValidateRuleWithModify();
|
|
|
RuleFor(m => m.LastModificationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(TrainPlan.LastModificationTime))));
|
|
|
+ RuleFor(m => m.Name).Must((t, v) => !_trainPlanRepository.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) => !_trainPlanRepository.Queryable().Any(x => x.Code == v && x.Id!=t.Id)).WithMessage(x => string.Format(ErrorMessage.IsRepeat, x.GetType().GetDescription(nameof(TrainPlan.Code))));
|
|
|
|
|
|
}
|
|
|
|