ExamAnswerValidator.cs 1.6 KB

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