QuestionService.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. using DocumentFormat.OpenXml.Office2010.Excel;
  2. using Exam.Application;
  3. using Exam.Infrastructure.Data.Entity;
  4. using Exam.Infrastructure.Enums;
  5. using Exam.Infrastructure.Extensions;
  6. using Exam.Share.ViewResponses.Question;
  7. using Hotline.Application.Exam.QueryExtensions.Questions;
  8. using Hotline.Exams.Sourcewares;
  9. using Hotline.Repository.SqlSugar;
  10. using Hotline.Repository.SqlSugar.DataPermissions;
  11. using Hotline.Repository.SqlSugar.Exam.Interfaces.Questions;
  12. using Hotline.Share.Dtos.Questions;
  13. using Hotline.Share.Requests.Question;
  14. using JiebaNet.Segmenter.Common;
  15. using MapsterMapper;
  16. using SqlSugar;
  17. using XF.Domain.Dependency;
  18. using XF.Domain.Entities;
  19. using Hotline.Application.Exam.Extensions;
  20. using Hotline.Application.Exam.Core.Extensions;
  21. using Hotline.Application.Exam.Constants.Messages;
  22. using Hotline.Repository.SqlSugar.Exam.Core.Constants;
  23. using NPOI.SS.Formula.Functions;
  24. using XF.Domain.Authentications;
  25. using Hotline.Tools;
  26. using Microsoft.AspNetCore.Http;
  27. using System.Dynamic;
  28. using NPOI.Util.ArrayExtensions;
  29. using System.Threading.Tasks;
  30. using Hotline.Share.Enums.Exams;
  31. using Hotline.Share.Tools;
  32. using DocumentFormat.OpenXml.Drawing;
  33. using Hotline.Application.Exam.Core.Utilities;
  34. using Hotline.Application.Exam.Interface.Questions;
  35. using Hotline.Exams.ExamManages;
  36. using Hotline.Exams.Questions;
  37. using Hotline.Repository.SqlSugar.Exam.Repositories;
  38. using Hotline.Share.Dtos.TestPapers;
  39. using ExamQuestion = Hotline.Exams.Questions.ExamQuestion;
  40. using ExamQuestionAnswer = Hotline.Exams.Questions.ExamQuestionAnswer;
  41. using ExamQuestionKnowladge = Hotline.Exams.Questions.ExamQuestionKnowladge;
  42. using ExamQuestionOptions = Hotline.Exams.Questions.ExamQuestionOptions;
  43. using ExamQuestionSourceware = Hotline.Exams.Questions.ExamQuestionSourceware;
  44. using Hotline.Repository.SqlSugar.Exam.Service;
  45. using Hotline.Repository.SqlSugar.Exam.Extensions;
  46. namespace Hotline.Application.Exam.Service.Questions
  47. {
  48. public class QuestionService : ApiService<ExamQuestion, AddQuestionDto,UpdateQuestionDto, HotlineDbContext>, IQuestionService, IScopeDependency
  49. {
  50. #region ctor
  51. private readonly IQuestionRepository _repository;
  52. private readonly IQuestionTagRepository _questionTagRepository;
  53. private readonly IQuestionOptionsRepository _questionOptionRepository;
  54. private readonly IQuestionAnswerRepository _questionAnswerRepository;
  55. private readonly IQuestionSourcewareRepository _questionSourcewareRepository;
  56. private readonly IQuestionKnowladgeRepository _questionKnowladgeRepository;
  57. private readonly IDataPermissionFilterBuilder _dataPermissionFilterBuilder;
  58. private readonly IServiceProvider _serviceProvider;
  59. private readonly IMapper _mapper;
  60. private readonly ISessionContext _sessionContext;
  61. private AddQuestionDto _addQuestionDto;
  62. public QuestionService(IQuestionRepository repository,
  63. IQuestionTagRepository questionTagRepository,
  64. IQuestionOptionsRepository questionOptionsRepository,
  65. IQuestionAnswerRepository questionAnswerRepository,
  66. IQuestionSourcewareRepository questionSourcewareRepository,
  67. IQuestionKnowladgeRepository questionKnowladgeRepository,
  68. IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider,
  69. IMapper mapper,
  70. ISessionContext sessionContext
  71. ) : base(repository,mapper)
  72. {
  73. _repository = repository;
  74. _questionTagRepository = questionTagRepository;
  75. _questionAnswerRepository = questionAnswerRepository;
  76. _questionOptionRepository = questionOptionsRepository;
  77. _questionSourcewareRepository = questionSourcewareRepository;
  78. _questionKnowladgeRepository = questionKnowladgeRepository;
  79. _dataPermissionFilterBuilder = dataPermissionFilterBuilder;
  80. _serviceProvider = serviceProvider;
  81. _mapper = mapper;
  82. this._sessionContext = sessionContext;
  83. }
  84. #endregion
  85. #region public method
  86. public async Task<QuestionDto> GetAsync(EntityQueryRequest entityQueryRequest)
  87. {
  88. var entity = await _repository.GetAsync(entityQueryRequest.Id);
  89. var questionDto = _mapper.Map<QuestionDto>(entity);
  90. if (questionDto != null)
  91. {
  92. questionDto.QuestionTagDtos = await GetQuestionTags(entityQueryRequest);
  93. questionDto.QuestionAnswerDto = await GetQuestionAnswer(entityQueryRequest);
  94. questionDto.QuestionKnowladgeDtos = await GetKnowladges(entityQueryRequest);
  95. questionDto.QuestionOptionsDtos = await GetQuestionOptions(entityQueryRequest);
  96. questionDto.QuestionSourcewareDtos = await GetQuestionSourcewares(entityQueryRequest);
  97. }
  98. return questionDto;
  99. }
  100. public async Task<(int, List<QuestionViewResponse>)> GetListAsync(QuestionPagedRequest queryRequest)
  101. {
  102. var expression = queryRequest.GetExpression();
  103. var questionTable = _repository.Queryable().Where(expression);
  104. var questionKnowladgeExpression = queryRequest.GetQuestionKnowladgeExpression();
  105. var questionKnowladgeTable = new ExamRepository<ExamQuestionKnowladge>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable().Where(questionKnowladgeExpression);
  106. var queryable = questionTable.InnerJoin(questionKnowladgeTable, (q, k) => q.Id == k.QuestionId).Select((q, k) => new QuestionViewResponse
  107. {
  108. DifficultyLevel = q.DifficultyLevel,
  109. Title = q.Title,
  110. QuestionType = q.QuestionType,
  111. Id= q.Id
  112. });
  113. var result = await queryable.ToListAsync();
  114. var total = await queryable.CountAsync();
  115. return (total, result);
  116. }
  117. public async Task<PageViewResponse<QuestionViewResponse>> GetPagedListAsync(QuestionPagedRequest queryRequest)
  118. {
  119. var expression = queryRequest.GetExpression();
  120. var questionTable = _repository.Queryable().Where(expression);
  121. var questionTagExpression = queryRequest.GetQuestionTagExpression();
  122. var questionTagRepository = new BaseRepository<ExamQuestionTag>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
  123. var examTagRepository = new BaseRepository<ExamTag>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
  124. var questionTagTable = questionTagRepository.Queryable().Where(questionTagExpression);
  125. var allQuestionTagTable = questionTagRepository.Queryable();
  126. var examTagExpression = queryRequest.GetExamTagExpression();
  127. var examTagTable = examTagRepository.Queryable().Where(examTagExpression);
  128. var allExamTagTable = examTagRepository.Queryable();
  129. var queryable = questionTable.InnerJoin(questionTagTable, (s, d) => s.Id == d.QuestionId).InnerJoin(examTagTable, (s,d, t) => d.TagId == t.Id)
  130. .Distinct()
  131. .Select((s, d, t) => new QuestionViewResponse
  132. {
  133. DifficultyLevel = s.DifficultyLevel,
  134. FormalEnable = s.FormalEnable,
  135. SimulateEnable = s.SimulateEnable,
  136. SortIndex = s.SortIndex,
  137. Status =s.Status,
  138. QuestionType = s.QuestionType,
  139. Title = s.Title,
  140. Id = s.Id
  141. });
  142. var list = await queryable.ToPageListAsync(queryRequest.PageIndex, queryRequest.PageSize);
  143. var total = await queryable.CountAsync();
  144. var questionIds = list.Select(x => x.Id);
  145. var tags = await allQuestionTagTable.Where(x => questionIds.Contains(x.QuestionId))
  146. .InnerJoin(allExamTagTable, (q, e) => q.TagId == e.Id)
  147. .Select((q, e) => new TagQuestionDto
  148. {
  149. Id = q.QuestionId,
  150. TagId = q.TagId,
  151. Tag = e.Name
  152. }).ToListAsync();
  153. list.ForEach(item =>
  154. {
  155. item.Tag = string.Join(",", tags.Where(x => x.Id == item.Id).Select(x => x.Tag));
  156. });
  157. var result = new QuestionPageViewResponse
  158. {
  159. Items = list,
  160. Pagination = new Pagination(queryRequest.PageIndex, queryRequest.PageSize, total)
  161. };
  162. return result;
  163. }
  164. public override async Task<string> AddAsync(AddQuestionDto actionRequest, CancellationToken cancellationToken)
  165. {
  166. base.StartTran();
  167. base.Entity= await AddQuestion(actionRequest, cancellationToken);
  168. await base.Complete(base.Entity, OperationConstant.Create);
  169. return base.Entity.Id;
  170. }
  171. public override async Task UpdateAsync(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
  172. {
  173. base.StartTran();
  174. await base.UpdateAsync(actionRequest, cancellationToken);
  175. ResolveQuestionId(actionRequest, actionRequest.Id);
  176. _addQuestionDto = _mapper.Map<AddQuestionDto>(actionRequest);
  177. base.Entity.QuestionTags = await ModifyQuestionTags(actionRequest, cancellationToken);
  178. base.Entity.QuestionOptionses = await ModifyQuestionOptions(actionRequest, cancellationToken);
  179. base.Entity.QuestionAnswers = await ModifyQuestionAnswer(actionRequest, cancellationToken);
  180. base.Entity.QuestionKnowladges = await ModifyKnowladges(actionRequest, cancellationToken);
  181. base.Entity.QuestionSourcewares = await ModifySourcewares(actionRequest, cancellationToken);
  182. await base.Complete(base.Entity,OperationConstant.Update);
  183. }
  184. public override async Task DeleteAsync(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
  185. {
  186. await base.DeleteAsync(entityQueryRequest, cancellationToken);
  187. var tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<ExamQuestionTag>()
  188. .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
  189. .AndIF(entityQueryRequest.Ids.IsNotNullOrEmpty(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
  190. .ToEntityQueryRequest<ExamQuestionTag>();
  191. await DeleteQuestionTags(tmpEntityQueryRequest, cancellationToken);
  192. tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<ExamQuestionOptions>()
  193. .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
  194. .AndIF(entityQueryRequest.Ids.IsNotNullOrEmpty(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
  195. .ToEntityQueryRequest<ExamQuestionOptions>();
  196. await DeleteQuestionOptions(tmpEntityQueryRequest, cancellationToken);
  197. tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<ExamQuestionAnswer>()
  198. .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
  199. .AndIF(entityQueryRequest.Ids.IsNotNullOrEmpty(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
  200. .ToEntityQueryRequest<ExamQuestionAnswer>();
  201. await DeleteQuestionAnswer(tmpEntityQueryRequest, cancellationToken);
  202. tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<ExamQuestionKnowladge>()
  203. .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
  204. .AndIF(entityQueryRequest.Ids.IsNotNullOrEmpty(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
  205. .ToEntityQueryRequest<ExamQuestionKnowladge>();
  206. await DeleteKnowladges(tmpEntityQueryRequest, cancellationToken);
  207. tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<ExamQuestionSourceware>()
  208. .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
  209. .AndIF(entityQueryRequest.Ids.IsNotNullOrEmpty(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
  210. .ToEntityQueryRequest<ExamQuestionSourceware>();
  211. await DeleteSourcewares(tmpEntityQueryRequest, cancellationToken);
  212. }
  213. public async Task ImportExcel(IFormFile files, CancellationToken cancellationToken)
  214. {
  215. using (var stream = files.OpenReadStream())
  216. {
  217. var contents = ExcelHelper.Read(stream, true);
  218. var questions = new List<ExamQuestion>();
  219. var examTags = await GetExamTags(contents);
  220. base.StartTran();
  221. contents.ForEach(async item =>
  222. {
  223. var questionDto = BuildQuestion(item as ExpandoObject, examTags);
  224. var question = await AddQuestion(questionDto, cancellationToken);
  225. if (question != null)
  226. questions.Add(question);
  227. });
  228. await _repository.AddNav(questions)
  229. .Include(x => x.QuestionTags)
  230. .Include(x => x.QuestionOptionses)
  231. .Include(x => x.QuestionSourcewares)
  232. .Include(x => x.QuestionAnswers)
  233. .Include(x => x.QuestionKnowladges).ExecuteCommandAsync();
  234. }
  235. }
  236. private async Task<List<ExamTag>> GetExamTags(List<object> contents)
  237. {
  238. var examTags = new List<ExamTag>();
  239. var tagNames = new List<string>();
  240. contents.ForEach(item =>
  241. {
  242. var tagNameStr = ((ExpandoObject)item).GetValueOrDefault(ExamSystemConstants.ColumnNames[1])?.ToString();
  243. if (tagNameStr.IsNotNullOrEmpty())
  244. {
  245. var names = tagNameStr.Split(",").ToList();
  246. names.ForEach(name =>
  247. {
  248. if (!tagNames.Contains(name))
  249. {
  250. tagNames.Add(name);
  251. }
  252. });
  253. }
  254. });
  255. var repository = new ExamRepository<ExamTag>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
  256. examTags = await repository.Queryable().Where(x => tagNames.Contains(x.Name)).ToListAsync();
  257. return examTags;
  258. }
  259. private AddQuestionDto BuildQuestion(ExpandoObject item,List<ExamTag> examTags)
  260. {
  261. if (item != null) {
  262. var options = new List<string>();
  263. ResolveOptions(options,item,6,15);
  264. var answer = item.GetValueOrDefault(ExamSystemConstants.ColumnNames[16]).ToString();
  265. var questionDto = new AddQuestionDto
  266. {
  267. Title = item.GetValueOrDefault(ExamSystemConstants.ColumnNames[2]) != null ? item.GetValueOrDefault(ExamSystemConstants.ColumnNames[5]).ToString() : string.Empty,
  268. QuestionTagDtos = BuildQuestionTags(item.GetValueOrDefault(ExamSystemConstants.ColumnNames[1]).ToString(), examTags),
  269. DifficultyLevel = item.GetValueOrDefault(ExamSystemConstants.ColumnNames[2]).ToString().ToEnumByDesc<EDifficultyLevel>(),
  270. QuestionType = item.GetValueOrDefault(ExamSystemConstants.ColumnNames[0]).ToString().ToEnumByDesc<EQuestionType>(),
  271. FormalEnable = item.GetValueOrDefault(ExamSystemConstants.ColumnNames[4]).ToString().ToEnumByDesc<ECheck>() == ECheck.Yes,
  272. SimulateEnable = item.GetValueOrDefault(ExamSystemConstants.ColumnNames[5]).ToString().ToEnumByDesc<ECheck>() == ECheck.Yes,
  273. };
  274. questionDto.QuestionAnswerDto = BuildQuestionAnswer(answer, questionDto.QuestionType);
  275. questionDto.QuestionOptionsDtos = BuildQuestionOptions(options, questionDto.QuestionType, answer);
  276. return questionDto;
  277. }
  278. return null;
  279. }
  280. private List<AddQuestionOptionsDto> BuildQuestionOptions(List<string> options,EQuestionType questionType,string answer)
  281. {
  282. if (questionType.CheckSelectType())
  283. {
  284. var addQuestionOptionDtos = new List<AddQuestionOptionsDto>();
  285. var index = 0;
  286. options.ForEach(item =>
  287. {
  288. var addQuestionOption = new AddQuestionOptionsDto
  289. {
  290. Content = item,
  291. Label = ExamSystemConstants.Labels[index],
  292. IsAnswer = answer.Contains(ExamSystemConstants.Labels[index])
  293. };
  294. addQuestionOptionDtos.Add(addQuestionOption);
  295. index++;
  296. });
  297. return addQuestionOptionDtos;
  298. }
  299. return null;
  300. }
  301. private void ResolveOptions(List<string> options, ExpandoObject item, int start, int end)
  302. {
  303. for(int i = start; i <= end; i++)
  304. {
  305. var option = item.GetValueOrDefault(ExamSystemConstants.ColumnNames[i])?.ToString();
  306. if (option.IsNotNullOrEmpty())
  307. {
  308. options.Add(option.ToString());
  309. }
  310. }
  311. }
  312. private AddQuestionAnswerDto BuildQuestionAnswer(string? content, EQuestionType questionType)
  313. {
  314. if (!questionType.CheckSelectType())
  315. {
  316. var addQuestionAnswerDto = new AddQuestionAnswerDto
  317. {
  318. Answer = content
  319. };
  320. return addQuestionAnswerDto;
  321. }
  322. return null;
  323. }
  324. private List<AddQuestionTagDto> BuildQuestionTags(string content,List<ExamTag> examTags)
  325. {
  326. if (content.IsNotNullOrEmpty())
  327. {
  328. var addQuestionTagDtos = new List<AddQuestionTagDto>();
  329. var tagNames = content.Split(",");
  330. tagNames.ToList().ForEach(item =>
  331. {
  332. var examTag = examTags.FirstOrDefault(x => x.Name == item);
  333. if (examTag != null)
  334. {
  335. addQuestionTagDtos.Add(new AddQuestionTagDto
  336. {
  337. TagId = examTag.Id
  338. });
  339. }
  340. });
  341. return addQuestionTagDtos;
  342. }
  343. return null;
  344. }
  345. #endregion
  346. #region private method
  347. private void ResolveQuestionId(AddQuestionDto actionRequest,string id)
  348. {
  349. actionRequest.QuestionKnowladgeDtos?.ForEach(x => x.QuestionId = id);
  350. actionRequest.QuestionOptionsDtos?.ForEach(x => x.QuestionId = id);
  351. actionRequest.QuestionSourcewareDtos?.ForEach(x => x.QuestionId = id);
  352. actionRequest.QuestionTagDtos?.ForEach(x => x.QuestionId = id);
  353. if (actionRequest.QuestionAnswerDto != null)
  354. {
  355. actionRequest.QuestionAnswerDto.QuestionId = id;
  356. }
  357. }
  358. private void ResolveQuestionId(UpdateQuestionDto actionRequest, string id)
  359. {
  360. actionRequest.QuestionKnowladgeDtos?.ForEach(x => x.QuestionId = id);
  361. actionRequest.QuestionOptionsDtos?.ForEach(x => x.QuestionId = id);
  362. actionRequest.QuestionSourcewareDtos?.ForEach(x => x.QuestionId = id);
  363. actionRequest.QuestionTagDtos?.ForEach(x => x.QuestionId = id);
  364. if (actionRequest.QuestionAnswerDto != null)
  365. {
  366. actionRequest.QuestionAnswerDto.QuestionId = id;
  367. }
  368. }
  369. private async Task<List<ExamQuestionTag>> AddQuestionTags(AddQuestionDto actionRequest, CancellationToken cancellationToken)
  370. {
  371. if (actionRequest.QuestionTagDtos == null) return null;
  372. actionRequest.QuestionTagDtos.ResolveOperationStatus();
  373. var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == EEOperationStatus.Add).ToList();
  374. var questionTags = _mapper.Map<List<ExamQuestionTag>>(questionTagDtos);
  375. questionTags.ToInsert(_sessionContext);
  376. await _questionTagRepository.ValidateAddAsync(questionTags, cancellationToken);
  377. return questionTags;
  378. }
  379. private async Task<List<ExamQuestionOptions>> AddQuestionOptions(AddQuestionDto actionRequest, CancellationToken cancellationToken)
  380. {
  381. if (actionRequest.QuestionOptionsDtos == null) return null;
  382. actionRequest.QuestionOptionsDtos.ResolveOperationStatus();
  383. // 简答和填空没有选项
  384. if (actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Essay || actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Blank)
  385. return null;
  386. var questionOptionseDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == EEOperationStatus.Add).ToList();
  387. var questionOptionses = _mapper.Map<List<ExamQuestionOptions>>(questionOptionseDtos);
  388. var sortIndex = 0;
  389. questionOptionses.ForEach(m =>
  390. {
  391. m.SortIndex = sortIndex;
  392. m.Label = ExamSystemConstants.Labels[sortIndex];
  393. sortIndex++;
  394. });
  395. questionOptionses.ToInsert(_sessionContext);
  396. await _questionOptionRepository.ValidateAddAsync(questionOptionses, cancellationToken);
  397. return questionOptionses;
  398. }
  399. private async Task<List<ExamQuestionAnswer>> AddQuestionAnswer(AddQuestionDto actionRequest, CancellationToken cancellationToken)
  400. {
  401. if (actionRequest.QuestionAnswerDto == null) return null;
  402. if (actionRequest.QuestionAnswerDto.Answer != null)
  403. {
  404. actionRequest.QuestionAnswerDto.OperationStatus = EEOperationStatus.Add;
  405. }
  406. // 简答和填空没有选项
  407. if (actionRequest.QuestionType.CheckSelectType()) return null;
  408. var questionAnswer = _mapper.Map<ExamQuestionAnswer>(actionRequest.QuestionAnswerDto);
  409. var questionAnswers = new List<ExamQuestionAnswer>();
  410. questionAnswer.ToInsert(_sessionContext);
  411. questionAnswers.Add(questionAnswer);
  412. await _questionAnswerRepository.ValidateAddAsync(questionAnswer, cancellationToken);
  413. return questionAnswers;
  414. }
  415. private async Task<List<ExamQuestionSourceware>> AddSourcewares(AddQuestionDto actionRequest, CancellationToken cancellationToken)
  416. {
  417. if (actionRequest.QuestionSourcewareDtos == null) return null;
  418. actionRequest.QuestionSourcewareDtos.ResolveOperationStatus();
  419. var questionSourcewareDtos = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == EEOperationStatus.Add).ToList();
  420. var questionSourcewares = _mapper.Map<List<ExamQuestionSourceware>>(questionSourcewareDtos);
  421. questionSourcewares.ToInsert(_sessionContext);
  422. await _questionSourcewareRepository.ValidateAddAsync(questionSourcewares, cancellationToken);
  423. return questionSourcewares;
  424. }
  425. private async Task<List<ExamQuestionKnowladge>> AddKnowladges(AddQuestionDto actionRequest, CancellationToken cancellationToken)
  426. {
  427. if (actionRequest.QuestionKnowladgeDtos == null) return null;
  428. actionRequest.QuestionKnowladgeDtos.ResolveOperationStatus();
  429. var questionKnoladgeDtos = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == EEOperationStatus.Add).ToList();
  430. var questionKnowladges = _mapper.Map<List<ExamQuestionKnowladge>>(questionKnoladgeDtos);
  431. questionKnowladges.ToInsert(_sessionContext);
  432. await _questionKnowladgeRepository.ValidateAddAsync(questionKnowladges, cancellationToken);
  433. return questionKnowladges;
  434. }
  435. private async Task<List<ExamQuestionSourceware>> UpdateSourcewares(UpdateQuestionDto actionRequest, List<ExamQuestionSourceware> all, CancellationToken cancellationToken)
  436. {
  437. if (actionRequest.QuestionSourcewareDtos == null) return null;
  438. actionRequest.QuestionSourcewareDtos.ResolveOperationStatus();
  439. var questionSourcewareDtos = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == EEOperationStatus.Update).ToList();
  440. var ids = questionSourcewareDtos.Select(x => x.Id);
  441. var questionSourcewares = all.Where(x => ids.Contains(x.Id)).ToList();
  442. var entitys = new List<ExamQuestionSourceware>();
  443. foreach (var questionSourcewareDto in questionSourcewareDtos)
  444. {
  445. var entity = questionSourcewares.FirstOrDefault(x => x.Id == questionSourcewareDto.Id);
  446. if (entity != null)
  447. {
  448. entity.QuestionId = actionRequest.Id;
  449. entitys.Add(_mapper.Map<UpdateQuestionSourcewareDto, ExamQuestionSourceware>(questionSourcewareDto, entity));
  450. }
  451. }
  452. //questionSourcewares = _mapper.Map<List<UpdateQuestionSourcewareDto>,List<QuestionSourceware>>(questionSourcewareDtos,questionSourcewares);
  453. //questionSourcewares.ForEach(x => x.QuestionId = actionRequest.Id);
  454. questionSourcewares.ToUpdate(_sessionContext);
  455. await _questionSourcewareRepository.ValidateUpdateAsync(questionSourcewares, cancellationToken);
  456. return questionSourcewares;
  457. }
  458. private async Task<List<ExamQuestionKnowladge>> UpdateKnowladges(UpdateQuestionDto actionRequest, List<ExamQuestionKnowladge> all, CancellationToken cancellationToken)
  459. {
  460. if (actionRequest.QuestionKnowladgeDtos == null) return null;
  461. actionRequest.QuestionKnowladgeDtos.ResolveOperationStatus();
  462. var questionKnowladgeDtos = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == EEOperationStatus.Add).ToList();
  463. var ids = questionKnowladgeDtos.Select(x => x.Id);
  464. var questionKnowladges = all.Where(x => ids.Contains(x.Id)).ToList();
  465. var entitys = new List<ExamQuestionKnowladge>();
  466. foreach (var questionKnowladgeDto in questionKnowladgeDtos)
  467. {
  468. var entity = questionKnowladges.FirstOrDefault(x => x.Id == questionKnowladgeDto.Id);
  469. if (entity != null)
  470. {
  471. entity.QuestionId = actionRequest.Id;
  472. entitys.Add(_mapper.Map<UpdateQuestionKnowladgeDto, ExamQuestionKnowladge>(questionKnowladgeDto, entity));
  473. }
  474. }
  475. //questionKnowladges = _mapper.Map<List<UpdateQuestionKnowladgeDto>, List<QuestionKnowladge>>(questionKnowladgeDtos,questionKnowladges);
  476. //questionKnowladges.ForEach(x => x.QuestionId = actionRequest.Id);
  477. questionKnowladges.ToUpdate(_sessionContext);
  478. await _questionKnowladgeRepository.ValidateUpdateAsync(questionKnowladges, cancellationToken);
  479. return questionKnowladges;
  480. }
  481. private async Task<ExamQuestionAnswer> UpdateQuestionAnswer(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
  482. {
  483. if (actionRequest.QuestionAnswerDto == null) return null;
  484. // 简单和填空没有选项
  485. if (actionRequest.QuestionType.CheckSelectType()) return null;
  486. var questionAnswer = await _questionAnswerRepository.GetAsync(actionRequest.QuestionAnswerDto.Id);
  487. questionAnswer = _mapper.Map<UpdateQuestionAnswerDto, ExamQuestionAnswer>(actionRequest.QuestionAnswerDto, questionAnswer);
  488. questionAnswer.QuestionId = actionRequest.Id;
  489. questionAnswer.ToUpdate(_sessionContext);
  490. await _questionAnswerRepository.ValidateUpdateAsync(questionAnswer, cancellationToken);
  491. return questionAnswer;
  492. }
  493. private async Task<List<ExamQuestionOptions>> UpdateQuestionOptions(UpdateQuestionDto actionRequest,List<ExamQuestionOptions> all, CancellationToken cancellationToken)
  494. {
  495. if (actionRequest.QuestionOptionsDtos == null) return null;
  496. // 简单和填空没有选项
  497. if (actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Essay || actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Blank)
  498. return null;
  499. var questionOptionsDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == EEOperationStatus.Update).ToList();
  500. var ids = questionOptionsDtos.Select(x => x.Id);
  501. var questionOptionses = all.Where(x => ids.Contains(x.Id)).ToList();
  502. var entitys = new List<ExamQuestionOptions>();
  503. foreach(var questionOptionsDto in questionOptionsDtos)
  504. {
  505. var entity = questionOptionses.FirstOrDefault(x => x.Id == questionOptionsDto.Id);
  506. if (entity != null)
  507. {
  508. entity.QuestionId = actionRequest.Id;
  509. entitys.Add(_mapper.Map<UpdateQuestionOptionsDto, ExamQuestionOptions>(questionOptionsDto, entity));
  510. }
  511. }
  512. //questionOptionses = _mapper.Map<List<QuestionOptionsDto>, List<QuestionOptions>>(questionOptionsDtos,questionOptionses);
  513. //entitys.ForEach(x => x.QuestionId = actionRequest.Id);
  514. entitys.ToUpdate(_sessionContext);
  515. await _questionOptionRepository.ValidateUpdateAsync(entitys, cancellationToken);
  516. return entitys;
  517. }
  518. private async Task<List<ExamQuestionTag>> UpdateQuestionTags(UpdateQuestionDto actionRequest,List<ExamQuestionTag> all, CancellationToken cancellationToken)
  519. {
  520. if (actionRequest.QuestionTagDtos == null) return null;
  521. var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == EEOperationStatus.Update).ToList();
  522. var ids = questionTagDtos.Select(x => x.Id);
  523. var questionTags = all.Where(x => ids.Contains(x.Id)).ToList();
  524. var entitys = new List<ExamQuestionTag>();
  525. foreach (var questionOptionsDto in questionTagDtos)
  526. {
  527. var entity = questionTags.FirstOrDefault(x => x.Id == questionOptionsDto.Id);
  528. if (entity != null)
  529. {
  530. entity.QuestionId = actionRequest.Id;
  531. entitys.Add(_mapper.Map<UpdateQuestionTagDto, ExamQuestionTag>(questionOptionsDto, entity));
  532. }
  533. }
  534. //questionTags = _mapper.Map<List<UpdateQuestionTagDto>, List<QuestionTag>>(questionTagDtos,questionTags);
  535. questionTags.ToUpdate(_sessionContext);
  536. await _questionTagRepository.ValidateUpdateAsync(questionTags, cancellationToken);
  537. return questionTags;
  538. }
  539. private async Task DeleteSourcewares(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
  540. {
  541. await _questionSourcewareRepository.DeleteWithValidateAsync(entityQueryRequest, cancellationToken);
  542. }
  543. private async Task DeleteKnowladges(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
  544. {
  545. await _questionKnowladgeRepository.DeleteWithValidateAsync(entityQueryRequest, cancellationToken);
  546. }
  547. private async Task DeleteQuestionAnswer(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
  548. {
  549. await _questionAnswerRepository.DeleteWithValidateAsync(entityQueryRequest, cancellationToken);
  550. }
  551. private async Task DeleteQuestionOptions(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
  552. {
  553. await _questionOptionRepository.DeleteWithValidateAsync(entityQueryRequest, cancellationToken);
  554. }
  555. private async Task DeleteQuestionTags(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
  556. {
  557. await _questionTagRepository.DeleteWithValidateAsync(entityQueryRequest, cancellationToken);
  558. }
  559. private async Task<List<ExamQuestionSourceware>> ModifySourcewares(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
  560. {
  561. var all = await _questionSourcewareRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
  562. if (actionRequest.QuestionSourcewareDtos == null) return null;
  563. var questionSourcewares = new List<ExamQuestionSourceware>();
  564. actionRequest.QuestionSourcewareDtos.ResolveOperationStatus(all);
  565. _addQuestionDto.QuestionSourcewareDtos = _mapper.Map<List<UpdateQuestionSourcewareDto>, List<AddQuestionSourcewareDto>>(actionRequest.QuestionSourcewareDtos);
  566. _addQuestionDto.QuestionSourcewareDtos.ResolveOperationStatus();
  567. questionSourcewares.AddRangeExt(await AddSourcewares(_addQuestionDto, cancellationToken));
  568. questionSourcewares.AddRangeExt(await UpdateSourcewares(actionRequest, all, cancellationToken));
  569. var questionSourcewareDtos = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
  570. var ids = questionSourcewareDtos.Select(m => m.Id);
  571. EntityQueryRequest entityQueryRequest = ResovleDelete<ExamQuestionSourceware>(ids);
  572. await DeleteSourcewares(entityQueryRequest, cancellationToken);
  573. return questionSourcewares;
  574. }
  575. private async Task<List<ExamQuestionKnowladge>> ModifyKnowladges(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
  576. {
  577. var all = await _questionKnowladgeRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
  578. if (actionRequest.QuestionKnowladgeDtos == null) return null;
  579. var questionKnowladges = new List<ExamQuestionKnowladge>();
  580. actionRequest.QuestionKnowladgeDtos.ResolveOperationStatus(all);
  581. _addQuestionDto.QuestionKnowladgeDtos = _mapper.Map<List<UpdateQuestionKnowladgeDto>, List<AddQuestionKnowladgeDto>>(actionRequest.QuestionKnowladgeDtos);
  582. _addQuestionDto.QuestionKnowladgeDtos.ResolveOperationStatus();
  583. questionKnowladges.AddRangeExt(await AddKnowladges(_addQuestionDto, cancellationToken));
  584. questionKnowladges.AddRangeExt(await UpdateKnowladges(actionRequest, all, cancellationToken));
  585. var questionKnowladgeDtos = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
  586. var ids = questionKnowladgeDtos.Select(m => m.Id);
  587. EntityQueryRequest entityQueryRequest = ResovleDelete<ExamQuestionKnowladge>(ids);
  588. await DeleteKnowladges(entityQueryRequest, cancellationToken);
  589. return questionKnowladges;
  590. }
  591. private async Task<List<ExamQuestionAnswer>> ModifyQuestionAnswer(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
  592. {
  593. var all = await _questionAnswerRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
  594. var questionAnswers = new List<ExamQuestionAnswer>();
  595. if (actionRequest.QuestionAnswerDto == null)
  596. {
  597. if (all == null)
  598. return null;
  599. else
  600. {
  601. var ids = all.Select(m => m.Id).ToList();
  602. var entityQueryRequest = new EntityQueryRequest
  603. {
  604. Expression = ExpressionableUtility.CreateExpression<ExamQuestionAnswer>()
  605. .AndIF(ids.IsNotEmpty(), x => ids.Contains(x.Id)).ToExpression()
  606. };
  607. await DeleteQuestionAnswer(entityQueryRequest, cancellationToken);
  608. return null;
  609. }
  610. }
  611. if (actionRequest.QuestionAnswerDto.Id != null)
  612. {
  613. actionRequest.QuestionAnswerDto.OperationStatus = EEOperationStatus.Update;
  614. var update = await UpdateQuestionAnswer(actionRequest, cancellationToken);
  615. if (update != null)
  616. {
  617. questionAnswers.Add(update);
  618. }
  619. }
  620. else
  621. {
  622. var add = await AddQuestionAnswer(_addQuestionDto, cancellationToken);
  623. if (add != null)
  624. {
  625. questionAnswers.AddRange(add);
  626. }
  627. }
  628. if (actionRequest.QuestionAnswerDto != null && actionRequest.QuestionAnswerDto.OperationStatus == EEOperationStatus.Delete)
  629. {
  630. var entityQueryRequest = new EntityQueryRequest
  631. {
  632. Id = actionRequest.QuestionAnswerDto?.Id
  633. };
  634. await DeleteQuestionAnswer(entityQueryRequest, cancellationToken);
  635. }
  636. return questionAnswers;
  637. }
  638. private async Task<List<ExamQuestionOptions>> ModifyQuestionOptions(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
  639. {
  640. if (actionRequest.QuestionOptionsDtos == null) return null;
  641. var questionOptions = new List<ExamQuestionOptions>();
  642. var all = await _questionOptionRepository.Queryable().Where(x=>x.QuestionId == actionRequest.Id).ToListAsync();
  643. actionRequest.QuestionOptionsDtos.ResolveOperationStatus(all);
  644. _addQuestionDto.QuestionOptionsDtos = _mapper.Map<List<UpdateQuestionOptionsDto>, List<AddQuestionOptionsDto>>(actionRequest.QuestionOptionsDtos);
  645. _addQuestionDto.QuestionOptionsDtos.ResolveOperationStatus();
  646. questionOptions.AddRangeExt(await AddQuestionOptions(_addQuestionDto, cancellationToken));
  647. questionOptions.AddRangeExt(await UpdateQuestionOptions(actionRequest, all, cancellationToken));
  648. var questionOptionsDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
  649. var ids = questionOptionsDtos.Select(m => m.Id);
  650. EntityQueryRequest entityQueryRequest = ResovleDelete<ExamQuestionOptions>(ids);
  651. await DeleteQuestionOptions(entityQueryRequest, cancellationToken);
  652. return questionOptions;
  653. }
  654. private async Task<List<ExamQuestionTag>> ModifyQuestionTags(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
  655. {
  656. if (actionRequest.QuestionTagDtos == null) return null;
  657. var questionTags = new List<ExamQuestionTag>();
  658. var all = await _questionTagRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
  659. actionRequest.QuestionTagDtos.ResolveOperationStatus(all);
  660. _addQuestionDto.QuestionTagDtos = _mapper.Map<List<UpdateQuestionTagDto>, List<AddQuestionTagDto>>(actionRequest.QuestionTagDtos);
  661. questionTags.AddRangeExt(await AddQuestionTags(_addQuestionDto, cancellationToken));
  662. questionTags.AddRangeExt(await UpdateQuestionTags(actionRequest, all, cancellationToken));
  663. var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
  664. var ids = questionTagDtos.Select(m => m.Id);
  665. EntityQueryRequest entityQueryRequest = ResovleDelete<ExamQuestionTag>(ids);
  666. await DeleteQuestionTags(entityQueryRequest, cancellationToken);
  667. return questionTags;
  668. }
  669. private EntityQueryRequest ResovleDelete<T>(IEnumerable<string> ids) where T:class,IEntity<string>,new()
  670. {
  671. Expressionable<T> expressionable = ExpressionableUtility.CreateExpression<T>();
  672. expressionable.AndIF(ids.Any(), x => ids.Contains(x.Id));
  673. var entityQueryRequest = new EntityQueryRequest
  674. {
  675. Expression = ids.Any() ? expressionable.ToExpression() : null
  676. };
  677. return entityQueryRequest;
  678. }
  679. private async Task<List<QuestionSourcewareDto>> GetQuestionSourcewares(EntityQueryRequest entityQueryRequest)
  680. {
  681. var questionSourcewareTable = _questionSourcewareRepository.Queryable().Where(x => x.QuestionId == entityQueryRequest.Id);
  682. var sourcewareTable = new ExamRepository<ExamSourceware>(_questionSourcewareRepository.UOW, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
  683. var questionSourcewares = questionSourcewareTable.InnerJoin(sourcewareTable, (q, s) =>
  684. q.SourcewareId == s.Id).Select((q, s) => new QuestionSourcewareDto
  685. {
  686. Id = q.Id,
  687. SourcewareId = q.SourcewareId,
  688. Name = s.Name
  689. });
  690. return await questionSourcewares.ToListAsync();
  691. }
  692. private async Task<List<QuestionOptionsDto>> GetQuestionOptions(EntityQueryRequest entityQueryRequest)
  693. {
  694. var questionOptionTable = await _questionOptionRepository.Queryable().Where(x => x.QuestionId == entityQueryRequest.Id).ToListAsync();
  695. var questionOptions = _mapper.Map<List<QuestionOptionsDto>>(questionOptionTable);
  696. return questionOptions;
  697. }
  698. private async Task<List<QuestionKnowladgeDto>> GetKnowladges(EntityQueryRequest entityQueryRequest)
  699. {
  700. var questionKnowladgeTable = await _questionKnowladgeRepository.Queryable().Where(x => x.QuestionId == entityQueryRequest.Id).ToListAsync();
  701. var questionKnowladges = _mapper.Map<List<QuestionKnowladgeDto>>(questionKnowladgeTable);
  702. return questionKnowladges;
  703. }
  704. private async Task<QuestionAnswerDto> GetQuestionAnswer(EntityQueryRequest entityQueryRequest)
  705. {
  706. var questionAnswer = await _questionAnswerRepository.GetAsync(x=>x.QuestionId == entityQueryRequest.Id);
  707. var questionAnswerDto = _mapper.Map<QuestionAnswerDto>(questionAnswer);
  708. return questionAnswerDto;
  709. }
  710. private async Task<List<QuestionTagDto>> GetQuestionTags(EntityQueryRequest entityQueryRequest)
  711. {
  712. var questionTags = _questionTagRepository.Queryable().Where(x => x.QuestionId == entityQueryRequest.Id);
  713. var examTags = new ExamRepository<ExamTag>(_questionTagRepository.UOW, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
  714. var questionTagDtos = questionTags.InnerJoin(examTags, (q, t) => q.TagId == t.Id).Select((q, t) => new QuestionTagDto
  715. {
  716. Id = q.Id,
  717. TagId = q.TagId,
  718. Tag = t.Name,
  719. QuestionId = q.QuestionId
  720. });
  721. return await questionTagDtos.ToListAsync();
  722. }
  723. private async Task<ExamQuestion> AddQuestion(AddQuestionDto actionRequest, CancellationToken cancellationToken)
  724. {
  725. var id = await base.AddAsync(actionRequest, cancellationToken);
  726. ResolveQuestionId(actionRequest, id);
  727. base.Entity.QuestionTags = await AddQuestionTags(actionRequest, cancellationToken);
  728. base.Entity.QuestionOptionses = await AddQuestionOptions(actionRequest, cancellationToken);
  729. base.Entity.QuestionAnswers = await AddQuestionAnswer(actionRequest, cancellationToken);
  730. base.Entity.QuestionKnowladges = await AddKnowladges(actionRequest, cancellationToken);
  731. base.Entity.QuestionSourcewares = await AddSourcewares(actionRequest, cancellationToken);
  732. return base.Entity;
  733. }
  734. #endregion
  735. #region protected method
  736. //protected override async Task CompleteAdd(Question entity)
  737. //{
  738. // if (entity.QuestionType.CheckSelectType())
  739. // {
  740. // await base.AddNav(entity)
  741. // .Include(x => x.QuestionTags)
  742. // .Include(x => x.QuestionOptionses)
  743. // .Include(x => x.QuestionSourcewares)
  744. // .Include(x => x.QuestionKnowladges).ExecuteCommandAsync();
  745. // }
  746. // else
  747. // {
  748. // await base.AddNav(entity)
  749. // .Include(x => x.QuestionTags)
  750. // .Include(x => x.QuestionAnswerE)
  751. // .Include(x => x.QuestionSourcewares)
  752. // .Include(x => x.QuestionKnowladges).ExecuteCommandAsync();
  753. // }
  754. //}
  755. //protected override async Task CompleteUpdate(Question entity)
  756. //{
  757. // if (entity.QuestionType.CheckSelectType())
  758. // {
  759. // await base.UpdateNav(entity)
  760. // .Include(x => x.QuestionTags,new UpdateNavOptions
  761. // {
  762. // OneToManyInsertOrUpdate = true
  763. // })
  764. // .Include(x => x.QuestionOptionses, new UpdateNavOptions
  765. // {
  766. // OneToManyInsertOrUpdate = true
  767. // })
  768. // .Include(x => x.QuestionSourcewares, new UpdateNavOptions
  769. // {
  770. // OneToManyInsertOrUpdate = true
  771. // })
  772. // .Include(x => x.QuestionKnowladges, new UpdateNavOptions
  773. // {
  774. // OneToManyInsertOrUpdate = true
  775. // }).ExecuteCommandAsync();
  776. // }
  777. // else
  778. // {
  779. // await base.UpdateNav(entity)
  780. // .Include(x => x.QuestionTags, new UpdateNavOptions
  781. // {
  782. // OneToManyInsertOrUpdate = true
  783. // })
  784. // .Include(x => x.QuestionAnswerE)
  785. // .Include(x => x.QuestionSourcewares, new UpdateNavOptions
  786. // {
  787. // OneToManyInsertOrUpdate = true
  788. // })
  789. // .Include(x => x.QuestionKnowladges, new UpdateNavOptions
  790. // {
  791. // OneToManyInsertOrUpdate = true
  792. // }).ExecuteCommandAsync();
  793. // }
  794. //}
  795. #endregion
  796. }
  797. }