assigonmentDto
This commit is contained in:
@@ -11,6 +11,7 @@ namespace TechHelper.Server.Repositories
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IRepository<Assignment> _assignmentRepo;
|
||||
private readonly IRepository<Question> _questionRepo;
|
||||
private readonly IRepository<AssignmentQuestion> _assignQuestionRepo;
|
||||
|
||||
public ExamRepository(IUnitOfWork unitOfWork)
|
||||
{
|
||||
@@ -20,11 +21,50 @@ namespace TechHelper.Server.Repositories
|
||||
|
||||
public async Task<Assignment?> GetFullExamByIdAsync(Guid assignmentId)
|
||||
{
|
||||
var result = await _assignmentRepo.GetFirstOrDefaultAsync(
|
||||
predicate:
|
||||
a => a.Id == assignmentId,
|
||||
include:
|
||||
i => i.Include(a => a.ExamStruct)
|
||||
);
|
||||
|
||||
return null;
|
||||
result.ExamStruct = await GetNeed(result.ExamStructId)?? null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<AssignmentQuestion?> GetNeed(Guid id)
|
||||
{
|
||||
var result = await _assignQuestionRepo.GetFirstOrDefaultAsync(
|
||||
predicate: aq => aq.Id == id,
|
||||
include: i => i
|
||||
.Include(aq => aq.ChildrenAssignmentQuestion)
|
||||
.Include(aq => aq.Question)
|
||||
.ThenInclude(q => q.Lesson)
|
||||
.Include(aq => aq.Question)
|
||||
.ThenInclude(q => q.KeyPoint)
|
||||
);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var loadedChildren = new List<AssignmentQuestion>();
|
||||
foreach (var child in result.ChildrenAssignmentQuestion)
|
||||
{
|
||||
var loadedChild = await GetNeed(child.Id);
|
||||
if (loadedChild != null)
|
||||
{
|
||||
loadedChildren.Add(loadedChild);
|
||||
}
|
||||
}
|
||||
result.ChildrenAssignmentQuestion = loadedChildren;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<IEnumerable<Assignment>> GetExamPreviewsByUserAsync(Guid userId)
|
||||
|
Reference in New Issue
Block a user