Exemplo n.º 1
0
        protected override async Task HandleCore(DeleteApprenticeshipCommand command)
        {
            LogMessage(command);

            var validationResult = _validator.Validate(command);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }

            var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(command.ApprenticeshipId);

            if (apprenticeship == null)
            {
                throw new ResourceNotFoundException();
            }

            var commitment = await _commitmentRepository.GetCommitmentById(apprenticeship.CommitmentId);

            CheckAuthorization(command, apprenticeship);
            CheckCommitmentStatus(command, commitment);
            CheckEditStatus(command, commitment);
            CheckPaymentStatus(apprenticeship);

            await Task.WhenAll(
                _apprenticeshipRepository.DeleteApprenticeship(command.ApprenticeshipId),
                _apprenticeshipEvents.PublishDeletionEvent(commitment, apprenticeship, "APPRENTICESHIP-DELETED"),
                CreateHistory(commitment, command.Caller.CallerType, command.UserId, command.UserName)
                );
        }
Exemplo n.º 2
0
        protected override async Task HandleCore(DeleteApprenticeshipCommand command)
        {
            LogMessage(command);

            var validationResult = _validator.Validate(command);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }

            var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(command.ApprenticeshipId);

            if (apprenticeship == null)
            {
                throw new ResourceNotFoundException();
            }

            var commitment = await _commitmentRepository.GetCommitmentById(apprenticeship.CommitmentId);

            var transferRejected = commitment.TransferApprovalStatus == TransferApprovalStatus.TransferRejected;

            CheckAuthorization(command, apprenticeship);
            CheckCommitmentStatus(command, commitment);
            CheckEditStatus(command, commitment);
            CheckPaymentStatus(apprenticeship);

            StartTrackingHistory(commitment, command.Caller.CallerType, command.UserId, command.UserName);

            await _apprenticeshipRepository.DeleteApprenticeship(command.ApprenticeshipId);

            await Task.WhenAll(
                ResetCommitmentProperties(commitment),
                _apprenticeshipEvents.PublishDeletionEvent(commitment, apprenticeship, "APPRENTICESHIP-DELETED"),
                PublishApprenticeshipUpdateEvents(commitment, apprenticeship, transferRejected),
                _v2EventsPublisher.PublishApprenticeshipDeleted(commitment, apprenticeship),
                _historyService.Save()
                );
        }