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 _assignmentRepo; private readonly IRepository _assignmentGroupRepo; private readonly IRepository _questionRepo; public ExamRepository(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; _assignmentRepo = _unitOfWork.GetRepository(); _assignmentGroupRepo = _unitOfWork.GetRepository(); } public async Task 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> 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) { } } }