public object GetAnswerDetial(AnswerModel bane) { if (!ModelState.IsValid) { return(OperateContext.Current.RedirectWebApi( WebResultCode.Exception, "参数验证失败", null)); } //返回数据 AnswerResultModel baneResult = operateContext.bllSession.Bane_HistoryScore.GetAnswerHistoryDetial(bane.answer_id); if (baneResult == null) { return(OperateContext.Current.RedirectWebApi(WebResultCode.Exception, "获取数据失败~", "")); } return(OperateContext.Current.RedirectWebApi(WebResultCode.Ok, "成功获取数据~", baneResult)); }
/// <summary> /// 根据答题历史记录ID 获取详细的答题记录 /// </summary> /// <param name="answer_id"></param> /// <returns></returns> public AnswerResultModel GetAnswerHistoryDetial(int answer_id) { AnswerResultModel model = new AnswerResultModel(); //1. 历史答题分数记录 Bane_HistoryScore hscore = Select(s => s.hs_id == answer_id).FirstOrDefault(); if (hscore == null) { return(null); } model.answer_date = hscore.hs_time.ToString("D"); model.answer_score = hscore.hs_score; model.answer_total = hscore.hs_total; //2. 历史答题详细记录 List <Bane_HistoryScoreDetial> sDetial = DBSession.IBane_HistoryScoreDetialDAL.Select(s => s.hs_id == answer_id); List <int> sub_ids = sDetial.Select(s => s.sub_id).ToList(); //3. 试题库 List <Bane_QuestionInfo> qInfo = DBSession.IBane_QuestionInfoDAL.GetAnswerByOptions(sub_ids); //4. 选项库 List <HCQ2_Model.Bane_QuestionValue> qValue = DBSession.IBane_QuestionValueDAL.GetOptionsById(sub_ids); List <AnswerResultDetial> issue = new List <AnswerResultDetial>(); foreach (var item in qInfo) { //4.1 选择项 List <HCQ2_Model.BaneUser.APP.Result.Bane_QuestionValue> option = new List <HCQ2_Model.BaneUser.APP.Result.Bane_QuestionValue>(); var valueTemp = qValue.Where(s => s.sub_id == item.sub_id).ToList(); foreach (var obj in valueTemp) { option.Add(new HCQ2_Model.BaneUser.APP.Result.Bane_QuestionValue { score_option = obj.score_option, score_value = obj.score_value }); } //4.2 试题 var query = sDetial.Where(s => s.sub_id == item.sub_id).FirstOrDefault(); issue.Add(new AnswerResultDetial { issue_title = item.sub_title, correct_option = query.sub_value, user_option = query.hd_value, option = option }); } model.issue = issue; return(model); }
public HttpResponseMessage AnswerQuestion(int id, string answer) { AnswerResultModel result = null; using (var ctx = _contextFactory.CreateContext()) { var question = ctx.Questions.Find(id); if (question != null) { result = new AnswerResultModel { Correct = string.Equals(question.AnswerText, answer, StringComparison.CurrentCultureIgnoreCase) }; } } return(result == null? Request.CreateResponse(HttpStatusCode.NotFound, new SimpleMessageResponseModel($"No question exists with id {id} to be answered.")) : Request.CreateResponse(HttpStatusCode.OK, result)); }