AddQuestionDtoValidator.cs 1.4 KB

12345678910111213141516171819202122232425262728
  1. using Exam.Infrastructure.Extensions;
  2. using FluentValidation;
  3. using Hotline.Exams.Questions;
  4. using Hotline.Exams.Validate;
  5. using Hotline.Share.Dtos.Questions;
  6. namespace Hotline.Validators.Exams
  7. {
  8. public class AddQuestionDtoValidator:AbstractValidator<AddQuestionDto>
  9. {
  10. public AddQuestionDtoValidator()
  11. {
  12. RuleFor(m => m.Title).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Title))));
  13. RuleFor(m => m.DifficultyLevel).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.DifficultyLevel))));
  14. RuleFor(m => m.FormalEnable).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.FormalEnable))));
  15. RuleFor(m => m.SimulateEnable).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.SimulateEnable))));
  16. RuleForEach(m => m.QuestionSourcewareDtos).SetValidator(new AddQuestionSourcewareDtoValidator());
  17. RuleForEach(m => m.QuestionKnowladgeDtos).SetValidator(new AddQuestionKnowladgeDtoValidator());
  18. RuleForEach(m => m.QuestionTagDtos).SetValidator(new AddQuestionTagDtoValidator());
  19. RuleForEach(m => m.QuestionOptionsDtos).SetValidator(new AddQuestionOptionsDtoValidator());
  20. }
  21. }
  22. }