public IHttpActionResult Post(MQuestion args) { var question = new Question { Course = args.Course, Description = args.Description }; _manager.Create(_alternativeManager, _sendQuestionManager, _subscribeManager, question, args.Course, args.Alternatives); return(Ok("Questão cadastrada com sucesso!")); }
/// <summary> /// 获取试卷的试题 /// </summary> /// <param name="exampaper">试卷信息</param> /// <param name="exam">试卷信息</param> /// <param name="examuser">学员答案</param> public void GetExampaper(ExampaperShow exampaper, tbExampaper exam, tbExamSendStudent examuser) { if (exampaper.ExampaperType == 0) { #region 正常 IMongoQuery query = Query.In("_id", new BsonArray(exam.QuestionList.Select(p => p.Qid))); List <tbQuestion> quList = Etdb.GetAllList <tbQuestion>(query); //获取试题 exam.QuestionList.ForEach(p => { tbQuestion qu = quList.FirstOrDefault(q => q._id == p.Qid); if (qu != null) { ReStudentExamAnswer an = examuser == null ? null : examuser.StudentAnswerList.FirstOrDefault( pa => pa.Qid == p.Qid); var newqu = new MQuestion { QAnswerType = qu.QuestionAnswer[0].AnswerType, QType = qu.QuestionType, QuestionContent = qu.QuestionContent, QuestionID = qu._id, QuestionLevel = ((QuestionLevel)qu.QuestionLevel).ToString(), QuestionOrder = p.QOrder, Score = p.QScore, UserAnswer = an == null ? "" : (an.Answer), FillBlankCount = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Count() - 1 }; qu.QuestionAnswer.OrderBy(o => o.Order) .ToList() .ForEach(pa => newqu.QuestionAnswer.Add(new MQuestionAnswer { AnswerContent = pa.Answer, AnswerFlag = pa.AnswerFlag, AnswerType = pa.AnswerType, Order = pa.Order, QuID = newqu.QuestionID, QType = newqu.QType })); qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile { _fileName = pa.FileName, _fileType = pa.FileType, _realName = pa.RealName })); exampaper.QuestionList.Add(newqu); } }); #endregion } else { #region 随机 List <tbQuestion> questionList = Etdb.GetAllList <tbQuestion>(Query.EQ("Status", 0)); exam.QuestionRule.ForEach(p => { var newqulist = new List <tbQuestion>(); foreach (string s in p.QLevelStr.Split(';')) { newqulist.AddRange( questionList.Where( qu => p.QSort == qu.QuestionSortID && p.Qtype == qu.QuestionType && s.Split(':')[0].StringToInt32() == qu.QuestionLevel) .ToList() .RandomGetSome(s.Split(':')[1].StringToInt32())); } newqulist.ForEach(qu => { var newqu = new MQuestion { QAnswerType = qu.QuestionAnswer[0].AnswerType, QType = qu.QuestionType, QuestionContent = qu.QuestionContent, QuestionID = qu._id, QuestionLevel = ((QuestionLevel)qu.QuestionLevel).ToString(), QuestionOrder = 0, Score = p.QScore, UserAnswer = "", FillBlankCount = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Count() - 1 }; qu.QuestionAnswer.OrderBy(o => o.Order) .ToList() .ForEach(pa => newqu.QuestionAnswer.Add(new MQuestionAnswer { AnswerContent = pa.Answer, AnswerFlag = pa.AnswerFlag, AnswerType = pa.AnswerType, Order = pa.Order, QuID = newqu.QuestionID, QType = newqu.QType })); qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile { _fileName = pa.FileName, _fileType = pa.FileType, _realName = pa.RealName })); exampaper.QuestionList.Add(newqu); }); }); #endregion } //if (exampaper.ExampaperType == 1 || (examination._id > 0 && examination.RadomOrderFlag == 1)) if (exampaper.ExampaperType == 1) { //排序 int order = 1; foreach (string s in exam.QuestionTypeOrder.Split(',')) { exampaper.QuestionList.Where(p => p.QType == s.StringToInt32()) .ToList() .RandomListOrder() .ForEach(p => { p.QuestionOrder = order; order++; }); } } exampaper.QuestionList = exampaper.QuestionList.OrderBy(p => p.QuestionOrder).ToList(); }
/// <summary> /// 获取试卷的试题 /// </summary> /// <param name="exampaper">试卷信息</param> /// <param name="exam">试卷信息</param> /// <param name="examuser">学员答案</param> /// <param name="examination">考试信息</param> private void GetExampaper(ExampaperShow exampaper, tbExampaperRedundancy exam, tbExamSendStudent examuser, tbExamination examination) { var radomOrder = string.IsNullOrWhiteSpace(examination.RadomOrderFlag) ? new string[0] : examination.RadomOrderFlag.Split(','); //IMongoQuery query = Query.In("_id", new BsonArray(exam.QuestionList.Select(p => p.Qid))); IMongoQuery query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid))); if (!examuser.StudentAnswerList.Any()) { //如果没有试题,则加入试题 if (exam.ExamType == 0) { exam.QuestionList.ForEach(p => { examuser.StudentAnswerList.Add(new ReStudentExamAnswer { Qid = p.Qid, Questionid = p.Questionid, Order = p.QOrder, QType = p.QType, Score = p.QScore, DoneFlag = 0, Answer = "", Evlution = "", GetScore = 0, WrongQuestionFlag = 0 }); }); } else { examuser = new RetechWing.BusinessCommon.Examination.GenerateExampaper().RandomGenerate(examuser, exam.QuestionRule); var questionIds = examuser.StudentAnswerList.Select(p => p.Questionid); var questions = Etdb.GetAllList <tbQuestion>(Query.In("_id", new BsonArray(questionIds))); int i = 1; foreach (var item in examuser.StudentAnswerList) { var tmp = questions.FirstOrDefault(p => p._id == item.Questionid); var questionRed = new tbQuestionRedundancy { QuestionId = tmp._id, QuestionSortID = tmp.QuestionSortID, QuestionOpen = tmp.QuestionOpen, UserID = tmp.UserID, CreateTime = tmp.CreateTime, FileUpload = tmp.FileUpload, LastUpdateTime = tmp.LastUpdateTime, QuestionAnalysis = tmp.QuestionAnalysis, QuestionAnswer = tmp.QuestionAnswer, QuestionAnswerKeys = tmp.QuestionAnswerKeys, QuestionAvailable = tmp.QuestionAvailable, QuestionContent = tmp.QuestionContent, QuestionKey = tmp.QuestionKey, QuestionLevel = tmp.QuestionLevel, QuestionType = tmp.QuestionType, Status = tmp.Status, TenantId = tmp.TenantId }; item.Qid = Etdb.Insert <tbQuestionRedundancy>(questionRed); item.Order = i; i++; } } Etdb.Modify <tbExamSendStudent>(examuser); query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid))); } ////从缓存中读取所有问题 //List<tbQuestionRedundancy> quList; //获取试题 //var cachekey = "examquestions:tenant:" + exam.TenantId; //quList = _cacheService.Get<List<tbQuestionRedundancy>>(cachekey); //if (quList == null || quList.Count == 0) //{ // quList = Etdb.GetAllList<tbQuestionRedundancy>(query); // _cacheService.Set(cachekey, quList, CachingExpirationType.Stable); //} var quList = Etdb.GetAllList <tbQuestionRedundancy>(query); //题目随机 if (radomOrder.Contains("1")) { var radomList = new List <int>(); var next = 0; var length = examuser.StudentAnswerList.Count; for (int i = 0; i < length; i++) { do { next = new Random().Next(); if (!radomList.Contains(next)) { examuser.StudentAnswerList[i].Order = next; radomList.Add(next); break; } } while (true); } } var m = 0; examuser.StudentAnswerList.OrderBy(p => p.Order).ToList().ForEach(p => { p.Order = ++m; tbQuestionRedundancy qu = quList.FirstOrDefault(q => q._id == p.Qid); if (qu != null) { ReStudentExamAnswer an = examuser == null ? null : examuser.StudentAnswerList.FirstOrDefault( pa => pa.Qid == p.Qid); var newqu = new MQuestion { QAnswerType = qu.QuestionType == 6 ? qu.QuestionAnswer[0].AnswerType : 0, QType = qu.QuestionType, //QuestionContent = qu.QuestionContent, QuestionContent = qu.QuestionContent.NoHtml().HtmlDecode(), QuestionID = qu._id, QuestionLevel = EnumsLanguage.GetString(((QuestionLevel)qu.QuestionLevel).ToString()), QuestionOrder = p.Order, Score = p.Score, UserAnswer = an == null ? "" : (an.Answer), UserAnswerScore = an == null ? 0 : an.GetScore, FillBlankCount = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Length - 1, WrongQuestionFlag = an == null ? 0 : an.WrongQuestionFlag, QuestionAnalysis = qu.QuestionAnalysis }; //记录选项随机前的原有序号 var tmpquestionlist = new List <MQuestionAnswer>(); //选择随机 if (radomOrder.Contains("2")) { var radomList = new List <int>(); var next = 0; var length = qu.QuestionAnswer.Count; for (int i = 0; i < length; i++) { do { next = new Random().Next(); if (!radomList.Contains(next)) { tmpquestionlist.Add(new MQuestionAnswer { Order = next, oldOrder = qu.QuestionAnswer[i].Order }); qu.QuestionAnswer[i].Order = next; radomList.Add(next); break; } } while (true); } } var n = 0; qu.QuestionAnswer.OrderBy(o => o.Order).ToList().ForEach(pa => { var tmp = tmpquestionlist.FirstOrDefault(t => t.Order == pa.Order); pa.Order = ++n; newqu.QuestionAnswer.Add(new MQuestionAnswer { AnswerContent = pa.Answer, AnswerFlag = pa.AnswerFlag, AnswerType = pa.AnswerType, Order = pa.Order, QuID = newqu.QuestionID, QType = newqu.QType, oldOrder = tmp == null ? pa.Order : tmp.oldOrder }); }); qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile { _fileName = pa.FileName, _fileType = pa.FileType, _realName = pa.RealName })); exampaper.QuestionList.Add(newqu); } }); exampaper.QuestionList = exampaper.QuestionList.OrderBy(p => p.QuestionOrder).ToList(); }