public ActionResult DeleteQuestionPost(int id) { //if ((string)Session["Userid"] != null && (string)Session["Level"] != null) //{ // if ((string)Session["Level"] == "admin") // { using (TsmsDBContext context = new TsmsDBContext()) { Question ques = context.Questions.SingleOrDefault(p => p.Id == id); context.Questions.Remove(ques); context.SaveChanges(); Exam exam = context.Exams.SingleOrDefault(p => p.Id == ques.ExamID); exam.TotalQues = exam.TotalQues - 1; context.Exams.Attach(exam); var entry = context.Entry(exam); entry.Property(e => e.TotalQues).IsModified = true; context.SaveChanges(); return(RedirectToAction("CreateQuestion", new { id = ques.ExamID })); } // } // else // { // return RedirectToAction("Index", "Exam"); // } //} //else //{ // return RedirectToAction("Index", "Exam"); // } }
public ActionResult EditQuestion(Question ques) { //if ((string)Session["Userid"] != null && (string)Session["Level"] != null) //{ // if ((string)Session["Level"] == "admin") // { using (TsmsDBContext context = new TsmsDBContext()) { context.Questions.Attach(ques); var entry = context.Entry(ques); entry.Property(e => e.QuestionTitle).IsModified = true; entry.Property(e => e.Option1).IsModified = true; entry.Property(e => e.Option2).IsModified = true; entry.Property(e => e.Option3).IsModified = true; entry.Property(e => e.Option4).IsModified = true; entry.Property(e => e.Option5).IsModified = true; entry.Property(e => e.CorrectAns).IsModified = true; context.SaveChanges(); return(RedirectToAction("CreateQuestion", new { id = ques.ExamID })); } // } // else // { // return RedirectToAction("Index", "Exam"); // } //} //else //{ // return RedirectToAction("Index", "Exam"); //} }
public ActionResult AddQuestion(Question question) { //if ((string)Session["Userid"] != null && (string)Session["Level"] != null) //{ // if ((string)Session["Level"] == "admin") // { using (TsmsDBContext context = new TsmsDBContext()) { Exam exam = context.Exams.SingleOrDefault(EId => EId.Id == question.ExamID); exam.TotalQues = (int)exam.TotalQues + 1; question.QuestionNumber = exam.TotalQues; context.Exams.Attach(exam); var entry = context.Entry(exam); entry.Property(e => e.TotalQues).IsModified = true; context.SaveChanges(); context.Questions.Add(question); context.SaveChanges(); return(RedirectToAction("CreateQuestion", new { id = question.ExamID })); } // } // else // { // return RedirectToAction("Index", "Exam"); // } //} //else //{ // return RedirectToAction("Index", "Exam"); //} }
public ActionResult EditExam(Exam exam) { //if (Session["Userid"] != null && Session["Level"] != null) //{ // if ((string)Session["Level"] == "admin") // { using (TsmsDBContext context = new TsmsDBContext()) { context.Exams.Attach(exam); var entry = context.Entry(exam); entry.Property(e => e.Course).IsModified = true; entry.Property(e => e.Date).IsModified = true; entry.Property(e => e.ExamState).IsModified = true; entry.Property(e => e.FinishTime).IsModified = true; entry.Property(e => e.MarkPerQues).IsModified = true; entry.Property(e => e.Name).IsModified = true; entry.Property(e => e.StartTime).IsModified = true; entry.Property(e => e.Type).IsModified = true; context.SaveChanges(); return(RedirectToAction("ExamDetail", new { id = exam.Id })); } // } // else // { // return RedirectToAction("Index", "Exam"); // } //} //else //{ // return RedirectToAction("Index", "Exam"); //} }
public ActionResult ShowQuestion(FormCollection form) { //if ((string)Session["Userid"] != null && (string)Session["Level"] != null) //{ using (TsmsDBContext context = new TsmsDBContext()) { int examId = Convert.ToInt32(Request.Form["hidden"]); Exam exam = context.Exams.SingleOrDefault(p => p.Id == examId); for (int i = 1; i <= exam.TotalQues; i++) { Answer ans = new Answer(); ans.StudentId = (string)Session["Userid"]; ans.StuAns = Convert.ToInt32(Request.Form[i.ToString()]); ans.ExamId = examId; ans.QuestionId = Convert.ToInt32(Request.Form["QuesId" + i.ToString()]); Question ques = context.Questions.SingleOrDefault(p => p.Id == ans.QuestionId); if (ans.StuAns == ques.CorrectAns) { ans.Result = true; } else { ans.Result = false; } context.Answers.Add(ans); context.SaveChanges(); } List <Answer> answers = context.Answers.Where(p => p.ExamId == examId && p.StudentId == (string)Session["Userid"]).ToList(); float achived = 0; foreach (Answer answer in answers) { if (answer.Result == true) { achived++; } } Exam examOb = context.Exams.SingleOrDefault(p => p.Id == examId); float Marks = achived * examOb.MarkPerQues; ExamAssign assign = context.ExamAssigns.SingleOrDefault(p => p.ExamID == examId && p.StudentID == Convert.ToString(Session["Userid"])); assign.gotMark = Marks.ToString(); context.ExamAssigns.Attach(assign); var entry = context.Entry(assign); entry.Property(e => e.gotMark).IsModified = true; context.SaveChanges(); float totalmarks = examOb.TotalQues * examOb.MarkPerQues; return(RedirectToAction("ShowResult", new { id = examId, total = totalmarks, achieved = Marks })); } //} //else //{ // return RedirectToAction("Index", "Exam"); //} }
public ActionResult Edit([Bind(Include = "batch_code,name,batch_starting_date,admission_last_date,room_number,faculty_name,amount,details,routine")] Batche batche) { if (ModelState.IsValid) { db.Entry(batche).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.faculty_name = new SelectList(db.Instructors, "faculty_name", "faculty_name"); ViewBag.name = new SelectList(db.Courses, "name", "vendor_heading", batche.name); return(View(batche)); }
public ActionResult Edit([Bind(Include = "id,UserId,batch_code,debit,credit,balance,lastTrunsaction")] Financeofstudent financeofstudent) { if (ModelState.IsValid) { db.Entry(financeofstudent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.batch_code = new SelectList(db.Batches, "batch_code", "name", financeofstudent.batch_code); ViewBag.UserId = new SelectList(db.Users, "UserId", "password", financeofstudent.UserId); return(View(financeofstudent)); }