public async Task Service_sends_email_to_notifications_api_with_tokens_for_template()
        {
            var emailTemplate = new EmailTemplate
            {
                TemplateId   = Guid.NewGuid().ToString(),
                TemplateName = "Template Name",
                Recipients   = "*****@*****.**"
            };

            _emailTemplateClient.Setup(x => x.GetEmailTemplate(It.IsAny <string>())).ReturnsAsync(emailTemplate).Verifiable();

            _notificationsApi.Setup(x => x.SendEmail(It.IsAny <Notifications.Api.Types.Email>())).Verifiable();

            var getHelpWithQuestion = new GetHelpWithQuestion
            {
                ApplicantFullName   = "Mrs Test Person",
                ApplicationSection  = "Your org",
                ApplicationSequence = "Preamble",
                EmailAddress        = "*****@*****.**",
                GetHelpQuery        = "Help! I need somebody",
                OrganisationName    = "Test Org",
                PageTitle           = "Provider route",
                UKPRN = "10002000"
            };

            await _service.SendGetHelpWithQuestionEmail(getHelpWithQuestion);

            _emailTemplateClient.VerifyAll();
            _notificationsApi.VerifyAll();
        }
        public async Task SendGetHelpWithQuestionEmail(GetHelpWithQuestion getHelpWithQuestion)
        {
            var emailTemplate = await _emailTemplateClient.GetEmailTemplate(EmailTemplateName.ROATP_GET_HELP_WITH_QUESTION);

            var personalisationTokens = GetPersonalisationTokens(getHelpWithQuestion);

            await SendEmail(emailTemplate.TemplateName, emailTemplate.Recipients, getHelpWithQuestion.EmailAddress, SUBJECT, personalisationTokens);
        }
        private Dictionary <string, string> GetPersonalisationTokens(GetHelpWithQuestion getHelpWithQuestion)
        {
            var personalisationTokens = new Dictionary <string, string>
            {
                { "ApplicantEmail", getHelpWithQuestion.EmailAddress },
                { "ApplicantFullName", getHelpWithQuestion.ApplicantFullName },
                { "UKPRN", getHelpWithQuestion.UKPRN },
                { "OrganisationName", getHelpWithQuestion.OrganisationName },
                { "ApplicationSequence", getHelpWithQuestion.ApplicationSequence },
                { "ApplicationSection", getHelpWithQuestion.ApplicationSection },
                { "PageTitle", getHelpWithQuestion.PageTitle },
                { "GetHelpQuery", getHelpWithQuestion.GetHelpQuery }
            };

            return(personalisationTokens);
        }
