|
@@ -27,6 +27,8 @@ using XF.Domain.Entities;
|
|
|
using Hotline.Application.Exam.Extensions;
|
|
|
using Hotline.Application.Exam.Core.Extensions;
|
|
|
using Hotline.Application.Exam.Constants.Messages;
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Core.Constants;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
@@ -131,6 +133,7 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
SortIndex = s.SortIndex,
|
|
|
Status = s.Status,
|
|
|
Tag = t.Name,
|
|
|
+ QuestionType = s.QuestionType,
|
|
|
Title = s.Title,
|
|
|
Id = s.Id
|
|
|
});
|
|
@@ -149,38 +152,46 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
public override async Task<string> AddAsync(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
+ base.StartTran();
|
|
|
+
|
|
|
var id = await base.AddAsync(actionRequest, cancellationToken);
|
|
|
|
|
|
ResolveQuestionId(actionRequest,id);
|
|
|
|
|
|
- await AddQuestionTags(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionTags = await AddQuestionTags(actionRequest, cancellationToken);
|
|
|
+
|
|
|
+ base.Entity.QuestionOptionses = await AddQuestionOptions(actionRequest, cancellationToken);
|
|
|
|
|
|
- await AddQuestionOptions(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionAnswerE = await AddQuestionAnswer(actionRequest, cancellationToken);
|
|
|
|
|
|
- await AddQuestionAnswer(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionKnowladges = await AddKnowladges(actionRequest, cancellationToken);
|
|
|
|
|
|
- await AddKnowladges(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionSourcewares = await AddSourcewares(actionRequest, cancellationToken);
|
|
|
|
|
|
- await AddSourcewares(actionRequest, cancellationToken);
|
|
|
+ await base.Complete(base.Entity, OperationConstant.Create);
|
|
|
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
public override async Task UpdateAsync(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
+ base.StartTran();
|
|
|
+
|
|
|
await base.UpdateAsync(actionRequest, cancellationToken);
|
|
|
|
|
|
ResolveQuestionId(actionRequest, actionRequest.Id);
|
|
|
|
|
|
- await ModifyQuestionTags(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionTags = await ModifyQuestionTags(actionRequest, cancellationToken);
|
|
|
|
|
|
- await ModifyQuestionOptions(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionOptionses = await ModifyQuestionOptions(actionRequest, cancellationToken);
|
|
|
|
|
|
- await ModifyQuestionAnswer(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionAnswerE = await ModifyQuestionAnswer(actionRequest, cancellationToken);
|
|
|
|
|
|
- await ModifyKnowladges(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionKnowladges = await ModifyKnowladges(actionRequest, cancellationToken);
|
|
|
|
|
|
- await ModifySourcewares(actionRequest, cancellationToken);
|
|
|
+ base.Entity.QuestionSourcewares = await ModifySourcewares(actionRequest, cancellationToken);
|
|
|
+
|
|
|
+ await base.Complete(base.Entity,OperationConstant.Update);
|
|
|
}
|
|
|
|
|
|
public override async Task DeleteAsync(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
|
|
@@ -226,20 +237,41 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
#region private method
|
|
|
|
|
|
- private void ResolveQuestionId(AddQuestionDto actionRequest,string id)
|
|
|
+ private void ResolveQuestionId(AddQuestionDto actionRequest,string id)
|
|
|
{
|
|
|
- actionRequest.QuestionKnowladgeDtos.ForEach(x => x.QuestionId = id);
|
|
|
+ actionRequest.QuestionKnowladgeDtos?.ForEach(x => x.QuestionId = id);
|
|
|
+
|
|
|
+ actionRequest.QuestionOptionsDtos?.ForEach(x => x.QuestionId = id);
|
|
|
|
|
|
- actionRequest.QuestionOptionsDtos.ForEach(x => x.QuestionId = id);
|
|
|
+ actionRequest.QuestionSourcewareDtos?.ForEach(x => x.QuestionId = id);
|
|
|
|
|
|
- actionRequest.QuestionSourcewareDtos.ForEach(x => x.QuestionId = id);
|
|
|
+ actionRequest.QuestionTagDtos?.ForEach(x => x.QuestionId = id);
|
|
|
|
|
|
- actionRequest.QuestionTagDtos.ForEach(x => x.QuestionId = id);
|
|
|
+ if (actionRequest.QuestionAnswerDto != null)
|
|
|
+ {
|
|
|
+ actionRequest.QuestionAnswerDto.QuestionId = id;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private async Task AddQuestionTags(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private void ResolveQuestionId(UpdateQuestionDto actionRequest, string id)
|
|
|
{
|
|
|
- if (actionRequest.QuestionTagDtos == null) return;
|
|
|
+ actionRequest.QuestionKnowladgeDtos?.ForEach(x => x.QuestionId = id);
|
|
|
+
|
|
|
+ actionRequest.QuestionOptionsDtos?.ForEach(x => x.QuestionId = id);
|
|
|
+
|
|
|
+ actionRequest.QuestionSourcewareDtos?.ForEach(x => x.QuestionId = id);
|
|
|
+
|
|
|
+ actionRequest.QuestionTagDtos?.ForEach(x => x.QuestionId = id);
|
|
|
+
|
|
|
+ if (actionRequest.QuestionAnswerDto != null)
|
|
|
+ {
|
|
|
+ actionRequest.QuestionAnswerDto.QuestionId = id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<List<QuestionTag>> AddQuestionTags(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (actionRequest.QuestionTagDtos == null) return null;
|
|
|
|
|
|
actionRequest.QuestionTagDtos.ResolveOperationStatus();
|
|
|
|
|
@@ -249,17 +281,19 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
questionTags.ToInsert();
|
|
|
|
|
|
- await _questionTagRepository.AddWithValidateAsync(questionTags, cancellationToken);
|
|
|
+ await _questionTagRepository.ValidateAddAsync(questionTags, cancellationToken);
|
|
|
+
|
|
|
+ return questionTags;
|
|
|
}
|
|
|
|
|
|
- private async Task AddQuestionOptions(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionOptions>> AddQuestionOptions(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionOptionsDtos == null) return;
|
|
|
+ if (actionRequest.QuestionOptionsDtos == null) return null;
|
|
|
|
|
|
actionRequest.QuestionOptionsDtos.ResolveOperationStatus();
|
|
|
// 简答和填空没有选项
|
|
|
if (actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Essay || actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Blank)
|
|
|
- return;
|
|
|
+ return null;
|
|
|
|
|
|
var questionOptionseDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == EEOperationStatus.Add).ToList();
|
|
|
|
|
@@ -276,11 +310,13 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
questionOptionses.ToInsert();
|
|
|
|
|
|
- await _questionOptionRepository.AddWithValidateAsync(questionOptionses, cancellationToken);
|
|
|
+ await _questionOptionRepository.ValidateAddAsync(questionOptionses, cancellationToken);
|
|
|
+
|
|
|
+ return questionOptionses;
|
|
|
}
|
|
|
- private async Task AddQuestionAnswer(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<QuestionAnswer> AddQuestionAnswer(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionAnswerDto == null) return;
|
|
|
+ if (actionRequest.QuestionAnswerDto == null) return null;
|
|
|
|
|
|
if (actionRequest.QuestionAnswerDto.Answer != null)
|
|
|
{
|
|
@@ -288,17 +324,18 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
}
|
|
|
|
|
|
// 简答和填空没有选项
|
|
|
- if (actionRequest.QuestionType.CheckSelectType()) return;
|
|
|
+ if (actionRequest.QuestionType.CheckSelectType()) return null;
|
|
|
var questionAnswer = _mapper.Map<QuestionAnswer>(actionRequest.QuestionAnswerDto);
|
|
|
|
|
|
questionAnswer.ToInsert();
|
|
|
|
|
|
- await _questionAnswerRepository.AddWithValidateAsync(questionAnswer, cancellationToken);
|
|
|
+ await _questionAnswerRepository.ValidateAddAsync(questionAnswer, cancellationToken);
|
|
|
|
|
|
+ return questionAnswer;
|
|
|
}
|
|
|
- private async Task AddSourcewares(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionSourceware>> AddSourcewares(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionSourcewareDtos == null) return;
|
|
|
+ if (actionRequest.QuestionSourcewareDtos == null) return null;
|
|
|
|
|
|
actionRequest.QuestionSourcewareDtos.ResolveOperationStatus();
|
|
|
|
|
@@ -308,11 +345,13 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
questionSourcewares.ToInsert();
|
|
|
|
|
|
- await _questionSourcewareRepository.AddWithValidateAsync(questionSourcewares, cancellationToken);
|
|
|
+ await _questionSourcewareRepository.ValidateAddAsync(questionSourcewares, cancellationToken);
|
|
|
+
|
|
|
+ return questionSourcewares;
|
|
|
}
|
|
|
- private async Task AddKnowladges(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionKnowladge>> AddKnowladges(AddQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionKnowladgeDtos == null) return;
|
|
|
+ if (actionRequest.QuestionKnowladgeDtos == null) return null;
|
|
|
|
|
|
actionRequest.QuestionKnowladgeDtos.ResolveOperationStatus();
|
|
|
|
|
@@ -322,11 +361,13 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
questionKnowladges.ToInsert();
|
|
|
|
|
|
- await _questionKnowladgeRepository.AddWithValidateAsync(questionKnowladges, cancellationToken);
|
|
|
+ await _questionKnowladgeRepository.ValidateAddAsync(questionKnowladges, cancellationToken);
|
|
|
+
|
|
|
+ return questionKnowladges;
|
|
|
}
|
|
|
- private async Task UpdateSourcewares(UpdateQuestionDto actionRequest, List<QuestionSourceware> all, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionSourceware>> UpdateSourcewares(UpdateQuestionDto actionRequest, List<QuestionSourceware> all, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionSourcewareDtos == null) return;
|
|
|
+ if (actionRequest.QuestionSourcewareDtos == null) return null;
|
|
|
|
|
|
actionRequest.QuestionSourcewareDtos.ResolveOperationStatus();
|
|
|
|
|
@@ -336,18 +377,32 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
var questionSourcewares = all.Where(x => ids.Contains(x.Id)).ToList();
|
|
|
|
|
|
- questionSourcewares = _mapper.Map<List<UpdateQuestionSourcewareDto>,List<QuestionSourceware>>(questionSourcewareDtos,questionSourcewares);
|
|
|
+ var entitys = new List<QuestionSourceware>();
|
|
|
+ foreach (var questionSourcewareDto in questionSourcewareDtos)
|
|
|
+ {
|
|
|
+ var entity = questionSourcewares.FirstOrDefault(x => x.Id == questionSourcewareDto.Id);
|
|
|
+ if (entity != null)
|
|
|
+ {
|
|
|
+ entity.QuestionId = actionRequest.Id;
|
|
|
+ entitys.Add(_mapper.Map<UpdateQuestionSourcewareDto, QuestionSourceware>(questionSourcewareDto, entity));
|
|
|
+ }
|
|
|
|
|
|
- questionSourcewares.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+ }
|
|
|
+
|
|
|
+ //questionSourcewares = _mapper.Map<List<UpdateQuestionSourcewareDto>,List<QuestionSourceware>>(questionSourcewareDtos,questionSourcewares);
|
|
|
+
|
|
|
+ //questionSourcewares.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
|
|
|
questionSourcewares.ToUpdate();
|
|
|
|
|
|
- await _questionSourcewareRepository.UpdateWithValidateAsync(questionSourcewares, cancellationToken);
|
|
|
+ await _questionSourcewareRepository.ValidateUpdateAsync(questionSourcewares, cancellationToken);
|
|
|
+
|
|
|
+ return questionSourcewares;
|
|
|
}
|
|
|
|
|
|
- private async Task UpdateKnowladges(UpdateQuestionDto actionRequest, List<QuestionKnowladge> all, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionKnowladge>> UpdateKnowladges(UpdateQuestionDto actionRequest, List<QuestionKnowladge> all, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionKnowladgeDtos == null) return;
|
|
|
+ if (actionRequest.QuestionKnowladgeDtos == null) return null;
|
|
|
|
|
|
actionRequest.QuestionKnowladgeDtos.ResolveOperationStatus();
|
|
|
|
|
@@ -357,20 +412,35 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
var questionKnowladges = all.Where(x => ids.Contains(x.Id)).ToList();
|
|
|
|
|
|
- questionKnowladges = _mapper.Map<List<UpdateQuestionKnowladgeDto>, List<QuestionKnowladge>>(questionKnowladgeDtos,questionKnowladges);
|
|
|
+ var entitys = new List<QuestionKnowladge>();
|
|
|
+ foreach (var questionKnowladgeDto in questionKnowladgeDtos)
|
|
|
+ {
|
|
|
+ var entity = questionKnowladges.FirstOrDefault(x => x.Id == questionKnowladgeDto.Id);
|
|
|
+ if (entity != null)
|
|
|
+ {
|
|
|
+ entity.QuestionId = actionRequest.Id;
|
|
|
+ entitys.Add(_mapper.Map<UpdateQuestionKnowladgeDto, QuestionKnowladge>(questionKnowladgeDto, entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- questionKnowladges.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+ //questionKnowladges = _mapper.Map<List<UpdateQuestionKnowladgeDto>, List<QuestionKnowladge>>(questionKnowladgeDtos,questionKnowladges);
|
|
|
+
|
|
|
+ //questionKnowladges.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
|
|
|
questionKnowladges.ToUpdate();
|
|
|
|
|
|
- await _questionKnowladgeRepository.UpdateWithValidateAsync(questionKnowladges, cancellationToken);
|
|
|
+ await _questionKnowladgeRepository.ValidateUpdateAsync(questionKnowladges, cancellationToken);
|
|
|
+
|
|
|
+ return questionKnowladges;
|
|
|
}
|
|
|
- private async Task UpdateQuestionAnswer(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<QuestionAnswer> UpdateQuestionAnswer(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionAnswerDto == null) return;
|
|
|
+ if (actionRequest.QuestionAnswerDto == null) return null;
|
|
|
|
|
|
// 简单和填空没有选项
|
|
|
- if (actionRequest.QuestionType.CheckSelectType()) return;
|
|
|
+ if (actionRequest.QuestionType.CheckSelectType()) return null;
|
|
|
|
|
|
var questionAnswer = _mapper.Map<QuestionAnswer>(actionRequest.QuestionAnswerDto);
|
|
|
|
|
@@ -378,15 +448,17 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
questionAnswer.ToUpdate();
|
|
|
|
|
|
- await _questionAnswerRepository.UpdateWithValidateAsync(questionAnswer, cancellationToken);
|
|
|
+ await _questionAnswerRepository.ValidateUpdateAsync(questionAnswer, cancellationToken);
|
|
|
+
|
|
|
+ return questionAnswer;
|
|
|
}
|
|
|
- private async Task UpdateQuestionOptions(UpdateQuestionDto actionRequest,List<QuestionOptions> all, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionOptions>> UpdateQuestionOptions(UpdateQuestionDto actionRequest,List<QuestionOptions> all, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionOptionsDtos == null) return;
|
|
|
+ if (actionRequest.QuestionOptionsDtos == null) return null;
|
|
|
|
|
|
// 简单和填空没有选项
|
|
|
if (actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Essay || actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Blank)
|
|
|
- return;
|
|
|
+ return null;
|
|
|
|
|
|
var questionOptionsDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == EEOperationStatus.Update).ToList();
|
|
|
|
|
@@ -398,21 +470,27 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
foreach(var questionOptionsDto in questionOptionsDtos)
|
|
|
{
|
|
|
var entity = questionOptionses.FirstOrDefault(x => x.Id == questionOptionsDto.Id);
|
|
|
- entitys.Add(_mapper.Map<UpdateQuestionOptionsDto, QuestionOptions>(questionOptionsDto, entity));
|
|
|
+ if (entity != null)
|
|
|
+ {
|
|
|
+ entity.QuestionId = actionRequest.Id;
|
|
|
+ entitys.Add(_mapper.Map<UpdateQuestionOptionsDto, QuestionOptions>(questionOptionsDto, entity));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//questionOptionses = _mapper.Map<List<QuestionOptionsDto>, List<QuestionOptions>>(questionOptionsDtos,questionOptionses);
|
|
|
|
|
|
- entitys.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+ //entitys.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
|
|
|
entitys.ToUpdate();
|
|
|
|
|
|
- await _questionOptionRepository.UpdateWithValidateAsync(entitys, cancellationToken);
|
|
|
+ await _questionOptionRepository.ValidateUpdateAsync(entitys, cancellationToken);
|
|
|
+
|
|
|
+ return entitys;
|
|
|
}
|
|
|
|
|
|
- private async Task UpdateQuestionTags(UpdateQuestionDto actionRequest,List<QuestionTag> all, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionTag>> UpdateQuestionTags(UpdateQuestionDto actionRequest,List<QuestionTag> all, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionTagDtos == null) return;
|
|
|
+ if (actionRequest.QuestionTagDtos == null) return null;
|
|
|
|
|
|
var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == EEOperationStatus.Update).ToList();
|
|
|
|
|
@@ -420,11 +498,24 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
var questionTags = all.Where(x => ids.Contains(x.Id)).ToList();
|
|
|
|
|
|
- questionTags = _mapper.Map<List<UpdateQuestionTagDto>, List<QuestionTag>>(questionTagDtos,questionTags);
|
|
|
+ var entitys = new List<QuestionTag>();
|
|
|
+ foreach (var questionOptionsDto in questionTagDtos)
|
|
|
+ {
|
|
|
+ var entity = questionTags.FirstOrDefault(x => x.Id == questionOptionsDto.Id);
|
|
|
+ if (entity != null)
|
|
|
+ {
|
|
|
+ entity.QuestionId = actionRequest.Id;
|
|
|
+ entitys.Add(_mapper.Map<UpdateQuestionTagDto, QuestionTag>(questionOptionsDto, entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //questionTags = _mapper.Map<List<UpdateQuestionTagDto>, List<QuestionTag>>(questionTagDtos,questionTags);
|
|
|
|
|
|
questionTags.ToUpdate();
|
|
|
|
|
|
- await _questionTagRepository.UpdateWithValidateAsync(questionTags, cancellationToken);
|
|
|
+ await _questionTagRepository.ValidateUpdateAsync(questionTags, cancellationToken);
|
|
|
+
|
|
|
+ return questionTags;
|
|
|
}
|
|
|
private async Task DeleteSourcewares(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
@@ -446,54 +537,62 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
await _questionTagRepository.DeleteWithValidateAsync(entityQueryRequest, cancellationToken);
|
|
|
}
|
|
|
- private async Task ModifySourcewares(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionSourceware>> ModifySourcewares(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var all = await _questionSourcewareRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
|
|
|
|
|
|
- if (actionRequest.QuestionSourcewareDtos == null) return;
|
|
|
+ if (actionRequest.QuestionSourcewareDtos == null) return null;
|
|
|
+
|
|
|
+ var questionSourcewares = new List<QuestionSourceware>();
|
|
|
|
|
|
actionRequest.QuestionSourcewareDtos.ResolveOperationStatus(all);
|
|
|
|
|
|
- await AddSourcewares(actionRequest, cancellationToken);
|
|
|
+ questionSourcewares.AddRangeExt(await AddSourcewares(actionRequest, cancellationToken));
|
|
|
|
|
|
- await UpdateSourcewares(actionRequest, all, cancellationToken);
|
|
|
+ questionSourcewares.AddRangeExt(await UpdateSourcewares(actionRequest, all, cancellationToken));
|
|
|
|
|
|
var questionSourcewareDtos = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
|
|
|
var ids = questionSourcewareDtos.Select(m => m.Id);
|
|
|
EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionSourceware>(ids);
|
|
|
|
|
|
await DeleteSourcewares(entityQueryRequest, cancellationToken);
|
|
|
+
|
|
|
+ return questionSourcewares;
|
|
|
}
|
|
|
|
|
|
- private async Task ModifyKnowladges(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionKnowladge>> ModifyKnowladges(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var all = await _questionKnowladgeRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
|
|
|
|
|
|
- if (actionRequest.QuestionKnowladgeDtos == null) return;
|
|
|
+ if (actionRequest.QuestionKnowladgeDtos == null) return null;
|
|
|
+
|
|
|
+ var questionKnowladges = new List<QuestionKnowladge>();
|
|
|
|
|
|
actionRequest.QuestionKnowladgeDtos.ResolveOperationStatus(all);
|
|
|
|
|
|
- await AddKnowladges(actionRequest, cancellationToken);
|
|
|
+ questionKnowladges.AddRangeExt(await AddKnowladges(actionRequest, cancellationToken));
|
|
|
|
|
|
- await UpdateKnowladges(actionRequest, all, cancellationToken);
|
|
|
+ questionKnowladges.AddRangeExt(await UpdateKnowladges(actionRequest, all, cancellationToken));
|
|
|
|
|
|
var questionKnowladgeDtos = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
|
|
|
var ids = questionKnowladgeDtos.Select(m => m.Id);
|
|
|
EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionKnowladge>(ids);
|
|
|
|
|
|
await DeleteKnowladges(entityQueryRequest, cancellationToken);
|
|
|
+
|
|
|
+ return questionKnowladges;
|
|
|
}
|
|
|
|
|
|
- private async Task ModifyQuestionAnswer(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<QuestionAnswer> ModifyQuestionAnswer(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var all = await _questionAnswerRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
|
|
|
|
|
|
-
|
|
|
+ var questionAnswer = new QuestionAnswer();
|
|
|
|
|
|
if (actionRequest.QuestionAnswerDto == null)
|
|
|
{
|
|
|
if (all == null)
|
|
|
- return;
|
|
|
+ return null;
|
|
|
else
|
|
|
{
|
|
|
var ids = all.Select(m => m.Id).ToList();
|
|
@@ -505,7 +604,7 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
await DeleteQuestionAnswer(entityQueryRequest, cancellationToken);
|
|
|
|
|
|
- return;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -515,9 +614,19 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
actionRequest.QuestionAnswerDto.OperationStatus = EEOperationStatus.Update;
|
|
|
}
|
|
|
|
|
|
- await AddQuestionAnswer(actionRequest, cancellationToken);
|
|
|
+ var add = await AddQuestionAnswer(actionRequest, cancellationToken);
|
|
|
|
|
|
- await UpdateQuestionAnswer(actionRequest, cancellationToken);
|
|
|
+ if (add!=null)
|
|
|
+ {
|
|
|
+ questionAnswer = add;
|
|
|
+ }
|
|
|
+
|
|
|
+ var update= await UpdateQuestionAnswer(actionRequest, cancellationToken);
|
|
|
+
|
|
|
+ if(update != null)
|
|
|
+ {
|
|
|
+ questionAnswer = update;
|
|
|
+ }
|
|
|
|
|
|
if (actionRequest.QuestionAnswerDto != null && actionRequest.QuestionAnswerDto.OperationStatus == EEOperationStatus.Delete)
|
|
|
{
|
|
@@ -529,44 +638,54 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
await DeleteQuestionAnswer(entityQueryRequest, cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ return questionAnswer;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private async Task ModifyQuestionOptions(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionOptions>> ModifyQuestionOptions(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionOptionsDtos == null) return;
|
|
|
+ if (actionRequest.QuestionOptionsDtos == null) return null;
|
|
|
+
|
|
|
+ var questionOptions = new List<QuestionOptions>();
|
|
|
|
|
|
var all = await _questionOptionRepository.Queryable().Where(x=>x.QuestionId == actionRequest.Id).ToListAsync();
|
|
|
|
|
|
actionRequest.QuestionOptionsDtos.ResolveOperationStatus(all);
|
|
|
|
|
|
- await AddQuestionOptions(actionRequest, cancellationToken);
|
|
|
+ questionOptions.AddRangeExt(await AddQuestionOptions(actionRequest, cancellationToken));
|
|
|
|
|
|
- await UpdateQuestionOptions(actionRequest, all, cancellationToken);
|
|
|
+ questionOptions.AddRangeExt(await UpdateQuestionOptions(actionRequest, all, cancellationToken));
|
|
|
|
|
|
var questionOptionsDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
|
|
|
var ids = questionOptionsDtos.Select(m => m.Id);
|
|
|
EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionOptions>(ids);
|
|
|
|
|
|
await DeleteQuestionOptions(entityQueryRequest, cancellationToken);
|
|
|
+
|
|
|
+ return questionOptions;
|
|
|
}
|
|
|
|
|
|
- private async Task ModifyQuestionTags(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
+ private async Task<List<QuestionTag>> ModifyQuestionTags(UpdateQuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- if (actionRequest.QuestionTagDtos == null) return;
|
|
|
+ if (actionRequest.QuestionTagDtos == null) return null;
|
|
|
+
|
|
|
+ var questionTags = new List<QuestionTag>();
|
|
|
|
|
|
var all = await _questionTagRepository.Queryable().Where(x => x.QuestionId == actionRequest.Id).ToListAsync();
|
|
|
|
|
|
actionRequest.QuestionTagDtos.ResolveOperationStatus(all);
|
|
|
|
|
|
- await AddQuestionTags(actionRequest, cancellationToken);
|
|
|
+ questionTags.AddRangeExt(await AddQuestionTags(actionRequest, cancellationToken));
|
|
|
|
|
|
- await UpdateQuestionTags(actionRequest, all, cancellationToken);
|
|
|
+ questionTags.AddRangeExt(await UpdateQuestionTags(actionRequest, all, cancellationToken));
|
|
|
|
|
|
var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == EEOperationStatus.Delete);
|
|
|
var ids = questionTagDtos.Select(m => m.Id);
|
|
|
EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionTag>(ids);
|
|
|
|
|
|
await DeleteQuestionTags(entityQueryRequest, cancellationToken);
|
|
|
+
|
|
|
+ return questionTags;
|
|
|
}
|
|
|
|
|
|
private EntityQueryRequest ResovleDelete<T>(IEnumerable<string> ids) where T:class,IEntity<string>,new()
|
|
@@ -642,5 +761,70 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
return await questionTagDtos.ToListAsync();
|
|
|
}
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region protected method
|
|
|
+
|
|
|
+ //protected override async Task CompleteAdd(Question entity)
|
|
|
+ //{
|
|
|
+ // if (entity.QuestionType.CheckSelectType())
|
|
|
+ // {
|
|
|
+ // await base.AddNav(entity)
|
|
|
+ // .Include(x => x.QuestionTags)
|
|
|
+ // .Include(x => x.QuestionOptionses)
|
|
|
+ // .Include(x => x.QuestionSourcewares)
|
|
|
+ // .Include(x => x.QuestionKnowladges).ExecuteCommandAsync();
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // await base.AddNav(entity)
|
|
|
+ // .Include(x => x.QuestionTags)
|
|
|
+ // .Include(x => x.QuestionAnswerE)
|
|
|
+ // .Include(x => x.QuestionSourcewares)
|
|
|
+ // .Include(x => x.QuestionKnowladges).ExecuteCommandAsync();
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ protected override async Task CompleteUpdate(Question entity)
|
|
|
+ {
|
|
|
+ if (entity.QuestionType.CheckSelectType())
|
|
|
+ {
|
|
|
+ await base.UpdateNav(entity)
|
|
|
+ .Include(x => x.QuestionTags,new UpdateNavOptions
|
|
|
+ {
|
|
|
+ OneToManyInsertOrUpdate = true
|
|
|
+ })
|
|
|
+ .Include(x => x.QuestionOptionses, new UpdateNavOptions
|
|
|
+ {
|
|
|
+ OneToManyInsertOrUpdate = true
|
|
|
+ })
|
|
|
+ .Include(x => x.QuestionSourcewares, new UpdateNavOptions
|
|
|
+ {
|
|
|
+ OneToManyInsertOrUpdate = true
|
|
|
+ })
|
|
|
+ .Include(x => x.QuestionKnowladges, new UpdateNavOptions
|
|
|
+ {
|
|
|
+ OneToManyInsertOrUpdate = true
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await base.UpdateNav(entity)
|
|
|
+ .Include(x => x.QuestionTags, new UpdateNavOptions
|
|
|
+ {
|
|
|
+ OneToManyInsertOrUpdate = true
|
|
|
+ })
|
|
|
+ .Include(x => x.QuestionAnswerE)
|
|
|
+ .Include(x => x.QuestionSourcewares, new UpdateNavOptions
|
|
|
+ {
|
|
|
+ OneToManyInsertOrUpdate = true
|
|
|
+ })
|
|
|
+ .Include(x => x.QuestionKnowladges, new UpdateNavOptions
|
|
|
+ {
|
|
|
+ OneToManyInsertOrUpdate = true
|
|
|
+ }).ExecuteCommandAsync();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|