QuestionDAL.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMISOnline.Entities;
  6. using EMISOnline.DataLogic.Repositories;
  7. using System.Linq.Expressions;
  8. using System.Data;
  9. using EMISOnline.ViewModel.ExamView;
  10. using Bowin.Common.Linq;
  11. namespace EMISOnline.DataLogic.ExamSetting
  12. {
  13. public class QuestionDAL : SqlHelper
  14. {
  15. public base_question_typeRepository typeRepository { get; set; }
  16. public questionRepository questionRepository { get; set; }
  17. public question_provid_answerRepository answerRepository { get; set; }
  18. public question_libaryRepository libaryRepository { get; set; }
  19. public test_base_question_type[] ListAllQuestionType()
  20. {
  21. return typeRepository.Entities.OrderBy(q => q.diplay_order).ToArray();
  22. }
  23. public decimal[] GeneratePractice(string[] libaryids, List<string> typeID, int? num)
  24. {
  25. var ds = Query("dbo.[SP_GeneratePractice]",
  26. new KeyValuePair<string, object>("@libryid", string.Join(",", libaryids)),
  27. new KeyValuePair<string, object>("@questionType", typeID.Count > 0 ? string.Join(",", typeID.ToArray()) : ""),
  28. new KeyValuePair<string, object>("@questionLength", num));
  29. return ds.Tables[0].AsEnumerable().Select(d => d.Field<decimal>("test_question_Id")).ToArray();
  30. }
  31. public object GetQuestion(decimal[] question_ids)
  32. {
  33. var query = from q in questionRepository.Entities
  34. //let answer = answerRepository.
  35. where question_ids.Contains(q.test_question_Id)
  36. where !q.filled
  37. select new
  38. {
  39. typeName = q.test_base_question_type.Name,
  40. q.content,
  41. q.test_question_Id,
  42. q.base_question_type_id,
  43. hasImg = q.question_file_id.HasValue,
  44. url = q.question_file_id.HasValue ? q.test_question_file.url : "",
  45. q.score,
  46. rightAnswer = q.answers,
  47. Answers = q.test_question_provid_answer.Select(a => new
  48. {
  49. a.answer_name,
  50. a.provid_answer_id,
  51. hasImg = a.file_id.HasValue,
  52. url = a.file_id.HasValue ? a.test_question_file.url : "",
  53. })
  54. };
  55. return query.SingleOrDefault();
  56. }
  57. public IQueryable<PaperQuestionView> GetPaperQuestion(decimal[] question_ids)
  58. {
  59. var query = from q in questionRepository.Entities
  60. //let answer = answerRepository.
  61. where question_ids.Contains(q.test_question_Id)
  62. where !q.filled
  63. select new PaperQuestionView
  64. {
  65. content = q.content,
  66. question_id = q.test_question_Id,
  67. question_typeid=q.base_question_type_id.Value,
  68. hasImg = q.question_file_id.HasValue,
  69. url = q.question_file_id.HasValue ? q.test_question_file.url : "",
  70. score = q.score.HasValue ? q.score.Value : 0,
  71. rightAnswer = q.answers,
  72. answers = q.test_question_provid_answer.Select(a => new Answers
  73. {
  74. content = a.answer_name,
  75. answer_id=a.provid_answer_id,
  76. hasImg = a.file_id.HasValue,
  77. url = a.file_id.HasValue ? a.test_question_file.url : "",
  78. })
  79. };
  80. return query.AsQueryable();
  81. }
  82. /// <summary>
  83. /// 获取所有的题库目录树数据
  84. /// </summary>
  85. /// <returns></returns>
  86. public System.Data.DataTable ListQuesLibTreeStu()
  87. {
  88. var query = from lib in libaryRepository.Entities
  89. where lib.filled == false
  90. select new
  91. {
  92. lib.test_question_libary_id,
  93. lib.name,
  94. lib.parent_id
  95. };
  96. return query.ToTable();
  97. }
  98. }
  99. }