This commit is contained in:
SpecialX
2025-07-01 19:05:07 +08:00
parent a21ca80782
commit 017cc2169c
33 changed files with 3778 additions and 109 deletions

View File

@@ -14,13 +14,17 @@ namespace TechHelper.Server.Services
{
private readonly IUnitOfWork _unitOfWork;
private readonly IExamRepository _examRepository;
private readonly ISubmissionServices _submissionService;
private readonly IClassService _classService;
private readonly IMapper _mapper;
public ExamService(IUnitOfWork unitOfWork, IExamRepository examRepository, IMapper mapper)
public ExamService(IUnitOfWork unitOfWork, IExamRepository examRepository, IMapper mapper, IClassService classService, ISubmissionServices submissionService)
{
_unitOfWork = unitOfWork;
_examRepository = examRepository;
_mapper = mapper;
_classService = classService;
_submissionService = submissionService;
}
public async Task<ApiResponse> CreateExamAsync(AssignmentDto assignmentDto)
@@ -128,7 +132,7 @@ namespace TechHelper.Server.Services
}
catch (Exception ex)
{
return ApiResponse.Error("内部问题");
return ApiResponse.Error($"内部问题,{ex.Message}, InerException{ex.InnerException}");
}
}
@@ -152,14 +156,65 @@ namespace TechHelper.Server.Services
}
}
public Task<ApiResponse> AssignmentToAllStudentsAsync(Guid id)
public async Task<ApiResponse> AssignmentToAllStudentsAsync(Guid assignmentId, Guid TeacherId)
{
throw new NotImplementedException();
try
{
var classes = await _classService.GetUserClass(TeacherId);
var classUsrClass = classes.Result as List<Class>;
var classDto = _mapper.Map<ClassDto>(classUsrClass?.FirstOrDefault());
var cla = await _classService.GetClassStudents(classDto);
var assignment = await _examRepository.GetFullExamByIdAsync(assignmentId);
if (assignment == null) return ApiResponse.Error("没有找到该试卷");
var cs = cla.Result as ICollection<ClassStudent>;
cs?.ToList().ForEach(async s =>
{
var subCount = _unitOfWork.GetRepository<Submission>().GetAll(predicate: su => su.AssignmentId == assignmentId && su.StudentId == s.StudentId);
var submission = assignment.ConvertToSubmission(s.StudentId, TeacherId);
submission.AttemptNumber = (byte)(subCount.Count() + 1);
await _unitOfWork.GetRepository<Submission>().InsertAsync(submission);
});
if (await _unitOfWork.SaveChangesAsync() > 0)
{
return ApiResponse.Success();
}
return ApiResponse.Error();
}
catch (Exception ex)
{
return ApiResponse.Error($"内部错误, {ex.Message}");
}
}
public Task<ApiResponse> AssignmentToStudentsAsync(Guid assignementId, Guid studentId)
public async Task<ApiResponse> AssignmentToStudentsAsync(AssigExamToStudentsDto examToStudentsDto)
{
throw new NotImplementedException();
try
{
var assignment = await _examRepository.GetFullExamByIdAsync(examToStudentsDto.AssignmentId);
if (assignment == null) return ApiResponse.Error("没有找到该试卷");
examToStudentsDto.StudentIds?.ForEach(async s =>
{
var subCount = _unitOfWork.GetRepository<Submission>().GetAll(predicate: su => su.AssignmentId == examToStudentsDto.AssignmentId && su.StudentId == s);
var submission = assignment.ConvertToSubmission(s, examToStudentsDto.CreaterId);
submission.AttemptNumber = (byte)(subCount.Count() + 1);
await _unitOfWork.GetRepository<Submission>().InsertAsync(submission);
});
if (await _unitOfWork.SaveChangesAsync() > 0)
{
return ApiResponse.Success();
}
return ApiResponse.Error();
}
catch (Exception ex)
{
return ApiResponse.Error($"内部错误, {ex.Message}");
}
}
public async Task<ApiResponse> GetAllSubmissionAsync(Guid id)