コード例 #4
0
        public async Task <IActionResult> Index(Guid?applicationId, int sequenceId, int sectionId, string pageId, string title, string getHelp, string controller, string action)
        {
            var getHelpQuery    = new GetHelpWithQuestion();
            var errorMessageKey = string.Format(GetHelpErrorMessageKey, pageId);

            if (string.IsNullOrWhiteSpace(getHelp))
            {
                _sessionService.Set(errorMessageKey, MinLengthErrorMessage);
                var questionKey = string.Format(GetHelpQuestionKey, pageId);
                _sessionService.Set(questionKey, string.Empty);
                return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
            }

            if (getHelp.Length > GetHelpTextMaxLength)
            {
                _sessionService.Set(errorMessageKey, MaxLengthErrorMessage);
                var questionKey = string.Format(GetHelpQuestionKey, pageId);
                _sessionService.Set(questionKey, getHelp);
                return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
            }

            if (applicationId.HasValue && applicationId.Value != Guid.Empty)
            {
                if (sequenceId > 0 && sectionId > 0)
                {
                    var page = await _qnaApiClient.GetPageBySectionNo(applicationId.Value, sequenceId, sectionId, pageId);

                    if (page == null || string.IsNullOrEmpty(page.Title))
                    {
                        getHelpQuery.PageTitle = title;
                    }
                    else
                    {
                        getHelpQuery.PageTitle = page.Title;
                    }

                    var sequenceConfig = _taskListConfiguration.FirstOrDefault(x => x.Id == sequenceId);
                    if (sequenceConfig != null)
                    {
                        getHelpQuery.ApplicationSequence = sequenceConfig.Title;
                    }

                    var currentSection = await _qnaApiClient.GetSectionBySectionNo(applicationId.Value, sequenceId, sectionId);

                    if (currentSection != null)
                    {
                        getHelpQuery.ApplicationSection = currentSection.Title;
                    }
                }
                else
                {
                    getHelpQuery.PageTitle           = title;
                    getHelpQuery.ApplicationSequence = "Not available";
                    getHelpQuery.ApplicationSection  = "Not available";
                }

                var organisationName = await _qnaApiClient.GetAnswerByTag(applicationId.Value, RoatpWorkflowQuestionTags.UkrlpLegalName);

                if (organisationName != null && !string.IsNullOrWhiteSpace(organisationName.Value))
                {
                    getHelpQuery.OrganisationName = organisationName.Value;
                }
                else
                {
                    getHelpQuery.OrganisationName = "Not available";
                }

                var organisationUKPRN = await _qnaApiClient.GetAnswerByTag(applicationId.Value, RoatpWorkflowQuestionTags.UKPRN);

                if (organisationUKPRN != null && !string.IsNullOrWhiteSpace(organisationUKPRN.Value))
                {
                    getHelpQuery.UKPRN = organisationUKPRN.Value;
                }
                else
                {
                    getHelpQuery.UKPRN = "Not available";
                }
            }
            else
            {
                // in preamble so we don't have an application set up yet
                var applicationDetails = _sessionService.Get <ApplicationDetails>(ApplicationDetailsKey);
                getHelpQuery.PageTitle           = title;
                getHelpQuery.ApplicationSequence = "Preamble";
                getHelpQuery.ApplicationSection  = "Preamble";
                var ukprn = applicationDetails?.UKPRN.ToString();
                if (string.IsNullOrWhiteSpace(ukprn))
                {
                    ukprn = "Not available";
                }
                getHelpQuery.UKPRN = ukprn;
                var organisationName = applicationDetails?.UkrlpLookupDetails?.ProviderName;
                if (string.IsNullOrWhiteSpace(organisationName))
                {
                    organisationName = "Not available";
                }
                getHelpQuery.OrganisationName = organisationName;
            }

            getHelpQuery.GetHelpQuery = getHelp;

            var userDetails = await _usersApiClient.GetUserBySignInId(User.GetSignInId());

            getHelpQuery.EmailAddress      = userDetails.Email;
            getHelpQuery.ApplicantFullName = $"{userDetails.GivenNames} {userDetails.FamilyName}";

            await _emailService.SendGetHelpWithQuestionEmail(getHelpQuery);

            var sessionKey = string.Format(GetHelpSubmittedForPageKey, pageId);

            _sessionService.Set(sessionKey, true);
            _sessionService.Set(errorMessageKey, string.Empty);

            return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
        }
