QuestionService.cs 46 KB

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