//private int GetQuestionCount(int QuestionCount) //{ // QuestionBL topicBL = new QuestionBL(); // return topicBL.GetAllQuestion(QuestionCount); //} //public JsonResult GetNextQuestion(string pageindex,string pagesize, string radioValue,string quesId) //{ // ExamPaper examPaper = new ExamPaper(); // QuestionBL topicBL = new QuestionBL(); // if (radioValue != null) // { // if(! String.IsNullOrEmpty(quesId)) // if(int.Parse(quesId) > 0 && !String.IsNullOrEmpty(radioValue)) // topicBL.SaveUserAnswer(int.Parse(radioValue), int.Parse(quesId), int.Parse(Session["UserId"].ToString())); // } // int questionCount = int.Parse(ConfigurationManager.AppSettings["QuestionCount"].ToString()); // examPaper = topicBL.GetNextPrevQuestion(int.Parse(pageindex), int.Parse(pagesize), int.Parse(Session["UserId"].ToString())); // examPaper.QuestionEntities = examPaper.QuestionEntities.OrderBy(o => o.Id).ToList(); // return Json(examPaper, JsonRequestBehavior.AllowGet); //} public ExamPaper GetQuestion(string pageindex, string pagesize, string radioValue, string quesId, string currentTime) { ExamPaper examPaper = new ExamPaper(); QuestionBL topicBL = new QuestionBL(); if (radioValue != null && radioValue != String.Empty) { if (!String.IsNullOrEmpty(quesId)) { if (int.Parse(quesId) > 0 && !String.IsNullOrEmpty(radioValue)) { topicBL.SaveUserAnswer(int.Parse(radioValue), int.Parse(quesId), int.Parse(Session["UserId"].ToString()), currentTime); } } } else { ExamBL examBL = new ExamBL(); examBL.UpdateExamTime(int.Parse(Session["UserId"].ToString()), currentTime); } int questionCount = int.Parse(ConfigurationManager.AppSettings["QuestionCount"].ToString()); examPaper = topicBL.GetNextPrevQuestion(int.Parse(pageindex), int.Parse(pagesize), int.Parse(Session["UserId"].ToString())); examPaper.QuestionEntities = examPaper.QuestionEntities.OrderBy(o => o.Id).ToList(); return(examPaper); }
public ActionResult QuestionPaper() { ExamPaper examPaper = new ExamPaper(); if (Session["QuestionPaper"] == null) { QuestionBL topicBL = new QuestionBL(); // i = i + 1; int questionCount = int.Parse(ConfigurationManager.AppSettings["QuestionCount"].ToString()); examPaper = topicBL.GetNextPrevQuestion(1, 1, int.Parse(Session["UserId"].ToString())); examPaper.QuestionEntities = examPaper.QuestionEntities.OrderBy(o => o.Id).ToList(); examPaper.QuestionEntities[0].IsShown = true; examPaper.QuestionEntities[0].HasAlreadyShown = true; examPaper.PageIndex = 1; examPaper.PageSize = 1; Session["QuestionPaper"] = examPaper; } else { examPaper = (ExamPaper)Session["QuestionPaper"]; } return(View(examPaper)); // return View(examPaper); }
public ActionResult QuestionPaper(FormCollection collection, string command) { QuestionBL topicBL = new QuestionBL(); //int questionCount = int.Parse(ConfigurationManager.AppSettings["QuestionCount"].ToString()); ExamPaper examPaper = new ExamPaper(); examPaper = (ExamPaper)Session["QuestionPaper"]; //topicBL.GetQuestionPaper(questionCount); examPaper.QuestionEntities = examPaper.QuestionEntities.OrderBy(o => o.Id).ToList(); // int index = examPaper.QuestionEntities.FindIndex(item => item.IsShown); int rightAnswerIndex = 0; // examPaper.QuestionEntities[0].AnswerEntities.FindIndex(o => o.ID == int.Parse(collection.AllKeys[0])); foreach (AnswerEntities item in examPaper.QuestionEntities[0].AnswerEntities) { if (collection.AllKeys.Length == 2) { if (item.ID == int.Parse(collection.AllKeys[0])) { item.IsUserAnswer = 1; //topicBL.SaveUserAnswer(item.ID, item.IsUserAnswer, int.Parse(Session["UserId"].ToString())); //save userdata break; } } } examPaper.QuestionEntities[0].IsShown = false; if (command == "Next") { if (examPaper.PageIndex < int.Parse(ConfigurationManager.AppSettings["QuestionCount"].ToString())) { examPaper.PageIndex += 1; } } else if (command == "Previous") { if (examPaper.PageIndex <= int.Parse(ConfigurationManager.AppSettings["QuestionCount"].ToString()) && examPaper.PageIndex > 1) { examPaper.PageIndex -= 1; } } examPaper = topicBL.GetNextPrevQuestion(examPaper.PageIndex, examPaper.PageSize, int.Parse(Session["UserId"].ToString())); //Session.Abandon(); Session["QuestionPaper"] = examPaper; return(RedirectToAction("QuestionPaper", "Question")); }