ExamQuestionAnswerValidator.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Exam.Infrastructure.Extensions;
  2. using Exam.Infrastructure.Validation.Validation;
  3. using FluentValidation;
  4. using Hotline.Exams.ExamManages;
  5. using Hotline.Exams.Validate;
  6. using Hotline.Repository.SqlSugar.Validate;
  7. namespace Hotline.Repository.SqlSugar.Exam.Validators.ExamManages
  8. {
  9. public class ExamQuestionAnswerValidator : BaseValidator<ExamQuestionAnswerBak>
  10. {
  11. public ExamQuestionAnswerValidator()
  12. {
  13. RuleSet(ValidatorTypeConstants.Create, () =>
  14. {
  15. BaseValidateRule();
  16. ValidateRuleWithAdd();
  17. });
  18. RuleSet(ValidatorTypeConstants.Modify, () =>
  19. {
  20. BaseValidateRule();
  21. ValidateRuleWithModify();
  22. });
  23. }
  24. protected override void BaseValidateRule()
  25. {
  26. base.BaseValidateRule();
  27. }
  28. protected override void ValidateRuleWithAdd()
  29. {
  30. base.ValidateRuleWithAdd();
  31. RuleFor(m => m.CreationTime).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestionBak.CreationTime))));
  32. }
  33. protected override void ValidateRuleWithModify()
  34. {
  35. base.ValidateRuleWithModify();
  36. RuleFor(m => m.LastModificationTime).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestionBak.LastModificationTime))));
  37. }
  38. }
  39. }