示例#1
0
        public async Task <DomainValidationResult <IChallenge> > DeleteChallengeAsync(IChallenge challenge, CancellationToken cancellationToken = default)
        {
            var result = new DomainValidationResult <IChallenge>();

            if (!challenge.CanDelete())
            {
                result.AddFailedPreconditionError("Challenge can't be deleted.");
            }

            if (result.IsValid)
            {
                _challengeRepository.Delete(challenge);

                await _challengeRepository.CommitAsync(true, cancellationToken);

                return(challenge.Cast <Challenge>());
            }

            return(result);
        }
示例#2
0
        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);
        }
示例#3
0
        public async Task <DomainValidationResult <IChallenge> > SynchronizeChallengeAsync(
            IChallenge challenge,
            IDateTimeProvider synchronizedAt,
            CancellationToken cancellationToken = default
            )
        {
            var result = new DomainValidationResult <IChallenge>();

            if (!challenge.CanSynchronize())
            {
                result.AddFailedPreconditionError("Challenge wasn't synchronized due to is current state.");
            }

            if (result.IsValid)
            {
                challenge.Synchronize(synchronizedAt);

                await _challengeRepository.CommitAsync(true, cancellationToken);

                return(challenge.Cast <Challenge>());
            }

            return(result);
        }