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))); }
private void AddApprenticeshipUpdatedEvent(Commitment commitment, Apprenticeship apprenticeship, IEnumerable <ApprenticeshipResult> existingApprenticeships) { var effectiveFromDate = DetermineEffectiveFromDate(apprenticeship.AgreementStatus, existingApprenticeships, apprenticeship.StartDate); _apprenticeshipEventsList.Add(commitment, apprenticeship, "APPRENTICESHIP-AGREEMENT-UPDATED", effectiveFromDate); }
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); } }