public async Task Handle(TransferRequestRejectedEvent message, IMessageHandlerContext context)
        {
            var cohortSummary = await _mediator.Send(new GetCohortSummaryQuery(message.CohortId));

            var cohortReference = _encodingService.Encode(cohortSummary.CohortId, EncodingType.CohortReference);

            var sendEmailToEmployerCommand = new SendEmailToEmployerCommand(cohortSummary.AccountId,
                                                                            "SenderRejectedCommitmentEmployerNotification", new Dictionary <string, string>
            {
                { "employer_name", cohortSummary.LegalEntityName },
                { "cohort_reference", cohortReference },
                { "sender_name", cohortSummary.TransferSenderName },
                { "employer_hashed_account", _encodingService.Encode(cohortSummary.AccountId, EncodingType.AccountId) },
            },
                                                                            cohortSummary.LastUpdatedByEmployerEmail);

            var sendEmailToProviderCommand = new SendEmailToProviderCommand(cohortSummary.ProviderId.Value,
                                                                            "SenderRejectedCommitmentProviderNotification",
                                                                            new Dictionary <string, string>
            {
                { "cohort_reference", cohortReference },
                { "ukprn", cohortSummary.ProviderId.Value.ToString() },
            },
                                                                            cohortSummary.LastUpdatedByProviderEmail);

            await Task.WhenAll(
                context.Send(sendEmailToProviderCommand, new SendOptions()),
                context.Send(sendEmailToEmployerCommand, new SendOptions())
                );
        }
        public Task ProviderAmendedCohort(Commitment commitment)
        {
            var tokens = CreateDictionaryWithCommonTokens(commitment);

            tokens["provider_name"]           = commitment.ProviderName;
            tokens["employer_hashed_account"] = _encodingService.Encode(commitment.EmployerAccountId, EncodingType.AccountId);

            var command = new SendEmailToEmployerCommand(commitment.EmployerAccountId, AmendedTemplate, tokens, commitment.LastUpdatedByEmployerEmail);

            return(SendCommandAndLog(command, $"Provider: {commitment.ProviderId} CohortId: {commitment.Id} LastAction: {commitment.LastAction}"));
        }
        public Task ProviderApprovedCohort(Commitment commitment)
        {
            SendEmailToEmployerCommand command = null;
            var tokens = CreateDictionaryWithCommonTokens(commitment);

            if (commitment.HasTransferSenderAssigned)
            {
                tokens["sender_name"]             = commitment.TransferSenderName;
                tokens["provider_name"]           = commitment.ProviderName;
                tokens["employer_hashed_account"] = _encodingService.Encode(commitment.EmployerAccountId, EncodingType.AccountId);
                command = new SendEmailToEmployerCommand(commitment.EmployerAccountId, ApprovedWithTransferTemplate, tokens, commitment.LastUpdatedByEmployerEmail);
            }
            else
            {
                command = new SendEmailToEmployerCommand(commitment.EmployerAccountId, ApprovedTemplate, tokens, commitment.LastUpdatedByEmployerEmail);
            }

            return(SendCommandAndLog(command, $"Provider: {commitment.ProviderId} CohortId: {commitment.Id} LastAction: {commitment.LastAction}"));
        }
        public async Task Handle(ProviderRejectedChangeOfPartyRequestEvent message, IMessageHandlerContext context)
        {
            var changeOfPartyRequest = await _dbContext.Value.GetChangeOfPartyRequestAggregate(message.ChangeOfPartyRequestId, default);

            if (changeOfPartyRequest.ChangeOfPartyType == ChangeOfPartyRequestType.ChangeProvider)
            {
                var sendEmailCommand = new SendEmailToEmployerCommand(message.EmployerAccountId,
                                                                      "TrainingProviderRejectedChangeOfProviderCohort",
                                                                      new Dictionary <string, string>
                {
                    { "EmployerName", message.EmployerName },
                    { "TrainingProviderName", message.TrainingProviderName },
                    { "ApprenticeNamePossessive", message.ApprenticeName.EndsWith("s") ? message.ApprenticeName + "'" : message.ApprenticeName + "'s" },
                    { "AccountHashedId", _encodingService.Encode(message.EmployerAccountId, EncodingType.AccountId) },
                    { "ApprenticeshipHashedId", _encodingService.Encode(changeOfPartyRequest.ApprenticeshipId, EncodingType.ApprenticeshipId) }
                },
                                                                      message.RecipientEmailAddress
                                                                      );

                await context.Send(sendEmailCommand, new SendOptions());
            }
        }
 public SendEmailToEmployerCommandHandlerTestsFixture SetupNullMessage()
 {
     Command = null;
     return(this);
 }
 public SendEmailToEmployerCommandHandlerTestsFixture SetupCommandWithSpecificEmailAddress(string email)
 {
     Command = new SendEmailToEmployerCommand(AccountId, TemplateId, Tokens, email);
     return(this);
 }
 public SendEmailToEmployerCommandHandlerTestsFixture SetupCommandWithoutEmailAddress()
 {
     Command = new SendEmailToEmployerCommand(AccountId, TemplateId, Tokens);
     return(this);
 }