コード例 #1
0
        public static RandomQuestion GenerateRandomQuestion()
        {
            var qa     = RandomQuestions.CreateRandomQuestions();
            var random = new Random();
            var index  = random.Next(qa.Count);

            return(qa[index]);
        }
コード例 #2
0
        public static bool ValidateProvidedAnswer(IFormCollection form)
        {
            ValidateForm(form);
            var(providedAnswer, questionId) = ExtractAnswerFromRequest(form);

            var qa = RandomQuestions.CreateRandomQuestions();

            var lookup = qa.FirstOrDefault(q => q.Id == questionId);

            if (lookup is null)
            {
                return(false);
            }

            var result = string.Equals(lookup.Answer, providedAnswer, StringComparison.OrdinalIgnoreCase);

            return(result ? true : throw new InvalidOperationException("Provided answer is not correct!"));
        }