// add new question or choice to a test selected public ActionResult AddQues(int id) { var test = db.Tests.Where(x => x.Id == id).Select(x => x.Id).Single(); AddQues testid = new AddQues(); testid.TestId = test; return(View(testid)); }
public ActionResult AddQues(AddQues m) { if (ModelState.IsValid) { if (m != null) { Question nq = new Question(); nq.QuestionCategoryId = 2; // hard coded to remove multiple option select nq.QuestionType = "radio"; //nq.QuestionCategoryId = m.QuestionCategoryId; //if (nq.QuestionCategoryId == 1) // nq.QuestionType = "mcq"; //else // nq.QuestionType = "radio"; nq.Question1 = m.Question; nq.Points = Convert.ToInt32(m.Points); nq.IsActive = m.IsActive; db.Questions.Add(nq); db.SaveChanges(); var testid = m.TestId; TestXQuestion newTXQ = new TestXQuestion(); newTXQ.TestId = testid; newTXQ.QuestionId = nq.Id; var z = db.TestXQuestions.Where(p => p.TestId == testid).Select(p => p.QuestionNumber).FirstOrDefault(); if (z != 0) { newTXQ.QuestionNumber = db.TestXQuestions.Where(x => x.TestId == testid).Select(x => x.QuestionNumber).Max() + 1; } else { newTXQ.QuestionNumber = 1; } newTXQ.IsActive = nq.IsActive; db.TestXQuestions.Add(newTXQ); db.SaveChanges(); return(RedirectToAction("AddChoice", "Admin", new { @id = nq.Id })); } } return(View()); }