コード例 #5
0
        public async Task <IActionResult> Index(Guid?applicationId, int sequenceId, int sectionId, string pageId, string title, string getHelp, string controller, string action)
        {
            var errorMessageKey = string.Format(GetHelpErrorMessageKey, pageId);

            if (string.IsNullOrWhiteSpace(getHelp))
            {
                _sessionService.Set(errorMessageKey, MinLengthErrorMessage);
                var questionKey = string.Format(GetHelpQuestionKey, pageId);
                _sessionService.Set(questionKey, string.Empty);
                return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
            }

            if (getHelp.Length > GetHelpTextMaxLength)
            {
                _sessionService.Set(errorMessageKey, MaxLengthErrorMessage);
                var questionKey = string.Format(GetHelpQuestionKey, pageId);
                _sessionService.Set(questionKey, getHelp);
                return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
            }

            var sequenceConfig = _taskListConfiguration.FirstOrDefault(x => x.Id == sequenceId);
            var getHelpQuery   = new GetHelpWithQuestion
            {
                ApplicationSequence = sequenceConfig?.Title ?? $"Not available (Sequence {sequenceId})",
                ApplicationSection  = $"Not available (Section {sectionId}))",
                PageTitle           = title ?? action,
                OrganisationName    = "Not available",
                UKPRN         = "Not available",
                CompanyNumber = "Not available",
                CharityNumber = "Not available",
            };

            if (applicationId.HasValue && applicationId.Value != Guid.Empty)
            {
                try
                {
                    var qnaApplicationData = await _qnaApiClient.GetApplicationData(applicationId.Value);

                    var organisationName = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UkrlpLegalName)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationName))
                    {
                        getHelpQuery.OrganisationName = organisationName;
                    }

                    var organisationUKPRN = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKPRN)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationUKPRN))
                    {
                        getHelpQuery.UKPRN = organisationUKPRN;
                    }

                    var organisationCompanyNumber = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKRLPVerificationCompanyNumber)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationCompanyNumber))
                    {
                        getHelpQuery.CompanyNumber = organisationCompanyNumber;
                    }

                    var organisationCharityNumber = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKRLPVerificationCharityRegNumber)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationCharityNumber))
                    {
                        getHelpQuery.CharityNumber = organisationCharityNumber;
                    }

                    var currentSection = await _qnaApiClient.GetSectionBySectionNo(applicationId.Value, sequenceId, sectionId);

                    if (!string.IsNullOrEmpty(currentSection?.Title))
                    {
                        getHelpQuery.ApplicationSection = currentSection.Title;
                    }

                    var currentPage = currentSection?.QnAData.Pages.FirstOrDefault(pg => pg.PageId == pageId);
                    if (!string.IsNullOrEmpty(currentPage?.Title))
                    {
                        getHelpQuery.PageTitle = currentPage.Title;
                    }
                }
                catch (ApplyService.Infrastructure.Exceptions.ApiClientException apiEx)
                {
                    // Safe to ignore any QnA issues. We just want to send help with as much info as possible.
                    _logger.LogError(apiEx, $"Unable to retrieve QNA details for application : {applicationId.Value}");
                }
                catch (NullReferenceException nullRefEx)
                {
                    // Safe to ignore any QnA issues. We just want to send help with as much info as possible.
                    _logger.LogError(nullRefEx, $"QNA details were not found for application: {applicationId.Value}");
                }
            }
            else
            {
                // in preamble so we don't have an application set up yet
                getHelpQuery.ApplicationSequence = "Preamble";
                getHelpQuery.ApplicationSection  = "Preamble";

                var applicationDetails = _sessionService.Get <ApplicationDetails>(ApplicationDetailsKey);

                if (applicationDetails != null)
                {
                    getHelpQuery.UKPRN = applicationDetails.UKPRN.ToString();

                    var organisationName = applicationDetails.UkrlpLookupDetails?.ProviderName;
                    if (!string.IsNullOrWhiteSpace(organisationName))
                    {
                        getHelpQuery.OrganisationName = organisationName;
                    }

                    var organisationCompanyNumber = applicationDetails.UkrlpLookupDetails?.VerificationDetails?.FirstOrDefault(x => x.VerificationAuthority == Domain.Ukrlp.VerificationAuthorities.CompaniesHouseAuthority)?.VerificationId;
                    if (!string.IsNullOrWhiteSpace(organisationCompanyNumber))
                    {
                        getHelpQuery.CompanyNumber = organisationCompanyNumber;
                    }

                    var organisationCharityNumber = applicationDetails.UkrlpLookupDetails?.VerificationDetails?.FirstOrDefault(x => x.VerificationAuthority == Domain.Ukrlp.VerificationAuthorities.CharityCommissionAuthority)?.VerificationId;
                    if (!string.IsNullOrWhiteSpace(organisationCharityNumber))
                    {
                        getHelpQuery.CharityNumber = organisationCharityNumber;
                    }
                }
            }

            getHelpQuery.GetHelpQuery = getHelp;

            var userDetails = await _usersApiClient.GetUserBySignInId(User.GetSignInId());

            getHelpQuery.EmailAddress      = userDetails.Email;
            getHelpQuery.ApplicantFullName = $"{userDetails.GivenNames} {userDetails.FamilyName}";

            await _emailService.SendGetHelpWithQuestionEmail(getHelpQuery);

            var sessionKey = string.Format(GetHelpSubmittedForPageKey, pageId);

            _sessionService.Set(sessionKey, true);
            _sessionService.Set(errorMessageKey, string.Empty);

            return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
        }