Esempio n. 1
0
        public IActionResult OnPostAsync(int id, string submit, string answer)
        {
            var content = sessionHelper.GetContent();
            var answers = content.Item2;

            answers[id - 1] = answer;
            content         = new Tuple <Quiz, Dictionary <int, string> >(content.Item1, answers);
            sessionHelper.SetContent(content);

            if (submit == "Previous")
            {
                id--;
            }
            else if (submit == "Next")
            {
                id++;
            }
            else if (submit == "Finish")
            {
                return(RedirectToPage("/Finish"));
            }
            else
            {
                return(RedirectToPage("/Index"));
            }
            return(RedirectToPage("/Question", new { id = id }));
        }
Esempio n. 2
0
        public async Task OnGetAsync(int id)
        {
            Quiz = await db.Quizzes
                   .Include(q => q.Questions)
                   .AsNoTracking().SingleOrDefaultAsync(q => q.QuizId == id);

            if (Quiz == null)
            {
                RedirectToPage(NotFound($"A quiz with the ID of {id} was not found."));
                return;
            }
            ViewData["Title"] = $"{Quiz.Title} Quiz";
            var answers = new Dictionary <int, string>();

            foreach (Question question in Quiz.Questions)
            {
                answers.Add(question.QuestionId, string.Empty);
            }
            var data = new Tuple <Quiz, Dictionary <int, string> >(Quiz, answers);

            sessionHelper.SetContent(data);
        }