private async Task PublishLegalGenericEvent(SignEmployerAgreementCommand message, string hashedLegalEntityId) { var agreementEvent = _agreementEventFactory.CreateSignedEvent(message.HashedAccountId, hashedLegalEntityId, message.HashedAgreementId); var genericEvent = _genericEventFactory.Create(agreementEvent); await _mediator.SendAsync(new PublishGenericEventCommand { Event = genericEvent }); }
protected override async Task HandleCore(SignEmployerAgreementCommand message) { var validationResult = await _validator.ValidateAsync(message); if (!validationResult.IsValid()) { throw new InvalidRequestException(validationResult.ValidationDictionary); } var owner = await _membershipRepository.GetCaller(message.HashedAccountId, message.ExternalUserId); if (owner == null || owner.Role != Role.Owner) { throw new UnauthorizedAccessException(); } var agreementId = _hashingService.DecodeValue(message.HashedAgreementId); var signedAgreementDetails = new Models.EmployerAgreement.SignEmployerAgreement { SignedDate = message.SignedDate, AgreementId = agreementId, SignedById = owner.UserId, SignedByName = $"{owner.FirstName} {owner.LastName}" }; await _employerAgreementRepository.SignAgreement(signedAgreementDetails); var accountId = _hashingService.DecodeValue(message.HashedAccountId); await AddAuditEntry(message, accountId, agreementId); var agreement = await _employerAgreementRepository.GetEmployerAgreement(agreementId); await _employerAgreementRepository.EvaluateEmployerLegalEntityAgreementStatus(accountId, agreement.LegalEntityId); var hashedLegalEntityId = _hashingService.HashValue((long)agreement.LegalEntityId); var agreementEvent = _agreementEventFactory.CreateSignedEvent(message.HashedAccountId, hashedLegalEntityId, message.HashedAgreementId); var genericEvent = _genericEventFactory.Create(agreementEvent); await _mediator.SendAsync(new PublishGenericEventCommand { Event = genericEvent }); var commitments = await _commitmentService.GetEmployerCommitments(accountId); var accountHasCommitments = commitments?.Any() ?? false; await PublishAgreementSignedMessage(accountId, agreement.LegalEntityId, agreement.LegalEntityName, agreementId, accountHasCommitments, owner.FullName(), owner.UserRef); await _agreementService.RemoveFromCacheAsync(accountId); }