예제 #1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Completed_Quiz = await _context.Completed_Quiz.FirstOrDefaultAsync(m => m.ID == id);

            Completed_Quiz.Get_Answers_JSON();

            Quiz = await _context.Quizzes.FirstOrDefaultAsync(m => m.Name == Completed_Quiz.CorrespondingQuizName);

            Quiz.Get_Questions_JSON();

            AnswerScores = new List <int>();
            foreach (Question q in Quiz.Questions)
            {
                AnswerScores.Add(0);
            }

            if (Completed_Quiz == null)
            {
                return(NotFound());
            }
            return(Page());
        }
예제 #2
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Completed_Quiz.QuizType = QuizType.Graded;


            Completed_Quiz.Get_Answers_JSON();

            for (int i = 0; i < Completed_Quiz.Answers.Count(); ++i)
            {
                Completed_Quiz.Answers.ElementAt(i).pointsGraded = AnswerScores.ElementAt(i);
            }

            foreach (Answer a in Completed_Quiz.Answers)
            {
                Completed_Quiz.pointsEarned += a.pointsGraded;
            }

            Completed_Quiz.Set_Answers_JSON();
            _context.Attach(Completed_Quiz).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Completed_QuizExists(Completed_Quiz.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
예제 #3
0
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Quiz = _context.Quizzes.FirstOrDefault(m => m.ID == id);
            Quiz.Get_Questions_JSON();
            foreach (Question q in Quiz.Questions)
            {
                q.Get_MCAnswers_JSON();
            }

            names = _context.Users.Select(x => x.Name).Distinct();

            // // -------------------------------------------------------------------
            Completed_Quiz = new Completed_Quiz();

            Completed_Quiz.Answers = new List <Answer>();

            foreach (Question q in Quiz.Questions)
            {
                Completed_Quiz.Answers.Add(new Answer(q.QuestionType));
            }
            Completed_Quiz.Set_Answers_JSON();

            Completed_Quiz.CorrespondingQuizName = Quiz.Name;
            Completed_Quiz.maxPoints             = Quiz.TotalPoints;
            Completed_Quiz.QuizType = QuizType.Pending;
            // // -------------------------------------------------------------------

            Answers = new List <string>();
            foreach (Question q in Quiz.Questions)
            {
                Answers.Add("");
            }
            // Answers_JSON = JsonConvert.SerializeObject(Answers);

            return(Page());
        }
예제 #4
0
        // [BindProperty]
        // public string Answers_JSON { get; set; }

        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Answers = JsonConvert.DeserializeObject<List<string>>(Answers_JSON);

            Completed_Quiz.Get_Answers_JSON();

            for (int i = 0; i < Completed_Quiz.Answers.Count(); ++i)
            {
                Completed_Quiz.Answers.ElementAt(i).Answer_Text = Answers.ElementAt(i);
            }

            Completed_Quiz.Set_Answers_JSON();
            _context.Completed_Quiz.Add(Completed_Quiz);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }