/// <summary> ///异步验证 /// </summary> public static async Task DoValidationAsync(IEmployeeMenuRespository employeeMenuRespository, EmployeeMenu employeeMenu, string validatorType) { var employeeMenuValidator = new EmployeeMenuValidator(employeeMenuRespository); var validatorReresult = await employeeMenuValidator.DoValidateAsync(employeeMenu, validatorType); if (!validatorReresult.IsValid) { throw new DomainException(validatorReresult); } }
public EmployeeMenuValidator(IEmployeeMenuRespository employeeMenuRespository) { RuleSet(ValidatorTypeConstants.Create, () => { BaseValidator(); }); RuleSet(ValidatorTypeConstants.Modify, () => { BaseValidator(); }); }
/// <summary> ///异步验证 /// </summary> public static async Task DoValidationAsync(IEmployeeMenuRespository employeeMenuRespository, IEnumerable <EmployeeMenu> employeeMenus, string validatorType) { var employeeMenuValidator = new EmployeeMenuValidator(employeeMenuRespository); var domainException = new DomainException(); foreach (var employeeMenu in employeeMenus) { var validatorReresult = await employeeMenuValidator.DoValidateAsync(employeeMenu, validatorType); if (!validatorReresult.IsValid) { domainException.AddErrors(validatorReresult); } } if (domainException.ValidationErrors.ErrorItems.Any()) { throw domainException; } }
public EmployeeMenuAppService(IEmployeeMenuRespository employeeMenuRespository, IMapper mapper) { _employeeMenuRespository = employeeMenuRespository; _mapper = mapper; }