Example #1
0
        public async Task <IActionResult> Index(Guid uniqueCode)
        {
            var idClaim = HttpContext.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);    //System.Security.Claims.ClaimTypes.NameIdentifier

            var employerEmailDetail = await _employerEmailDetailsRepository.GetEmployerInviteForUniqueCode(uniqueCode);

            if (employerEmailDetail == null)
            {
                _logger.LogWarning($"Attempt to use invalid unique code: {uniqueCode}");
                return(NotFound());
            }

            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
            });
            var newSurveyModel = MapToNewSurveyModel(employerEmailDetail, providerAttributesModel);

            newSurveyModel.UniqueCode = uniqueCode;
            await _sessionService.Set(idClaim.Value, newSurveyModel);

            var encodedAccountId = _encodingService.Encode(employerEmailDetail.AccountId, EncodingType.AccountId);

            return(RedirectToRoute(RouteNames.Landing_Get_New, new { encodedAccountId = encodedAccountId }));
        }
Example #2
0
        private async Task <IEnumerable <ProviderAttribute> > ConvertSurveyToProviderAttributes(SurveyModel surveyModel)
        {
            var feedbackQuestionAttributes = await _employerFeedbackRepository.GetAllAttributes();

            var providerAttributes = new List <ProviderAttribute>();

            foreach (var attribute in surveyModel.Attributes.Where(s => s.Good || s.Bad))
            {
                var providerAttribute = feedbackQuestionAttributes.FirstOrDefault(s => s.AttributeName == attribute.Name);
                if (providerAttribute != null)
                {
                    providerAttributes.Add(new ProviderAttribute
                    {
                        AttributeId    = providerAttribute.AttributeId,
                        AttributeValue = attribute.Score,
                    });
                }
            }

            return(providerAttributes);
        }
        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"));
        }