123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using EMISOnline.Entities;
- using EMISOnline.DataLogic.Repositories;
- using System.Linq.Expressions;
- using System.Data;
- using EMISOnline.ViewModel.ExamView;
- using Bowin.Common.Linq;
- namespace EMISOnline.DataLogic.ExamSetting
- {
- public class QuestionDAL : SqlHelper
- {
- public base_question_typeRepository typeRepository { get; set; }
- public questionRepository questionRepository { get; set; }
- public question_provid_answerRepository answerRepository { get; set; }
- public question_libaryRepository libaryRepository { get; set; }
- public test_base_question_type[] ListAllQuestionType()
- {
- return typeRepository.Entities.OrderBy(q => q.diplay_order).ToArray();
- }
- public decimal[] GeneratePractice(string[] libaryids, List<string> typeID, int? num)
- {
- var ds = Query("dbo.[SP_GeneratePractice]",
- new KeyValuePair<string, object>("@libryid", string.Join(",", libaryids)),
- new KeyValuePair<string, object>("@questionType", typeID.Count > 0 ? string.Join(",", typeID.ToArray()) : ""),
- new KeyValuePair<string, object>("@questionLength", num));
- return ds.Tables[0].AsEnumerable().Select(d => d.Field<decimal>("test_question_Id")).ToArray();
- }
- public object GetQuestion(decimal[] question_ids)
- {
- var query = from q in questionRepository.Entities
- //let answer = answerRepository.
- where question_ids.Contains(q.test_question_Id)
- where !q.filled
- select new
- {
- typeName = q.test_base_question_type.Name,
- q.content,
- q.test_question_Id,
- q.base_question_type_id,
- hasImg = q.question_file_id.HasValue,
- url = q.question_file_id.HasValue ? q.test_question_file.url : "",
- q.score,
- rightAnswer = q.answers,
- Answers = q.test_question_provid_answer.Select(a => new
- {
- a.answer_name,
- a.provid_answer_id,
- hasImg = a.file_id.HasValue,
- url = a.file_id.HasValue ? a.test_question_file.url : "",
- })
- };
- return query.SingleOrDefault();
- }
- public IQueryable<PaperQuestionView> GetPaperQuestion(decimal[] question_ids)
- {
- var query = from q in questionRepository.Entities
- //let answer = answerRepository.
- where question_ids.Contains(q.test_question_Id)
- where !q.filled
- select new PaperQuestionView
- {
- content = q.content,
- question_id = q.test_question_Id,
- question_typeid=q.base_question_type_id.Value,
- hasImg = q.question_file_id.HasValue,
- url = q.question_file_id.HasValue ? q.test_question_file.url : "",
- score = q.score.HasValue ? q.score.Value : 0,
- rightAnswer = q.answers,
- answers = q.test_question_provid_answer.Select(a => new Answers
- {
- content = a.answer_name,
- answer_id=a.provid_answer_id,
- hasImg = a.file_id.HasValue,
- url = a.file_id.HasValue ? a.test_question_file.url : "",
- })
- };
- return query.AsQueryable();
- }
- /// <summary>
- /// 获取所有的题库目录树数据
- /// </summary>
- /// <returns></returns>
- public System.Data.DataTable ListQuesLibTreeStu()
- {
- var query = from lib in libaryRepository.Entities
- where lib.filled == false
- select new
- {
- lib.test_question_libary_id,
- lib.name,
- lib.parent_id
- };
- return query.ToTable();
- }
- }
- }
|