Exemple #1
0
        public async Task GenerateSurveyInvites(GenerateSurveyCodeMessage message)
        {
            var feedbackId = await _employerEmailDetailRepository.UpsertIntoFeedback(message.UserRef, message.AccountId, message.Ukprn);

            _logger.LogInformation("Done upserting feedback");

            if (await IsNewSurveyCodeRequired(feedbackId))
            {
                await _employerEmailDetailRepository.InsertNewSurveyForFeedback(feedbackId);

                _logger.LogInformation($"Generated New Survey Code for feedbackId : {feedbackId} ");
            }
        }
Exemple #2
0
        public async Task SubmitConfirmedEmployerFeedback(SurveyModel surveyModel)
        {
            var employerFeedback = await _employerFeedbackRepository.GetEmployerFeedbackRecord(surveyModel.UserRef, surveyModel.AccountId, surveyModel.Ukprn);

            long feedbackId = 0;

            if (null == employerFeedback)
            {
                feedbackId = await _employerFeedbackRepository.UpsertIntoFeedback(surveyModel.UserRef, surveyModel.AccountId, surveyModel.Ukprn);
            }
            else
            {
                feedbackId = employerFeedback.FeedbackId;
            }

            if (feedbackId == default(long))
            {
                throw new InvalidOperationException($"Unable to find or create feedback record");
            }

            try
            {
                var providerAttributes = await ConvertSurveyToProviderAttributes(surveyModel);

                var feedbackSource = ProvideFeedback.Data.Enums.FeedbackSource.AdHoc;
                if (surveyModel.UniqueCode.HasValue)
                {
                    feedbackSource = ProvideFeedback.Data.Enums.FeedbackSource.Email;
                }

                var employerFeedbackResultId =
                    await _employerFeedbackRepository.CreateEmployerFeedbackResult(
                        feedbackId,
                        surveyModel.Rating.Value.GetDisplayName(),
                        DateTime.UtcNow,
                        feedbackSource,
                        providerAttributes);

                if (null != surveyModel.UniqueCode && surveyModel.UniqueCode.HasValue)
                {
                    // Email journey. Burn the survey code.
                    await _employerFeedbackRepository.SetCodeBurntDate(surveyModel.UniqueCode.Value);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to submit feedback");
            }
        }