12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using Exam.ExamManages;
- using Exam.Infrastructure.Extensions;
- using Exam.Infrastructure.Validation.Validation;
- using FluentValidation;
- using Hotline.Repository.SqlSugar.Exam.Core.Constants;
- using Hotline.Repository.SqlSugar.Exam.Interfaces.ExamManages;
- using Hotline.Repository.SqlSugar.Validate;
- namespace Exam.Repository.Sqlsugar.Validators.ExamManages
- {
- public class UserExamValidator:BaseValidator<UserExam>
- {
- private readonly IUserExamRepository _userExamRepository;
- public UserExamValidator(IUserExamRepository userExamRepository)
- {
- RuleSet(ValidatorTypeConstants.Create, () =>
- {
- BaseValidateRule();
- ValidateRuleWithAdd();
- });
- RuleSet(ValidatorTypeConstants.Modify, () =>
- {
- BaseValidateRule();
- ValidateRuleWithModify();
- });
- RuleSet(ValidatorTypeConstants.Remove, () =>
- {
- ValidateRuleWithRemove();
- });
- this._userExamRepository = userExamRepository;
- }
- protected override void BaseValidateRule()
- {
- base.BaseValidateRule();
- }
- protected override void ValidateRuleWithAdd()
- {
- base.ValidateRuleWithAdd();
- RuleFor(m => m.CreationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(UserExam.CreationTime))));
- }
- protected override void ValidateRuleWithModify()
- {
- base.ValidateRuleWithModify();
- RuleFor(m => m.LastModificationTime).NotEmpty().WithMessage(x => string.Format(ErrorMessage.IsRequired, x.GetType().GetDescription(nameof(UserExam.LastModificationTime))));
- }
- private void ValidateRuleWithRemove()
- {
- RuleFor(m => m.Id).Must(v=>!_userExamRepository.Queryable().Where(x=>x.Id == v && x.ExamStatus != Hotline.Share.Enums.Exams.EExamStatus.NoStart).Any()).WithMessage(ExamErrorMessage.DeleteUnableUserExam);
- }
- }
- }
|