|
@@ -19,6 +19,16 @@ using Hotline.Share.Requests.Question;
|
|
|
using Mapster;
|
|
|
using SqlSugar;
|
|
|
using XF.Domain.Dependency;
|
|
|
+using Exam.Infrastructure.Data.Extensions;
|
|
|
+using Exam.Infrastructure.Data.Interface;
|
|
|
+using Hotline.Import;
|
|
|
+using Exam.Infrastructure.Web.Utilities;
|
|
|
+using XF.Domain.Repository;
|
|
|
+using MapsterMapper;
|
|
|
+using XF.Domain.Entities;
|
|
|
+using Exam.Infrastructure.Extensions;
|
|
|
+using Exam.Infrastructure.Web.Extensions;
|
|
|
+using JiebaNet.Segmenter.Common;
|
|
|
|
|
|
namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
@@ -33,14 +43,17 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
private readonly IQuestionKnowladgeRepository _questionKnowladgeRepository;
|
|
|
private readonly IDataPermissionFilterBuilder _dataPermissionFilterBuilder;
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+
|
|
|
public QuestionService(IQuestionRepository repository,
|
|
|
IQuestionTagRepository questionTagRepository,
|
|
|
IQuestionOptionsRepository questionOptionsRepository,
|
|
|
IQuestionAnswerRepository questionAnswerRepository,
|
|
|
IQuestionSourcewareRepository questionSourcewareRepository,
|
|
|
IQuestionKnowladgeRepository questionKnowladgeRepository,
|
|
|
- IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider
|
|
|
- ) : base(repository)
|
|
|
+ IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider,
|
|
|
+ IMapper mapper
|
|
|
+ ) : base(repository,mapper)
|
|
|
{
|
|
|
_repository = repository;
|
|
|
_questionTagRepository = questionTagRepository;
|
|
@@ -50,6 +63,7 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
_questionKnowladgeRepository = questionKnowladgeRepository;
|
|
|
_dataPermissionFilterBuilder = dataPermissionFilterBuilder;
|
|
|
_serviceProvider = serviceProvider;
|
|
|
+ _mapper = mapper;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -58,7 +72,7 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
var entity = await _repository.GetAsync(entityQueryRequest.Id);
|
|
|
|
|
|
- var questionDto = entity.Adapt<QuestionDto>();
|
|
|
+ var questionDto = _mapper.Map<QuestionDto>(entity);
|
|
|
|
|
|
questionDto.QuestionTagDtos = await GetQuestionTags(entityQueryRequest);
|
|
|
|
|
@@ -114,20 +128,22 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
var examTagTable = new BaseRepository<ExamTag>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider).Queryable().Where(examTagExpression);
|
|
|
|
|
|
|
|
|
- var queryable = questionTable.InnerJoin(questionTagTable, (s, d) => s.Id == d.QuestionId).InnerJoin(examTagTable, (f, s, t) => s.TagId == t.Id).Select((s, d, f) => new QuestionViewResponse
|
|
|
+ var queryable = questionTable.InnerJoin(questionTagTable, (s, d) => s.Id == d.QuestionId).InnerJoin(examTagTable, (s,d, t) => d.TagId == t.Id).Select((s, d, t) => new QuestionViewResponse
|
|
|
{
|
|
|
DifficultyLevel = s.DifficultyLevel,
|
|
|
FormalEnable = s.FormalEnable,
|
|
|
SimulateEnable = s.SimulateEnable,
|
|
|
SortIndex = s.SortIndex,
|
|
|
Status = s.Status,
|
|
|
- Tag = f.Name
|
|
|
+ Tag = t.Name,
|
|
|
+ Title = s.Title,
|
|
|
+ Id = s.Id
|
|
|
});
|
|
|
|
|
|
var list = await queryable.ToPageListAsync(queryRequest.PageIndex, queryRequest.PageSize);
|
|
|
var total = await queryable.CountAsync();
|
|
|
|
|
|
- var result = new PageViewResponse<QuestionViewResponse>
|
|
|
+ var result = new QuestionPageViewResponse
|
|
|
{
|
|
|
Items = list,
|
|
|
Pagination = new Pagination(queryRequest.PageIndex, queryRequest.PageSize, total)
|
|
@@ -170,15 +186,40 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
await base.DeleteAsync(entityQueryRequest, cancellationToken);
|
|
|
|
|
|
- await DeleteQuestionTags(entityQueryRequest, cancellationToken);
|
|
|
+ var tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<QuestionTag>()
|
|
|
+ .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
|
|
|
+ .AndIF(entityQueryRequest.Ids.IsNotNull(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
|
|
|
+ .ToEntityQueryRequest<QuestionTag>();
|
|
|
|
|
|
- await DeleteQuestionOptions(entityQueryRequest, cancellationToken);
|
|
|
+ await DeleteQuestionTags(tmpEntityQueryRequest, cancellationToken);
|
|
|
|
|
|
- await DeleteQuestionAnswer(entityQueryRequest, cancellationToken);
|
|
|
+ tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<QuestionOptions>()
|
|
|
+ .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
|
|
|
+ .AndIF(entityQueryRequest.Ids.IsNotNull(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
|
|
|
+ .ToEntityQueryRequest<QuestionOptions>();
|
|
|
|
|
|
- await DeleteKnowladges(entityQueryRequest, cancellationToken);
|
|
|
+ await DeleteQuestionOptions(tmpEntityQueryRequest, cancellationToken);
|
|
|
|
|
|
- await DeleteSourcewares(entityQueryRequest, cancellationToken);
|
|
|
+ tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<QuestionAnswer>()
|
|
|
+ .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
|
|
|
+ .AndIF(entityQueryRequest.Ids.IsNotNull(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
|
|
|
+ .ToEntityQueryRequest<QuestionAnswer>();
|
|
|
+
|
|
|
+ await DeleteQuestionAnswer(tmpEntityQueryRequest, cancellationToken);
|
|
|
+
|
|
|
+ tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<QuestionKnowladge>()
|
|
|
+ .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
|
|
|
+ .AndIF(entityQueryRequest.Ids.IsNotNull(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
|
|
|
+ .ToEntityQueryRequest<QuestionKnowladge>();
|
|
|
+
|
|
|
+ await DeleteKnowladges(tmpEntityQueryRequest, cancellationToken);
|
|
|
+
|
|
|
+ tmpEntityQueryRequest = ExpressionableUtility.CreateExpression<QuestionSourceware>()
|
|
|
+ .AndIF(entityQueryRequest.Id.IsNotNullOrEmpty(), x => x.QuestionId == entityQueryRequest.Id)
|
|
|
+ .AndIF(entityQueryRequest.Ids.IsNotNull(), x => entityQueryRequest.Ids.Contains(x.QuestionId))
|
|
|
+ .ToEntityQueryRequest<QuestionSourceware>();
|
|
|
+
|
|
|
+ await DeleteSourcewares(tmpEntityQueryRequest, cancellationToken);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -187,12 +228,19 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
if (actionRequest.QuestionTagDtos == null) return;
|
|
|
|
|
|
- var questionTags = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == OperationStatus.Add).Adapt<QuestionTag>();
|
|
|
+ var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == OperationStatus.Add).ToList();
|
|
|
+
|
|
|
+ var questionTags = _mapper.Map<List<QuestionTag>>(questionTagDtos);
|
|
|
|
|
|
- questionTags.ToInsert(actionRequest);
|
|
|
+ questionTagDtos.InitRequest<QuestionTagDto, QuestionDto>(actionRequest);
|
|
|
+
|
|
|
+ questionTags.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionTags.ToInsert(questionTagDtos);
|
|
|
|
|
|
await _questionTagRepository.AddWithValidateAsync(questionTags, cancellationToken);
|
|
|
}
|
|
|
+
|
|
|
private async Task AddQuestionOptions(QuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
if (actionRequest.QuestionOptionsDtos == null) return;
|
|
@@ -201,9 +249,15 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
if (actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Essay || actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Blank)
|
|
|
return;
|
|
|
|
|
|
- var questionOptionses = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == OperationStatus.Add).Adapt<QuestionOptions>();
|
|
|
+ var questionOptionseDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == OperationStatus.Add).ToList();
|
|
|
+
|
|
|
+ var questionOptionses = _mapper.Map<List<QuestionOptions>>(questionOptionseDtos);
|
|
|
|
|
|
- questionOptionses.ToInsert(actionRequest);
|
|
|
+ questionOptionseDtos.InitRequest<QuestionOptionsDto,QuestionDto>(actionRequest);
|
|
|
+
|
|
|
+ questionOptionses.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionOptionses.ToInsert(questionOptionseDtos);
|
|
|
|
|
|
await _questionOptionRepository.AddWithValidateAsync(questionOptionses, cancellationToken);
|
|
|
}
|
|
@@ -215,8 +269,9 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
if (actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Multi
|
|
|
|| actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Single
|
|
|
|| actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Judge) return;
|
|
|
-
|
|
|
- var questionAnswer = actionRequest.QuestionAnswerDto.Adapt<QuestionAnswer>();
|
|
|
+ actionRequest.QuestionAnswerDto.InitRequest<QuestionAnswerDto, QuestionDto>(actionRequest);
|
|
|
+ var questionAnswer = _mapper.Map<QuestionAnswer>(actionRequest.QuestionAnswerDto);
|
|
|
+ questionAnswer.QuestionId = actionRequest.Id;
|
|
|
|
|
|
questionAnswer.ToInsert(actionRequest);
|
|
|
|
|
@@ -227,9 +282,15 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
if (actionRequest.QuestionSourcewareDtos == null) return;
|
|
|
|
|
|
- var questionSourcewares = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == OperationStatus.Add).Adapt<QuestionSourceware>();
|
|
|
+ var questionSourcewareDtos = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == OperationStatus.Add).ToList();
|
|
|
+
|
|
|
+ var questionSourcewares = _mapper.Map<List<QuestionSourceware>>(questionSourcewareDtos);
|
|
|
+
|
|
|
+ questionSourcewareDtos.InitRequest<QuestionSourcewareDto, QuestionDto>(actionRequest);
|
|
|
|
|
|
- questionSourcewares.ToInsert(actionRequest);
|
|
|
+ questionSourcewares.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionSourcewares.ToInsert(questionSourcewareDtos);
|
|
|
|
|
|
await _questionSourcewareRepository.AddWithValidateAsync(questionSourcewares, cancellationToken);
|
|
|
}
|
|
@@ -237,9 +298,15 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
if (actionRequest.QuestionKnowladgeDtos == null) return;
|
|
|
|
|
|
- var questionKnowladges = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == OperationStatus.Add).Adapt<QuestionKnowladge>();
|
|
|
+ var questionKnoladgeDtos = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == OperationStatus.Add).ToList();
|
|
|
|
|
|
- questionKnowladges.ToInsert(actionRequest);
|
|
|
+ var questionKnowladges = _mapper.Map<List<QuestionKnowladge>>(questionKnoladgeDtos);
|
|
|
+
|
|
|
+ questionKnoladgeDtos.InitRequest<QuestionKnowladgeDto, QuestionDto>(actionRequest);
|
|
|
+
|
|
|
+ questionKnowladges.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionKnowladges.ToInsert(questionKnoladgeDtos);
|
|
|
|
|
|
await _questionKnowladgeRepository.AddWithValidateAsync(questionKnowladges, cancellationToken);
|
|
|
}
|
|
@@ -247,9 +314,18 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
if (actionRequest.QuestionSourcewareDtos == null) return;
|
|
|
|
|
|
- var questionSourcewares = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == OperationStatus.Add).Adapt<QuestionSourceware>();
|
|
|
+ var questionSourcewareDtos = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == OperationStatus.Update).ToList();
|
|
|
+
|
|
|
+ var ids = questionSourcewareDtos.Select(x => x.Id);
|
|
|
|
|
|
- questionSourcewares.ToUpdate(actionRequest);
|
|
|
+ var questionSourcewares = await _questionSourcewareRepository.Queryable().Where(x => ids.Contains(x.Id)).ToListAsync();
|
|
|
+
|
|
|
+ questionSourcewares = _mapper.Map<List<QuestionSourcewareDto>,List<QuestionSourceware>>(questionSourcewareDtos,questionSourcewares);
|
|
|
+
|
|
|
+
|
|
|
+ questionSourcewares.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionSourcewares.ToUpdate(questionSourcewareDtos);
|
|
|
|
|
|
await _questionSourcewareRepository.UpdateWithValidateAsync(questionSourcewares, cancellationToken);
|
|
|
}
|
|
@@ -257,9 +333,17 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
if (actionRequest.QuestionKnowladgeDtos == null) return;
|
|
|
|
|
|
- var questionKnowladges = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == OperationStatus.Add).Adapt<QuestionKnowladge>();
|
|
|
+ var questionKnowladgeDtos = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == OperationStatus.Add).ToList();
|
|
|
+
|
|
|
+ var ids = questionKnowladgeDtos.Select(x => x.Id);
|
|
|
|
|
|
- questionKnowladges.ToUpdate(actionRequest);
|
|
|
+ var questionKnowladges = await _questionKnowladgeRepository.Queryable().Where(x => ids.Contains(x.Id)).ToListAsync();
|
|
|
+
|
|
|
+ questionKnowladges = _mapper.Map<List<QuestionKnowladgeDto>, List<QuestionKnowladge>>(questionKnowladgeDtos,questionKnowladges);
|
|
|
+
|
|
|
+ questionKnowladges.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionKnowladges.ToUpdate(questionKnowladgeDtos);
|
|
|
|
|
|
await _questionKnowladgeRepository.UpdateWithValidateAsync(questionKnowladges, cancellationToken);
|
|
|
}
|
|
@@ -272,7 +356,11 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|| actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Single
|
|
|
|| actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Judge) return;
|
|
|
|
|
|
- var questionAnswer = actionRequest.QuestionAnswerDto.Adapt<QuestionAnswer>();
|
|
|
+ actionRequest.QuestionAnswerDto.InitRequest<QuestionAnswerDto, QuestionDto>(actionRequest);
|
|
|
+
|
|
|
+ var questionAnswer = _mapper.Map<QuestionAnswer>(actionRequest.QuestionAnswerDto);
|
|
|
+
|
|
|
+ questionAnswer.QuestionId = actionRequest.Id;
|
|
|
|
|
|
questionAnswer.ToUpdate(actionRequest);
|
|
|
|
|
@@ -286,19 +374,46 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
if (actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Essay || actionRequest.QuestionType == Share.Enums.Exams.EQuestionType.Blank)
|
|
|
return;
|
|
|
|
|
|
- var questionOptionses = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == OperationStatus.Add).Adapt<QuestionOptions>();
|
|
|
+ var questionOptionsDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == OperationStatus.Update).ToList();
|
|
|
+
|
|
|
+ var ids = questionOptionsDtos.Select(x => x.Id);
|
|
|
+
|
|
|
+ var questionOptionses = await _questionOptionRepository.Queryable().Where(x => ids.Contains(x.Id)).ToListAsync();
|
|
|
+
|
|
|
+ var entitys = new List<QuestionOptions>();
|
|
|
+ foreach(var questionOptionsDto in questionOptionsDtos)
|
|
|
+ {
|
|
|
+ var entity = questionOptionses.FirstOrDefault(x => x.Id == questionOptionsDto.Id);
|
|
|
+ entitys.Add(_mapper.Map<QuestionOptionsDto, QuestionOptions>(questionOptionsDto, entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ //questionOptionses = _mapper.Map<List<QuestionOptionsDto>, List<QuestionOptions>>(questionOptionsDtos,questionOptionses);
|
|
|
+
|
|
|
+ entitys.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionOptionsDtos.InitRequest(actionRequest);
|
|
|
|
|
|
- questionOptionses.ToUpdate(actionRequest);
|
|
|
+ entitys.ToUpdate(questionOptionsDtos);
|
|
|
|
|
|
- await _questionOptionRepository.UpdateWithValidateAsync(questionOptionses, cancellationToken);
|
|
|
+ await _questionOptionRepository.UpdateWithValidateAsync(entitys, cancellationToken);
|
|
|
}
|
|
|
+
|
|
|
private async Task UpdateQuestionTags(QuestionDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
if (actionRequest.QuestionTagDtos == null) return;
|
|
|
|
|
|
- var questionTags = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == OperationStatus.Update).Adapt<QuestionTag>();
|
|
|
+ var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == OperationStatus.Update).ToList();
|
|
|
+
|
|
|
+ var ids = questionTagDtos.Select(x => x.Id);
|
|
|
+
|
|
|
+ var questionTags = await _questionTagRepository.Queryable().Where(x => ids.Contains(x.Id)).ToListAsync();
|
|
|
+
|
|
|
+ questionTags = _mapper.Map<List<QuestionTagDto>, List<QuestionTag>>(questionTagDtos,questionTags);
|
|
|
+
|
|
|
|
|
|
- questionTags.ToUpdate(actionRequest);
|
|
|
+ questionTags.ForEach(x => x.QuestionId = actionRequest.Id);
|
|
|
+
|
|
|
+ questionTags.ToUpdate(questionTagDtos);
|
|
|
|
|
|
await _questionTagRepository.UpdateWithValidateAsync(questionTags, cancellationToken);
|
|
|
}
|
|
@@ -328,14 +443,9 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
await UpdateSourcewares(actionRequest, cancellationToken);
|
|
|
|
|
|
- Expressionable<QuestionSourceware> expressionable = new Expressionable<QuestionSourceware>();
|
|
|
var questionSourcewareDtos = actionRequest.QuestionSourcewareDtos.Where(x => x.OperationStatus == OperationStatus.Delete);
|
|
|
- expressionable.AndIF(questionSourcewareDtos.Any(), x => questionSourcewareDtos.Select(m => m.Id).Contains(x.Id));
|
|
|
-
|
|
|
- var entityQueryRequest = new EntityQueryRequest
|
|
|
- {
|
|
|
- Expression = expressionable.ToExpression()
|
|
|
- };
|
|
|
+ var ids = questionSourcewareDtos.Select(m => m.Id);
|
|
|
+ EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionSourceware>(ids);
|
|
|
|
|
|
await DeleteSourcewares(entityQueryRequest, cancellationToken);
|
|
|
}
|
|
@@ -346,14 +456,9 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
await UpdateKnowladges(actionRequest, cancellationToken);
|
|
|
|
|
|
- Expressionable<QuestionKnowladge> expressionable = new Expressionable<QuestionKnowladge>();
|
|
|
var questionKnowladgeDtos = actionRequest.QuestionKnowladgeDtos.Where(x => x.OperationStatus == OperationStatus.Delete);
|
|
|
- expressionable.AndIF(questionKnowladgeDtos.Any(), x => questionKnowladgeDtos.Select(m => m.Id).Contains(x.Id));
|
|
|
-
|
|
|
- var entityQueryRequest = new EntityQueryRequest
|
|
|
- {
|
|
|
- Expression = expressionable.ToExpression()
|
|
|
- };
|
|
|
+ var ids = questionKnowladgeDtos.Select(m => m.Id);
|
|
|
+ EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionKnowladge>(ids);
|
|
|
|
|
|
await DeleteKnowladges(entityQueryRequest, cancellationToken);
|
|
|
}
|
|
@@ -382,14 +487,9 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
await UpdateQuestionOptions(actionRequest, cancellationToken);
|
|
|
|
|
|
- Expressionable<QuestionOptions> expressionable = new Expressionable<QuestionOptions>();
|
|
|
- var questionSourcewareDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == OperationStatus.Delete);
|
|
|
- expressionable.AndIF(questionSourcewareDtos.Any(), x => questionSourcewareDtos.Select(m => m.Id).Contains(x.Id));
|
|
|
-
|
|
|
- var entityQueryRequest = new EntityQueryRequest
|
|
|
- {
|
|
|
- Expression = expressionable.ToExpression()
|
|
|
- };
|
|
|
+ var questionOptionsDtos = actionRequest.QuestionOptionsDtos.Where(x => x.OperationStatus == OperationStatus.Delete);
|
|
|
+ var ids = questionOptionsDtos.Select(m => m.Id);
|
|
|
+ EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionOptions>(ids);
|
|
|
|
|
|
await DeleteQuestionOptions(entityQueryRequest, cancellationToken);
|
|
|
}
|
|
@@ -400,19 +500,24 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
|
|
|
await UpdateQuestionTags(actionRequest, cancellationToken);
|
|
|
|
|
|
- Expressionable<QuestionTag> expressionable = new Expressionable<QuestionTag>();
|
|
|
- var questionSourcewareDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == OperationStatus.Delete);
|
|
|
- expressionable.AndIF(questionSourcewareDtos.Any(), x => questionSourcewareDtos.Select(m => m.Id).Contains(x.Id));
|
|
|
-
|
|
|
- var entityQueryRequest = new EntityQueryRequest
|
|
|
- {
|
|
|
- Expression = expressionable.ToExpression()
|
|
|
- };
|
|
|
+ var questionTagDtos = actionRequest.QuestionTagDtos.Where(x => x.OperationStatus == OperationStatus.Delete);
|
|
|
+ var ids = questionTagDtos.Select(m => m.Id);
|
|
|
+ EntityQueryRequest entityQueryRequest = ResovleDelete<QuestionTag>(ids);
|
|
|
|
|
|
await DeleteQuestionTags(entityQueryRequest, cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private EntityQueryRequest ResovleDelete<T>(IEnumerable<string> ids) where T:class,IEntity<string>,new()
|
|
|
+ {
|
|
|
+ Expressionable<T> expressionable = ExpressionableUtility.CreateExpression<T>();
|
|
|
+ expressionable.AndIF(ids.Any(), x => ids.Contains(x.Id));
|
|
|
|
|
|
+ var entityQueryRequest = new EntityQueryRequest
|
|
|
+ {
|
|
|
+ Expression = ids.Any() ? expressionable.ToExpression() : null
|
|
|
+ };
|
|
|
+ return entityQueryRequest;
|
|
|
+ }
|
|
|
|
|
|
private async Task<List<QuestionSourcewareDto>> GetQuestionSourcewares(EntityQueryRequest entityQueryRequest)
|
|
|
{
|
|
@@ -435,7 +540,7 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
var questionOptionTable = await _questionOptionRepository.Queryable().Where(x => x.QuestionId == entityQueryRequest.Id).ToListAsync();
|
|
|
|
|
|
- var questionOptions = questionOptionTable.Adapt<List<QuestionOptionsDto>>();
|
|
|
+ var questionOptions = _mapper.Map<List<QuestionOptionsDto>>(questionOptionTable);
|
|
|
|
|
|
return questionOptions;
|
|
|
}
|
|
@@ -444,7 +549,7 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
var questionKnowladgeTable = await _questionKnowladgeRepository.Queryable().Where(x => x.QuestionId == entityQueryRequest.Id).ToListAsync();
|
|
|
|
|
|
- var questionKnowladges = questionKnowladgeTable.Adapt<List<QuestionKnowladgeDto>>();
|
|
|
+ var questionKnowladges = _mapper.Map<List<QuestionKnowladgeDto>>(questionKnowladgeTable);
|
|
|
|
|
|
return questionKnowladges;
|
|
|
}
|
|
@@ -453,7 +558,7 @@ namespace Hotline.Application.Exam.Service.Questions
|
|
|
{
|
|
|
var questionAnswer = await _questionAnswerRepository.GetAsync(entityQueryRequest.Id);
|
|
|
|
|
|
- var questionAnswerDto = questionAnswer.Adapt<QuestionAnswerDto>();
|
|
|
+ var questionAnswerDto = _mapper.Map<QuestionAnswerDto>(questionAnswer);
|
|
|
|
|
|
return questionAnswerDto;
|
|
|
}
|