public async Task UpdateAccountUsers(GroupedFeedbackRefreshMessage message)
        {
            _logger.LogInformation("Starting upserting user");

            var user = message.RefreshMessages.First().User;
            await _dbRepository.UpsertIntoUsers(user);

            _logger.LogInformation("Done upserting user");
        }
        public async Task <IActionResult> ProviderConfirmed(ProviderSearchConfirmationViewModel postedModel)
        {
            if (!postedModel.Confirmed.HasValue)
            {
                ModelState.AddModelError("Confirmation", "Please choose an option");
                return(View("ConfirmProvider", postedModel));
            }

            if (!postedModel.Confirmed.Value)
            {
                return(RedirectToAction("Index"));
            }

            var providerAttributes = await _employerEmailDetailsRepository.GetAllAttributes();

            if (providerAttributes == null)
            {
                _logger.LogError($"Unable to load Provider Attributes from the database.");
                return(RedirectToAction("Error", "Error"));
            }

            var providerAttributesModel = providerAttributes.Select(s => new ProviderAttributeModel {
                Name = s.AttributeName
            }).ToList();

            var idClaim = HttpContext.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);

            if (null == idClaim)
            {
                _logger.LogError($"User id not found in user claims.");
                return(RedirectToAction("Error", "Error"));
            }

            var newSurveyModel = new SurveyModel
            {
                AccountId    = _encodingService.Decode(postedModel.EncodedAccountId, EncodingType.AccountId),
                Ukprn        = postedModel.ProviderId,
                UserRef      = new Guid(idClaim?.Value),
                Submitted    = false, //employerEmailDetail.CodeBurntDate != null,
                ProviderName = postedModel.ProviderName,
                Attributes   = providerAttributesModel
            };

            await _sessionService.Set(idClaim.Value, newSurveyModel);

            // Make sure the user exists.
            var emailAddressClaim = HttpContext.User.FindFirst(CLAIMTYPE_EMAILADDRESS);
            var firstNameClaim    = HttpContext.User.FindFirst(CLAIMTYPE_FIRSTNAME);
            var user = new User()
            {
                UserRef      = new Guid(idClaim?.Value),
                EmailAddress = emailAddressClaim?.Value,
                FirstName    = firstNameClaim?.Value,
            };
            await _employerEmailDetailsRepository.UpsertIntoUsers(user);

            // Make sure the provider exists and is active.
            await _trainingProviderService.UpsertTrainingProvider(newSurveyModel.Ukprn, newSurveyModel.ProviderName);

            return(RedirectToAction("Index", "Home"));
        }