Beispiel #1
0
 internal async Task PublishApprenticeshipAgreementUpdatedEvents(Commitment commitment)
 {
     Parallel.ForEach(commitment.Apprenticeships, apprenticeship =>
     {
         _apprenticeshipEventsList.Add(commitment, apprenticeship, "APPRENTICESHIP-AGREEMENT-UPDATED");
     });
     await _apprenticeshipEventsPublisher.Publish(_apprenticeshipEventsList);
 }
        private async Task PublishEvents(Apprenticeship apprenticeship)
        {
            var commitment = await _commitmentRepository.GetCommitmentById(apprenticeship.CommitmentId);

            _apprenticeshipEventsList.Add(commitment, apprenticeship, "APPRENTICESHIP-UPDATED", _currentDateTime.Now);

            await _eventsApi.Publish(_apprenticeshipEventsList);
        }
        private async Task PublishEvents(Apprenticeship apprenticeship)
        {
            var commitment = await _commitmentRepository.GetCommitmentById(apprenticeship.CommitmentId);

            _apprenticeshipEventsList.Add(commitment, apprenticeship, "APPRENTICESHIP-UPDATED", _currentDateTime.Now);

            var tasks = _apprenticeshipEventsList.Events.Select(x => _v2EventsPublisher.PublishDataLockTriageApproved(x));
            await Task.WhenAll(tasks);

            await _eventsApi.Publish(_apprenticeshipEventsList);
        }
 private Task PublishEvent(UpdateApprenticeshipStopDateCommand command, Commitment commitment, Apprenticeship apprenticeship)
 {
     _apprenticeshipEventsList.Add(commitment, apprenticeship, "APPRENTICESHIP-UPDATED", command.StopDate);
     return(Task.WhenAll(_eventsPublisher.Publish(_apprenticeshipEventsList), _v2EventsPublisher.PublishApprenticeshipStopDateChanged(commitment, apprenticeship)));
 }
Beispiel #5
0
        protected override async Task HandleCore(UpdateCommitmentAgreementCommand command)
        {
            _validator.ValidateAndThrow(command);

            LogMessage(command);

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

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

            var latestAction = (LastAction)command.LatestAction;

            if (latestAction == LastAction.Approve)
            {
                CheckStateForApproval(commitment, command.Caller);
                var overlaps = await GetOverlappingApprenticeships(commitment);

                if (overlaps.Data.Any())
                {
                    throw new ValidationException("Unable to approve commitment with overlapping apprenticeships");
                }
            }

            var updatedApprenticeships = await UpdateApprenticeshipAgreementStatuses(command, commitment, latestAction);

            var anyApprenticeshipsPendingAgreement = commitment.Apprenticeships.Any(a => a.AgreementStatus != AgreementStatus.BothAgreed);

            await UpdateCommitmentStatuses(command, commitment, anyApprenticeshipsPendingAgreement, latestAction);
            await CreateCommitmentMessage(command, commitment);

            // If final approval
            if (latestAction == LastAction.Approve && commitment.Apprenticeships.Count > 0 &&
                !anyApprenticeshipsPendingAgreement)
            {
                await _apprenticeshipRepository.CreatePriceHistoryForApprenticeshipsInCommitment(commitment.Id);

                //create price history for purposes of event creation
                foreach (var updatedApprenticeship in updatedApprenticeships)
                {
                    updatedApprenticeship.PriceHistory = new List <PriceHistory>
                    {
                        new PriceHistory
                        {
                            ApprenticeshipId = updatedApprenticeship.Id,
                            Cost             = updatedApprenticeship.Cost.Value,
                            FromDate         = updatedApprenticeship.StartDate.Value
                        }
                    };
                }
            }

            await CreateEventsForUpdatedApprenticeships(commitment, updatedApprenticeships);

            await _apprenticeshipEventsPublisher.Publish(_apprenticeshipEventsList);

            if (latestAction == LastAction.Approve && commitment.Apprenticeships.Count > 0 &&
                !anyApprenticeshipsPendingAgreement)
            {
                await _mediator.SendAsync(new SetPaymentOrderCommand { AccountId = commitment.EmployerAccountId });
            }
        }
Beispiel #6
0
        protected override async Task HandleCore(CreateApprenticeshipUpdateCommand command)
        {
            var validationResult = _validator.Validate(command);

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

            if (await _apprenticeshipUpdateRepository.GetPendingApprenticeshipUpdate(command.ApprenticeshipUpdate.ApprenticeshipId) != null)
            {
                throw new ValidationException("Unable to create an ApprenticeshipUpdate for an Apprenticeship with a pending update");
            }

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

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

            if (!ValidateStartedApprenticeship(apprenticeship, command.ApprenticeshipUpdate))
            {
                throw new ValidationException("Unable to create an update for an apprenticeship that is already started ");
            }

            CheckAuthorisation(command, apprenticeship);

            await Task.WhenAll(
                CheckOverlappingApprenticeships(command, apprenticeship),
                CheckReservation(command.ApprenticeshipUpdate, apprenticeship));

            Apprenticeship       immediateUpdate = null;
            ApprenticeshipUpdate pendingUpdate   = null;

            if (HasImmediateUpdate(command))
            {
                StartHistoryTracking(commitment, apprenticeship, command.Caller.CallerType, command.UserId, command.UserName);
                MapImmediateApprenticeshipUpdate(apprenticeship, command);
                immediateUpdate = apprenticeship;
            }

            if (apprenticeship.StartDate == null)
            {
                throw new InvalidOperationException($"The start date on apprenticeship {apprenticeship.Id} is null when calling {nameof(CreateApprenticeshipUpdateCommand)} command handler");
            }

            if (command.ApprenticeshipUpdate.HasChanges)
            {
                pendingUpdate = command.ApprenticeshipUpdate;
                pendingUpdate.EffectiveFromDate = apprenticeship.StartDate.Value;
                await SendApprenticeshipUpdateCreatedEvent(apprenticeship);
            }

            await Task.WhenAll(
                _apprenticeshipUpdateRepository.CreateApprenticeshipUpdate(pendingUpdate, immediateUpdate),
                SaveHistory(),
                _v2EventsPublisher.PublishApprenticeshipUlnUpdatedEvent(immediateUpdate)
                );

            if (command.ApprenticeshipUpdate.ULN != null)
            {
                _apprenticeshipEventsList.Add(commitment, apprenticeship, "APPRENTICESHIP-UPDATED", _currentDateTime.Now);
                await _apprenticeshipEventsPublisher.Publish(_apprenticeshipEventsList);
            }
        }