public ExamQuestion GetExamQuestion(RequestGetExamQuestion request) { ExamQuestionHelper eqh = new ExamQuestionHelper(); ExamQuestion eq = eqh.GetRow(request.ExamPaper); QuestionHelper qh = new QuestionHelper(); eq.Questions = qh.GetRows(request.ExamPaper); QuestionItemHelper qih = new QuestionItemHelper(); var qis = qih.GetRows(request.ExamPaper); Dictionary<string, IList<QuestionItem>> items = new Dictionary<string,IList<QuestionItem>>(); Dictionary<string, IList<QuestionItem>> answers = new Dictionary<string,IList<QuestionItem>>(); foreach (var qi in qis) { if (!items.ContainsKey(qi.Code)) { items.Add(qi.Code, new List<QuestionItem>()); } if (!answers.ContainsKey(qi.Code)) { answers.Add(qi.Code, new List<QuestionItem>()); } items[qi.Code].Add(qi); if (!string.IsNullOrWhiteSpace(qi.Value)) { answers[qi.Code].Add(qi); } } foreach (var q in eq.Questions) { q.Items = items[q.Code]; q.Answers = answers[q.Code]; } return eq; }
public ResultMessage SetExamQuestion(ExamQuestion request) { ExamQuestionHelper eqh = new ExamQuestionHelper(); QuestionHelper qh = new QuestionHelper(); QuestionItemHelper qih = new QuestionItemHelper(); ResultMessage result = new ResultMessage(); result = eqh.Create(request.ExamPaper, request.Byname, request.TotalFullScore, request.LimitTime, request.OwnerType); if (!result.State) return result; foreach (var q in request.Questions) { var q_guid = Guid.NewGuid().ToString(); result = qh.Create(q_guid, request.ExamPaper, q.Code, q.QuestionType, q.QuestionContent, q.FullScore, q.Comment); if (!result.State) return result; if (q.Items == null || q.Items.Count == 0) continue; foreach (var qi in q.Items) { if (string.IsNullOrWhiteSpace(qi.ItemOrder)) continue; foreach (var qia in q.Answers) { if (qi.ItemOrder == qia.ItemOrder) { qi.Value = qia.Value; qi.ExpandValue = qia.ExpandValue; break; } } result = qih.Create(Guid.NewGuid().ToString(), q_guid, qi.ItemOrder, qi.ItemAnswer, qi.Value, qi.ExpandValue, qi.IsWrite ); if (!result.State) return result; } } return result; }