예제 #1
0
        public async Task <IActionResult> Create([Bind("ID")] Exam exam)
        {
            if (ModelState.IsValid)
            {
                _context.Add(exam);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Validate"));
            }
            return(View(exam));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("ID,question,type")] Question question)
        {
            if (ModelState.IsValid)
            {
                _context.Add(question);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(question));
        }
예제 #3
0
        public IActionResult InsertSChoice(string name, string q1, string q2, string q3, string q4)
        {
            List <Response> responses = new List <Response>();
            var             question  = new Question()
            {
                question  = name,
                type      = QuestionType.U,
                responses = responses
            };
            var rep1 = new Response()
            {
                response  = q1,
                question  = question,
                isCorrect = true
            };
            var rep2 = new Response()
            {
                response  = q2,
                question  = question,
                isCorrect = false
            };
            var rep3 = new Response()
            {
                response  = q3,
                question  = question,
                isCorrect = false
            };
            var rep4 = new Response()
            {
                response  = q4,
                question  = question,
                isCorrect = false
            };

            responses.Add(rep1);
            responses.Add(rep2);
            responses.Add(rep3);
            responses.Add(rep4);

            question.responses = responses;

            var optionsBuilder = new DbContextOptionsBuilder <ExamGeneratorContext>();

            using (var _context = new ExamGeneratorContext(optionsBuilder.Options))
            {
                _context.Add(question);
                _context.SaveChangesAsync();
            }
            return(View("Validate"));
        }