// GET: PaperQuestions/Edit/5 public ActionResult Up(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PaperQuestion paperQuestionToUp = db.PaperQuestions.Find(id); if (paperQuestionToUp == null) { return(RedirectToAction("EditPapers", "Examiner")); } PaperQuestion paperQuestionToDown = (from p in db.PaperQuestions where p.NumberInPaper == paperQuestionToUp.NumberInPaper - 1 && p.ExamId == paperQuestionToUp.ExamId select p).FirstOrDefault(); if (paperQuestionToDown != null) { paperQuestionToDown.NumberInPaper++; paperQuestionToUp.NumberInPaper--; //return RedirectToAction("EditPapers", "Examiner", new { subject = paperQuestionToUp.RelatedQuestion.SubjectId }); } db.SaveChanges(); return(RedirectToAction("EditPapers", "Examiner", new { subject = paperQuestionToUp.RelatedQuestion.SubjectId })); }
// GET: PaperQuestions/Create public ActionResult Create(int questionid, string examid, string subject) { if (examid == null || subject == null) { return(RedirectToAction("EditPapers", "Examiner", new { subject = subject })); } PaperQuestion paperQuestion = new PaperQuestion(); paperQuestion.PaperQuestionId = questionid + "-" + examid; paperQuestion.ExamId = examid; paperQuestion.QuestionId = questionid; paperQuestion.MarksAllocated = 0; byte nextNumber = (byte)(from p in db.PaperQuestions where p.ExamId == examid select p.ExamId).Count(); nextNumber++; paperQuestion.NumberInPaper = nextNumber; db.PaperQuestions.Add(paperQuestion); db.SaveChanges(); return(RedirectToAction("EditPapers", "Examiner", new{ subject = subject })); }
// GET: PaperQuestions/Delete/5 public async Task <ActionResult> Delete(string id, string session) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // we find the question to be deleted PaperQuestion paperQuestion = await db.PaperQuestions.FindAsync(id); if (paperQuestion == null) { return(HttpNotFound()); } // we find the last question byte lastQNumber = (from p in db.PaperQuestions where p.ExamId == session select p.NumberInPaper).Max(); PaperQuestion lastQuestion = (from p in db.PaperQuestions where p.NumberInPaper == lastQNumber && p.ExamId == session select p).SingleOrDefault(); // we give the last question the same number as the one to be deleted. // this way the last question will jump to its position lastQuestion.NumberInPaper = paperQuestion.NumberInPaper; // db.SaveChanges(); string Subject = (from q in db.Questions where q.QuestionId == paperQuestion.QuestionId select q.SubjectId).SingleOrDefault(); db.PaperQuestions.Remove(paperQuestion); await db.SaveChangesAsync(); return(RedirectToAction("EditPapers", "Examiner", new { subject = Subject })); }
public async Task <ActionResult> Create([Bind(Include = "PaperQuestionId,ExamId,QuestionId,NumberInPaper,MarksAllocated")] PaperQuestion paperQuestion) { if (ModelState.IsValid) { db.PaperQuestions.Add(paperQuestion); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ExamId = new SelectList(db.ExamSessions, "ExamId", "SubjectId", paperQuestion.ExamId); ViewBag.QuestionId = new SelectList(db.Questions, "QuestionId", "SubjectId", paperQuestion.QuestionId); return(View(paperQuestion)); }
// GET: PaperQuestions/Details/5 public async Task <ActionResult> Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PaperQuestion paperQuestion = await db.PaperQuestions.FindAsync(id); if (paperQuestion == null) { return(HttpNotFound()); } return(View(paperQuestion)); }
public async Task <ActionResult> Edit([Bind(Include = "PaperQuestionId,ExamId,QuestionId,NumberInPaper,MarksAllocated")] PaperQuestion paperQuestion) { if (ModelState.IsValid) { string Subject = (from q in db.Questions where q.QuestionId == paperQuestion.QuestionId select q.SubjectId).SingleOrDefault(); db.Entry(paperQuestion).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("EditPapers", "Examiner", new { subject = Subject })); } ViewBag.ExamId = new SelectList(db.ExamSessions, "ExamId", "SubjectId", paperQuestion.ExamId); ViewBag.QuestionId = new SelectList(db.Questions, "QuestionId", "SubjectId", paperQuestion.QuestionId); return(View(paperQuestion)); }
// GET: PaperQuestions/Edit/5 public async Task <ActionResult> Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PaperQuestion paperQuestion = await db.PaperQuestions.FindAsync(id); if (paperQuestion == null) { return(HttpNotFound()); } ViewBag.ExamId = new SelectList(db.ExamSessions, "ExamId", "SubjectId", paperQuestion.ExamId); ViewBag.QuestionId = new SelectList(db.Questions, "QuestionId", "SubjectId", paperQuestion.QuestionId); return(View(paperQuestion)); }
public async Task <ActionResult> DeleteConfirmed(string id) { // REDUNDANT AS FU*** Method PaperQuestion paperQuestion = await db.PaperQuestions.FindAsync(id); string Subject = (from q in db.Questions where q.QuestionId == paperQuestion.QuestionId select q.SubjectId).SingleOrDefault(); db.PaperQuestions.Remove(paperQuestion); await db.SaveChangesAsync(); return(RedirectToAction("EditPapers", "Examiner", new { subject = Subject })); }
public ActionResult CreatBaseTestPaper() { string strId = Request["strId"]; string baseTestPaperName = Request["baseTestPaperName"]; string baseTestPaperType = Request["baseTestPaperType"]; BaseTestPaper baseTestPaper = new BaseTestPaper() { BaseTestPaperName = baseTestPaperName, BaseTestPaperType = baseTestPaperType, BaseTestPaperCreateTime = DateTime.Now }; baseTestPaperService.Add(baseTestPaper); string[] strIds = strId.Split(','); //选中的试题数组 foreach (string id in strIds) { TestQuestion testQuestion = testQuestionService.GetModelById(Convert.ToInt32(id)); PaperQuestion paperQuestion = new PaperQuestion(); paperQuestion.BaseTestPaper = baseTestPaper; paperQuestion.TestQuestion = testQuestion; paperQuestionService.Add(paperQuestion); } return(Content("ok")); }
public ActionResult AddModule(FormCollection form) { int moduleTag = Convert.ToInt32(Request.QueryString["moduleTag"]); int CId = Convert.ToInt32(form["CourseId"]); //int ModuleId = Convert.ToInt32(form["ModuleId"]); ///完成修改 HttpPostedFileBase hpfb = Request.Files["teacherUpLoad"]; string filePath = ""; try { if (hpfb.ContentLength > 0) { Common.UpLoad upLoad = new Common.UpLoad(); filePath = upLoad.TeacherSaveFile(hpfb); } Module module = db.Module.Where(m => m.ModuleTag == moduleTag && m.CourseId == CId).FirstOrDefault(); //如果可以查询到module 说明模块已存在,即是修改,否则是建立新的模块 if (module == null) { module = new Module() { ModuleTag = moduleTag, DeadlineTime = form["DeadlineTime"], ModuleContent = form["ModuleContent"], ModuleTitle = form["ModuleTitle"], CourseId = CId, ModuleFilePath = filePath }; module = db.Module.Add(module); int moduleId = module.Id; string[] keys = form.AllKeys; if (form["SelectQ1"] != "" && form["SelectQ1"] != null) { for (int i = 1; i <= 10; i++)//默认只能有十个选择 { if (keys.Contains <string>("SelectQ" + i)) { PaperQuestion question = new PaperQuestion() { QTitle = form["SelectQ" + i], QuestionType = int.Parse(form["type" + i]), A = form["SelectQ" + i + "A"], B = form["SelectQ" + i + "B"], C = form["SelectQ" + i + "C"], D = form["SelectQ" + i + "D"], Answer = form["SelectAnswer" + i], MouduleId = moduleId, CourseId = CId, ModuleTag = moduleTag }; db.PaperQuestion.Add(question); } else { break; } } } if (form["BlankQ1"] != "" && form["BlankQ1"] != null) { for (int i = 1; i <= 5; i++)//默认只能有五个填空 { if (keys.Contains <string>("BlankQ" + i)) { PaperQuestion question = new PaperQuestion() { QTitle = form["BlankQ" + i], Answer = form["BlankAnswer" + i], QuestionType = 2, MouduleId = moduleId, CourseId = CId, ModuleTag = moduleTag }; db.PaperQuestion.Add(question); } else { break; } } } } //修改模块信息 else { //todo ---------修改试题!!!! module.DeadlineTime = form["DeadlineTime"]; module.ModuleContent = form["ModuleContent"]; module.ModuleTitle = form["ModuleTitle"]; if (!string.IsNullOrEmpty(filePath)) { module.ModuleFilePath = filePath; } } db.SaveChanges(); } catch (Exception) { ViewBag.TagMSG = "Error"; throw; } ViewBag.TagMSG = "OK"; return(RedirectToAction("CoursesDetail", "CourseManage", new { id = CId })); }