93 lines
2.3 KiB
C#
93 lines
2.3 KiB
C#
using Entities.Contracts;
|
|
using Entities.DTO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SharedDATA.Api;
|
|
using TechHelper.Repository;
|
|
|
|
namespace TechHelper.Server.Repositories
|
|
{
|
|
public class ExamRepository : IExamRepository
|
|
{
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
private readonly IRepository<Assignment> _assignmentRepo;
|
|
private readonly IRepository<AssignmentStruct> _assignmentGroupRepo;
|
|
private readonly IRepository<Question> _questionRepo;
|
|
|
|
public ExamRepository(IUnitOfWork unitOfWork)
|
|
{
|
|
_unitOfWork = unitOfWork;
|
|
_assignmentRepo = _unitOfWork.GetRepository<Assignment>();
|
|
_assignmentGroupRepo = _unitOfWork.GetRepository<AssignmentStruct>();
|
|
}
|
|
|
|
public async Task<Assignment?> GetFullExamByIdAsync(Guid assignmentId)
|
|
{
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
private async Task LoadSubGroupsRecursive(AssignmentStruct group)
|
|
{
|
|
// EF Core 已经加载了下一层,我们需要确保更深层次的加载
|
|
var groupWithChildren = await _assignmentGroupRepo.GetFirstOrDefaultAsync(
|
|
predicate: g => g.Id == group.Id,
|
|
include: source => source
|
|
.Include(g => g.ChildrenGroups.Where(cg => !cg.IsDeleted))
|
|
.ThenInclude(cg => cg.AssignmentQuestions.Where(aq => !aq.IsDeleted))
|
|
.ThenInclude(aq => aq.Question)
|
|
.Include(g => g.AssignmentQuestions.Where(aq => !aq.IsDeleted))
|
|
.ThenInclude(aq => aq.Question)
|
|
);
|
|
|
|
group.ChildrenGroups = groupWithChildren.ChildrenGroups;
|
|
group.AssignmentQuestions = groupWithChildren.AssignmentQuestions;
|
|
|
|
if (group.ChildrenGroups != null)
|
|
{
|
|
foreach (var child in group.ChildrenGroups)
|
|
{
|
|
await LoadSubGroupsRecursive(child);
|
|
}
|
|
}
|
|
}
|
|
|
|
public async Task<IEnumerable<Assignment>> GetExamPreviewsByUserAsync(Guid userId)
|
|
{
|
|
return await _assignmentRepo.GetAllAsync(
|
|
predicate: a => a.CreatorId == userId && !a.IsDeleted);
|
|
}
|
|
|
|
public async Task AddAsync(Assignment assignment)
|
|
{
|
|
await _assignmentRepo.InsertAsync(assignment);
|
|
}
|
|
|
|
|
|
public async Task AddAsync(QuestionGroupDto qg)
|
|
{
|
|
if (qg.ValidQuestionGroup)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public async Task AddAsync(AssignmentStruct assignment)
|
|
{
|
|
|
|
}
|
|
|
|
public async Task AddAsync(AssignmentQuestion assignment)
|
|
{
|
|
}
|
|
|
|
public async Task AddAsync(Question assignment)
|
|
{
|
|
}
|
|
|
|
public async Task AddAsync(AssignmentClass assignment)
|
|
{
|
|
}
|
|
}
|
|
}
|