public async Task <DomainValidationResult <IChallenge> > CloseChallengeAsync( IChallenge challenge, IDateTimeProvider provider, CancellationToken cancellationToken = default ) { var result = new DomainValidationResult <IChallenge>(); if (!challenge.CanClose()) { result.AddFailedPreconditionError("Challenge can't be closed."); } if (result.IsValid) { challenge.Close(provider); await _challengeRepository.CommitAsync(true, cancellationToken); return(challenge.Cast <Challenge>()); } return(result); }