// [ValidateAntiForgeryToken] public ActionResult Create(int[] TestWordsParameters, string title, int rstatus, int time) //string Title, bool? TotalTime , bool? Second, DateTime? Time { // string name = Request.Form["Title"].ToString(); CTest test = new CTest(); if (TestWordsParameters != null) { test.CTNote = title; if (rstatus == 1) { test.Score = time; test.TestTime = true; } else if (rstatus == 2) { test.Score = time; test.TimePerWord = true; } for (int j = 0; j < TestWordsParameters.Length; j++) { var r = TestWordsParameters[j]; ChoiceTest wt = new ChoiceTest(); wt.FChoicerID = r; test.ChoiceTests.Add(wt); // parent.childs.Add(child obj) } test.FCTuserID = userid; db.CTests.Add(test); db.SaveChanges(); } // ViewBag.FWTUserID = new SelectList(db.Users, "UserID", "Forename", wTest.FWTUserID); return(RedirectToAction("Create")); }
public ActionResult DeleteConfirmed(int id) { ChoiceTest choiceTest = db.ChoiceTests.Find(id); db.ChoiceTests.Remove(choiceTest); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ChoiceTestID,FCTestID,FChoicerID,Result,TimeSkip,TestAppearance")] ChoiceTest choiceTest) { if (ModelState.IsValid) { db.Entry(choiceTest).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FChoicerID = new SelectList(db.Choicers, "ChoicerID", "CQuestion", choiceTest.FChoicerID); ViewBag.FCTestID = new SelectList(db.CTests, "CTestID", "CTNote", choiceTest.FCTestID); return(View(choiceTest)); }
// GET: ChoiceTest/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChoiceTest choiceTest = db.ChoiceTests.Find(id); if (choiceTest == null) { return(HttpNotFound()); } return(View(choiceTest)); }
// GET: ChoiceTest/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChoiceTest choiceTest = db.ChoiceTests.Find(id); if (choiceTest == null) { return(HttpNotFound()); } ViewBag.FChoicerID = new SelectList(db.Choicers, "ChoicerID", "CQuestion", choiceTest.FChoicerID); ViewBag.FCTestID = new SelectList(db.CTests, "CTestID", "CTNote", choiceTest.FCTestID); return(View(choiceTest)); }
// WTest start tomorrow, send data to answer view wothout timer public ActionResult Answer(int?id) { var r = (from t in db.CTests where t.FCTuserID == userid orderby t.CTestID descending select t).First(); double time = Convert.ToDouble(r.Score); bool minute = r.TestTime ?? false; bool second = r.TimePerWord ?? false; if (minute == true) { if (Session["EndDate"] == null) { Session["EndDate"] = DateTime.Now.AddMinutes(time).ToString("dd-MM-yyyy h:mm:ss tt"); } } else if (second == true) { Session["EndDate"] = DateTime.Now.AddSeconds(time).ToString("dd-MM-yyyy h:mm:ss tt"); } // Session["EndDate"] = DateTime.Now.AddMinutes(minute).ToString("dd-MM-yyyy h:mm:ss tt"); ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; ViewBag.EndDate = Session["EndDate"]; int value = id ?? default(int); if (value == 1) { int wid = fwords[true_count]; ChoiceTest wt = db.ChoiceTests.Where(t => (t.FChoicerID == wid) && (t.FCTestID == r.CTestID)).FirstOrDefault(); wt.Result = true; db.SaveChanges(); true_count = true_count + 1; } // var d = db.WordTests.Where(t => t.FWtestID==1).FirstOrDefault(); // working //int turnfirst = 0; if (turnfirst == 0) { v = 0; //testid = (from t in db.WTests // orderby t.WTestID descending // select t.WTestID).First(); Choicer w = new Choicer(); var IDs = db.ChoiceTests.Where(t => t.FCTestID == r.CTestID).ToArray().Select(t => t.FChoicerID); int index = 0; k = IDs.Count(); // k = total no words foreach (var c in IDs) { w = db.Choicers.Find(c); if (w.CAnswer == 1) { definitions[index] = w.Opt1.ToString(); } else if (w.CAnswer == 2) { definitions[index] = w.Opt2.ToString(); } else if (w.CAnswer == 3) { definitions[index] = w.Opt3.ToString(); } else if (w.CAnswer == 4) { definitions[index] = w.Opt4.ToString(); } else if (w.CAnswer == 5) { definitions[index] = w.Opt5.ToString(); } //definitions[index] = w.CAnswer.ToString(); // CAnswer is int so convert into string hint[index] = w.Category.Name; // Appearance colomn replace the hint and convert into string wordlist[index] = w.CQuestion; fwords[index] = w.ChoicerID; index = index + 1; } turnfirst = 1; } if (v < k) { ViewBag.Definition = definitions[v]; ViewBag.Hint = hint[v]; ViewBag.Word = wordlist[v]; v = v + 1; } else { ViewBag.Status = "complete"; ViewBag.EndDate = null; return(RedirectToAction("Result", new { id = r.CTestID })); } return(View()); }