public DocumentModelValidator(IModulesService modulesService) { RuleFor(doc => doc.CandidateId).NotEmpty().WithMessage(ResponseMessageCodes.EmptyRequiredAttribute); RuleFor(doc => doc.Filename).NotEmpty().WithMessage(ResponseMessageCodes.EmptyRequiredAttribute); CustomAsync(async doc => { try { if ((doc.ReviewerId == null || doc.ReviewerId == default(Guid)) && await modulesService.IsActive(Modules.AccountManagement)) { return(new ValidationFailure("ReviewerId", ResponseMessageCodes.EmptyRequiredAttribute)); } } catch (IncompleteRequest) { return(new ValidationFailure("", ResponseMessageCodes.IncompleteRequest)); } return(null); }); }