Пример #1
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()
        {
            All_Questions = from q in _context.Questions select q;
            IEnumerable <string> Question_Strings = Questions.Split("\r\n");

            Quiz.Questions = new List <Question>(); // BUG - ONLY PUTS ONE QUESTION IN THE QUIZ

            foreach (string s in Question_Strings)
            {
                foreach (Question q in All_Questions)
                {
                    if (s == q.Name)
                    {
                        Quiz.Questions.Add(q);
                    }
                }
            }

            foreach (Question q in Quiz.Questions)
            {
                Quiz.TotalPoints += q.NumPoints;
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Quiz.Set_Questions_JSON();
            _context.Quizzes.Add(Quiz);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        // 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());
            }

            //user.Set_Completed_Quizzes_JSON();
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Login"));
        }
Пример #3
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"));
        }
Пример #4
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());
            }

            // Get the MCAnswers and Tags from bound variables and put in Question object
            Question.Tags = Tags.Split(' ');
            if (MCAnswers != null)
            {
                Question.MCAnswers = MCAnswers.Split('\n');
            }

            Question.Set_MCAnswers_JSON();
            Question.Set_Tags_JSON();
            _context.Questions.Add(Question);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #5
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"));
        }