/// <summary> /// 随机出题(因功能废弃暂未实现主客观题2:1比例) /// </summary> /// <param name="courseId"></param> /// <param name="kpointId"></param> /// <param name="cpointId"></param> /// <param name="count"></param> /// <returns></returns> public ActionResult RandomQuestions(int courseId, int kpointId, int cpointId, int count) { List <dto_Question> list = null; if (count <= 20) { int[] qids = B_Ques.GetQuesIds(courseId, kpointId, cpointId, count); if (qids != null && qids.Length > 0) { list = new List <dto_Question>(); foreach (var q in qids) { dto_Question ques = B_QuesRedis.GetQuestion(courseId, q); if (ques != null) { //暴露的qid重写 ques.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, ques.id); ques.id = 0; if (ques.Children != null && ques.Children.Count > 0) { ques.Children.ForEach(a => { a.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, a.id); a.id = 0; }); } list.Add(ques); } } } } ViewBag.QuesList = list; return(PartialView()); }
public ActionResult GetBasketQues(int courseId, string qid) { List <dto_Question> dql = null; if (!string.IsNullOrEmpty(qid)) { dql = new List <dto_Question>(); string[] ql = qid.Split(','); foreach (string q in ql) { dto_Question dq = B_QuesRedis.GetQuestion(courseId, IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Ques, long.Parse(q))); dq.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, dq.id); dq.id = 0; dql.Add(dq); } //因为二级题型是6位的,int型比1级题型大排序会排到后面,所以转化为字符型排序 dql = dql.OrderBy(a => a.typeid.ToString()).ToList(); } ViewBag.QuesList = dql; return(PartialView()); }
/// <summary> /// 保存作业试题 /// </summary> /// <param name="courseId"></param> /// <param name="zyId"></param> /// <param name="questions"></param> /// <returns></returns> private bool SaveZyQuestions(int courseId, int zyId, string[] questions) { int OrderIndex = 0; List <dto_ZyQuestion> ql = new List <dto_ZyQuestion>(); foreach (var qid in questions) { dto_ZyQuestion q = null; dto_Question dq = B_QuesRedis.GetQuestion(courseId, IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Ques, long.Parse(qid))); if (dq.haschildren && dq.Children != null) { foreach (var cq in dq.Children) { q = new dto_ZyQuestion(); OrderIndex += 1; q.PQId = dq.id; q.QId = cq.id; q.PTypeId = cq.ptypeid; q.OrderIndex = OrderIndex; q.Score = 0; ql.Add(q); } } else { q = new dto_ZyQuestion(); OrderIndex += 1; q.PQId = dq.id; q.QId = dq.id; q.PTypeId = dq.ptypeid; q.OrderIndex = OrderIndex; q.Score = 0; ql.Add(q); } } return(B_Zy.AddQdbZyQues(zyId, JsonConvert.SerializeObject(ql))); }
public ActionResult add(long quesId = 0, int courseId = 0) { if (quesId != 0) { int qid = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Ques, quesId); dto_Question q = B_QuesRedis.GetQuestion(courseId, qid); string cont = ""; if (q != null) { cont = q.quesbody + "\n\r"; if (Const.OBJECTIVE_QUES_TYPES.Contains(q.ptypeid) && q.Options != null) { cont = string.Concat(cont, "<p>A. ", q.Options.optiona, "</p><p>B. ", q.Options.optionb, "</p><p>C. ", q.Options.optionc, "</p><p>D. ", q.Options.optiond, "</p>"); if (!string.IsNullOrEmpty(q.Options.optione)) { cont = string.Concat(cont, "<p>E.", q.Options.optione, "</p>"); } if (!string.IsNullOrEmpty(q.Options.optionf)) { cont = string.Concat(cont, "<p>F.", q.Options.optionf, "</p>"); } if (!string.IsNullOrEmpty(q.Options.optiong)) { cont = string.Concat(cont, "<p>G.", q.Options.optiong, "</p>"); } } } ViewBag.TopicContent = cont; int subjectId = Const.CourseSubjectMapping[courseId]; ViewBag.SubjectId = subjectId; } ViewBag.Grades = Const.Grades; ViewBag.Subjects = Const.Subjects; return(View()); }
/// <summary> /// 筛题 /// </summary> /// <param name="courseId"></param> /// <param name="kpointId"></param> /// <param name="cpointId"></param> /// <param name="typeId"></param> /// <param name="diffType"></param> /// <param name="paperYear"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult GetQuestions(int courseId, int kpointId, int cpointId, int typeId, int diffType, int paperYear, int pageIndex, int pageSize) { int totalCount = 0; //int[] qids = B_Ques.GetQuesIds(courseId, kpointId, cpointId, typeId, diffType, paperYear, pageIndex, pageSize, out totalCount); int[] qids = B_QuesSolr.GetQuesIds(courseId, kpointId, cpointId, typeId, diffType, paperYear, pageIndex, pageSize, out totalCount); int totalPage = Util.GetTotalPageCount(totalCount, pageSize); List <dto_Question> list = null; if (qids != null && qids.Length > 0) { list = new List <dto_Question>(); foreach (var q in qids) { dto_Question ques = B_QuesRedis.GetQuestion(courseId, q); if (ques != null) { //暴露的qid重写 ques.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, ques.id); ques.id = 0; if (ques.Children != null && ques.Children.Count > 0) { ques.Children.ForEach(a => { a.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, a.id); a.id = 0; }); } list.Add(ques); } } } ViewBag.PageCount = totalPage; ViewBag.QuesList = list; return(PartialView()); }
/// <summary> /// 提交答案 /// 仍然做各种状态判断 /// </summary> /// <param name="zyId"></param> /// <param name="questions"></param> /// <param name="answers"></param> /// <returns></returns> public JsonResult SubmitAnswer(long zyId, string questions, string answers) { dto_AjaxJsonResult <string> r = new dto_AjaxJsonResult <string>(); int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); //试用作业验证 if (zy.UserId == 0) { r.code = AjaxResultCodeEnum.Error; r.message = "试用作业仅用于数据展示,不允许进行操作!<br/>注册成为正式用户后即可体验所有功能!"; r.data = ""; return(Json(r)); } #region 访问权限验证 dto_AjaxJsonResult <dto_Zy> r1 = AccessJudge(UserId, zy); if (r1.code == AjaxResultCodeEnum.Error) { r.code = AjaxResultCodeEnum.Error; r.message = r1.message; r.data = ""; return(Json(r)); } #endregion //作业提交验证 T_Answer ans = B_Answer.GetAnswer(id, UserId); if (ans != null && ans.Submited) { r.code = AjaxResultCodeEnum.Error; r.message = "作业已提交,不能重复提交!"; r.data = ""; return(Json(r)); } //todo submit List <string> submitQlist = questions.Split(',').ToList(); List <string> submitAlist = string.IsNullOrEmpty(answers) ? new List <string>() : answers.Split(',').ToList(); if (submitQlist.Count != submitAlist.Count) { r.code = AjaxResultCodeEnum.Error; r.message = "试题信息有误,提交失败!"; r.data = ""; return(Json(r)); } string qjson = B_ZyRedis.GetQdbZyQuesJson(id); List <dto_ZyQuestion> ql = JsonConvert.DeserializeObject <List <dto_ZyQuestion> >(qjson); List <dto_UserAnswer> al = new List <dto_UserAnswer>(); ql.ForEach(a => { string CAnswer = ""; if (Const.OBJECTIVE_QUES_TYPES.Contains(a.PTypeId)) { if (a.QId == a.PQId) { CAnswer = B_QuesRedis.GetQuestion(zy.CourseId, a.QId).quesanswer; } else { CAnswer = B_QuesRedis.GetQuestion(zy.CourseId, a.PQId).Children.Find(b => b.id == a.QId).quesanswer; } } int i = submitQlist.IndexOf(IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, a.QId).ToString()); al.Add(new dto_UserAnswer() { QId = a.QId, PTypeId = a.PTypeId, Score = a.Score, Answer = (i == -1 ? "" : submitAlist[i]), CAnswer = CAnswer, Point = 0 }); }); bool isok = false; T_Answer answer = new T_Answer() { ZyId = id, ZyType = zy.Type, StudentId = UserId, Submited = true, CreateDate = DateTime.Now, AnswerJson = JsonConvert.SerializeObject(al), AnswerImg = "", Ip = ClientUtil.Ip, IMEI = ClientUtil.IMEI, MobileBrand = ClientUtil.MobileBrand, SystemType = Request.Browser.Platform.ToString(), Browser = Request.Browser.Browser.ToString() }; if (ans != null) { isok = B_Answer.UpdateAnswerJson(id, UserId, answer.AnswerJson); } else { isok = B_Answer.InsertZyAnswer(answer); } if (isok) { //写统计表 B_Analyze.GenerateAnalyze(answer); r.code = AjaxResultCodeEnum.Success; r.message = ""; r.data = ""; return(Json(r)); } else { r.code = AjaxResultCodeEnum.Error; r.message = "提交入库失败!"; r.data = ""; return(Json(r)); } }