Beispiel #1
0
        //public async Task<IActionResult> AttemptQuiz(int? id,int? comp) f**k off
        //{
        //    if (id == null)
        //    {
        //        return NotFound();
        //    }
        //    var quiz = await _context.Quiz
        //        .Include(q => q.Questions)
        //        .ThenInclude(q => q.Answers)
        //        .FirstOrDefaultAsync(e => e.ID == id);
        //    if (quiz == null)
        //    {
        //        return NotFound();
        //    }

        //    string quizData = Newtonsoft.Json.JsonConvert.SerializeObject(quiz, new Newtonsoft.Json.JsonSerializerSettings()
        //    {
        //        PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects,
        //        Formatting = Newtonsoft.Json.Formatting.Indented
        //    });
        //    ViewBag.jsonQuiz = (quizData);
        //    return View();
        //}
        //GET:
        public async Task <IActionResult> AttemptQuiz2(int?id, int?comp, string vs)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var quiz = await _context.Quiz
                       .Include(q => q.Questions)
                       .ThenInclude(q => q.Answers)
                       .FirstOrDefaultAsync(e => e.ID == id);

            if (quiz == null)
            {
                return(NotFound());
            }

            AttemptQuizViewModel viewModel = new AttemptQuizViewModel();

            viewModel.fillFromQuiz(quiz);
            if (comp != null)
            {
                viewModel.Comp = comp.Value;
                var check = _context.Competitions.FirstOrDefault(x => x.ID == comp);
                if (check.Deadline < DateTime.Now)
                {
                    return(Forbid());
                }
            }
            if (vs != null && vs != "")
            {
                viewModel.vs = vs;
            }
            return(View(viewModel));
        }