public IActionResult Validate(string name, string nombre, string duree) { //Insert data int nb = int.Parse(nombre); List <Question> tabQuestion = new List <Question>(); int maxId = 1; for (int i = 0; i <= nb; i++) { Random rdm = new Random(); //maxId = Dernier ID de la table int id = rdm.Next(0, maxId); //Récupération des infos de la question Question q1 = new Question(); tabQuestion.Add(q1); } var optionsBuilder = new DbContextOptionsBuilder <ExamGeneratorContext>(); var exam = new Exam() { name = name, duree = int.Parse(duree), nombre = nb, questions = tabQuestion }; using (var _context = new ExamGeneratorContext(optionsBuilder.Options)) { _context.Add(exam); //await _context.SaveChangesAsync(); } return(View("Validate")); }
public async Task <IActionResult> Create([Bind("ID")] Exam exam) { if (ModelState.IsValid) { _context.Add(exam); await _context.SaveChangesAsync(); return(RedirectToAction("Validate")); } return(View(exam)); }
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)); }
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")); }