public ActionResult DeleteConfirmed(Guid id) { QuizSection quizSection = db.QuizSections.Find(id); db.QuizSections.Remove(quizSection); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Admin/QuizSections/Create public ActionResult Create(Guid?id) { var quiz = db.Quizzes.SingleOrDefault(x => x.Id == id.Value); var model = new QuizSection(); model.Quiz = quiz; return(View(model)); }
public ActionResult Edit([Bind(Include = "Id,Name,Description")] QuizSection quizSection) { if (ModelState.IsValid) { db.Entry(quizSection).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(quizSection)); }
// GET: Admin/QuizSections/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } QuizSection quizSection = db.QuizSections.Find(id); if (quizSection == null) { return(HttpNotFound()); } return(View(quizSection)); }
public ActionResult Create(QuizSection quizSection) { if (ModelState.IsValid) { var quiz = db.Quizzes.SingleOrDefault(x => x.Id == quizSection.Quiz.Id); if (quiz != null) { quizSection.Id = Guid.NewGuid(); quizSection.Quiz = quiz; db.QuizSections.Add(quizSection); db.SaveChanges(); return(RedirectToAction("Index", new { id = quiz.Id })); } return(RedirectToAction("Index")); } return(View(quizSection)); }
// Get DB result via SQL private void GetDBResult(SqlDataReader reader, List <Quiz> listRst) { Int32 nRstBatch = 0; if (nRstBatch == 0) { if (reader.HasRows) { while (reader.Read()) { Quiz qz = new Quiz { QuizID = reader.GetInt32(0), QuizType = (QuizTypeEnum)reader.GetInt16(1) }; if (!reader.IsDBNull(2)) { qz.BasicInfo = reader.GetString(2); } qz.AttendUser = reader.GetString(3); qz.SubmitDate = reader.GetDateTime(4); listRst.Add(qz); } } ++nRstBatch; reader.NextResult(); } if (nRstBatch == 1) { if (reader.HasRows) { List <QuizFailLog> listLogs = new List <QuizFailLog>(); while (reader.Read()) { QuizFailLog fl = new QuizFailLog { QuizID = reader.GetInt32(0), QuizFailIndex = reader.GetInt32(1), Expected = reader.GetString(2), Inputted = reader.GetString(3) }; listLogs.Add(fl); } foreach (Quiz qz in listRst) { foreach (QuizFailLog fl in listLogs) { if (qz.QuizID == fl.QuizID) { qz.FailLogs.Add(fl); } } } listLogs.Clear(); listLogs = null; } ++nRstBatch; reader.NextResult(); } if (nRstBatch == 2) { if (reader.HasRows) { List <QuizSection> listSect = new List <QuizSection>(); while (reader.Read()) { QuizSection qs = new QuizSection { QuizID = reader.GetInt32(0), SectionID = reader.GetInt32(1), TimeSpent = reader.GetInt32(2), TotalItems = reader.GetInt32(3), FailedItems = reader.GetInt32(4) }; listSect.Add(qs); } foreach (Quiz qz in listRst) { foreach (QuizSection qs in listSect) { if (qz.QuizID == qs.QuizID) { qz.Sections.Add(qs); } } } listSect.Clear(); listSect = null; } } }