QuestionService.cs 47 KB

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