public async Task <IActionResult> CreateBool([Bind("BoolAnswerId,Answer,QuestionId,CreationDate")] BoolAnswer boolAnswer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(boolAnswer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), "Questions", new { id = boolAnswer.QuestionId }));
            }

            return(View(boolAnswer));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("SubjectId,Name,CreationDate")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                _context.Add(subject);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(subject));
        }
        public async Task <IActionResult> Create([Bind("TypeQuestionId,Name,Wording,CreationDate")] TypeQuestion typeQuestion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(typeQuestion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(typeQuestion));
        }
        public async Task <IActionResult> Create([Bind("ExamId,Name,SubjectId,NumberQuestions,Duration,NumberTriesAllow,EndDate,CreationDate,UserId")] Exam exam)
        {
            exam.UserId = _userManager.GetUserId(User);

            if (ModelState.IsValid)
            {
                _context.Add(exam);

                SelectRandomQuestion(exam);

                //Create userExams for each user
                var users = _context.Users.ToListAsync();

                for (int i = 0; i < users.Result.Count(); i++)
                {
                    _context.Add(new UserExam
                    {
                        UserId      = users.Result[i].Id,
                        ExamId      = exam.ExamId,
                        NumberTries = 0,
                        BestNote    = 0,
                        IsValid     = false
                    });
                    await _context.SaveChangesAsync();
                }

                return(View(nameof(Details), new CreateOrUpdateExamViewModel
                {
                    Questions = _context.Questions.Include(e => e.TypeQuestion).ToList(),
                    Subjects = _context.Subjects.ToList(),
                    Exam = exam
                }));
            }

            return(View(new CreateOrUpdateExamViewModel
            {
                Questions = _context.Questions.Include(e => e.TypeQuestion).ToList(),
                Subjects = _context.Subjects.ToList(),
                Exam = exam
            }));
        }
        public async Task <IActionResult> Create([Bind("QuestionId,Header,Mark,CreationDate,TypeQuestionId,SubjectId,UserId")] Question question)
        {
            question.UserId = _userManager.GetUserId(User);
            if (ModelState.IsValid)
            {
                _context.Add(question);
                await _context.SaveChangesAsync();

                // Return the right view to fill the answer => TypeQuestion
                question.TypeQuestion = await _context.TypeQuestions.Where(t => t.TypeQuestionId == question.TypeQuestionId).FirstOrDefaultAsync();

                question.Subject = await _context.Subjects.Where(s => s.SubjectId == question.SubjectId).FirstOrDefaultAsync();

                var model = new CreateAnswerViewModel
                {
                    Question = question
                };

                if (question.TypeQuestion.Name == "Multiple" || question.TypeQuestion.Name == "Unique")
                {
                    model.IsChoiceAnswer = true;
                }
                else if (question.TypeQuestion.Name == "VraiFaux")
                {
                    model.IsBoolAnswer   = true;
                    model.ListBoolAnswer = _context.BoolAnswers.Where(a => a.QuestionId == question.QuestionId).ToList();
                }
                else if (question.TypeQuestion.Name == "Trou")
                {
                    model.IsHoleAnswer   = true;
                    model.ListHoleAnswer = _context.HoleAnswers.Where(a => a.QuestionId == question.QuestionId).ToList();
                }

                ViewData["ChoiceAnswersIsRight"] = false;

                return(View("CreateAnswer", model));
            }
            ViewData["SubjectId"]      = new SelectList(_context.Subjects, "SubjectId", "SubjectId", question.SubjectId);
            ViewData["TypeQuestionId"] = new SelectList(_context.TypeQuestions, "TypeQuestionId", "TypeQuestionId", question.TypeQuestionId);
            return(View(question));
        }