Beispiel #1
0
        public async Task <VerifySecurityQuestionsResponse> Handle(VerifySecurityQuestionsQuery query)
        {
            IEnumerable <Contact> contacts = Array.Empty <Contact>();

            contacts = (await contactRepository.QueryContact(new ContactQuery {
                ContactId = query.RegistrantId, MaskSecurityAnswers = false
            })).Items;
            VerifySecurityQuestionsResponse ret = new VerifySecurityQuestionsResponse
            {
                NumberOfCorrectAnswers = 0
            };

            if (contacts.Count() == 1)
            {
                Contact contact = contacts.First();
                if (contact.SecurityQuestions != null && contact.SecurityQuestions.Count() > 0)
                {
                    for (int i = 0; i < query.Answers.Count(); ++i)
                    {
                        Shared.Contracts.Submissions.SecurityQuestion question = query.Answers.ElementAt(i);
                        string submittedAnswer = question.Answer;
                        string savedAnswer     = contact.SecurityQuestions.Where(q => q.Id == question.Id).FirstOrDefault().Answer;
                        if (string.Equals(savedAnswer, submittedAnswer, StringComparison.OrdinalIgnoreCase))
                        {
                            ++ret.NumberOfCorrectAnswers;
                        }
                    }
                }
            }

            return(ret);
        }
Beispiel #2
0
        public async Task <ActionResult <VerifySecurityQuestionsResponse> > VerifySecurityQuestions(string registrantId, VerifySecurityQuestionsRequest request)
        {
            VerifySecurityQuestionsQuery verifySecurityQuestionsQuery = new VerifySecurityQuestionsQuery {
                RegistrantId = registrantId, Answers = mapper.Map <IEnumerable <ESS.Shared.Contracts.Events.SecurityQuestion> >(request.Answers)
            };
            var response = await messagingClient.Send(verifySecurityQuestionsQuery);

            return(Ok(mapper.Map <VerifySecurityQuestionsResponse>(response)));
        }
Beispiel #3
0
        public async Task <VerifySecurityQuestionsResponse> Handle(VerifySecurityQuestionsQuery query)
        {
            var contact = (await contactRepository.QueryContact(new RegistrantQuery {
                ContactId = query.RegistrantId, MaskSecurityAnswers = false
            })).Items.FirstOrDefault();

            if (contact == null)
            {
                throw new NotFoundException($"registrant {query.RegistrantId} not found", query.RegistrantId);
            }

            var numberOfCorrectAnswers = query.Answers
                                         .Select(a => contact.SecurityQuestions.Any(q => a.Answer.Equals(q.Answer, StringComparison.OrdinalIgnoreCase) && a.Answer.Equals(q.Answer, StringComparison.OrdinalIgnoreCase)))
                                         .Count(a => a);

            return(new VerifySecurityQuestionsResponse {
                NumberOfCorrectAnswers = numberOfCorrectAnswers
            });
        }