This commit is contained in:
SpecialX
2025-06-27 19:03:10 +08:00
parent 14fbe6397a
commit a21ca80782
57 changed files with 3872 additions and 611 deletions

View File

@@ -57,7 +57,7 @@ namespace TechHelper.Server.Services
}
catch (Exception ex)
{
return ApiResponse.Error(ex.Message);
return ApiResponse.Error(ex.Message);
}
}
@@ -78,7 +78,7 @@ namespace TechHelper.Server.Services
public async Task<ApiResponse> GetAllExamPreviewsAsync(Guid userId)
{
var assignments = await _examRepository.GetExamPreviewsByUserAsync(userId);
var result = _mapper.Map<List<AssignmentDto>>(assignments);
var result = _mapper.Map<List<AssignmentDto>>(assignments);
return ApiResponse.Success(result: result);
}
@@ -109,11 +109,72 @@ namespace TechHelper.Server.Services
throw new NotImplementedException();
}
public Task<ApiResponse> DeleteAsync(Guid id)
public async Task<ApiResponse> DeleteAsync(Guid id)
{
try
{
var assignment = await _unitOfWork.GetRepository<Assignment>().GetFirstOrDefaultAsync(predicate: a => a.Id == id);
if (assignment == null) return ApiResponse.Error("找不到该试卷");
_unitOfWork.GetRepository<Assignment>().Delete(id);
_unitOfWork.GetRepository<AssignmentQuestion>().Delete(assignment.ExamStructId);
if (await _unitOfWork.SaveChangesAsync() > 0)
{
return ApiResponse.Success();
}
return ApiResponse.Error("删除失败");
}
catch (Exception ex)
{
return ApiResponse.Error("内部问题");
}
}
public async Task<ApiResponse> SubmissionAssignment(SubmissionDto submissionDto)
{
try
{
var submission = _mapper.Map<Submission>(submissionDto);
await _examRepository.AddAsync(submission);
if (await _unitOfWork.SaveChangesAsync() > 0)
{
return ApiResponse.Success("保存成功");
}
return ApiResponse.Error("保存失败");
}
catch (Exception ex)
{
return ApiResponse.Error($"出现了错误,{ex.Message} innerEx:{ex.InnerException}");
}
}
public Task<ApiResponse> AssignmentToAllStudentsAsync(Guid id)
{
throw new NotImplementedException();
}
public Task<ApiResponse> AssignmentToStudentsAsync(Guid assignementId, Guid studentId)
{
throw new NotImplementedException();
}
public async Task<ApiResponse> GetAllSubmissionAsync(Guid id)
{
try
{
var result = await _examRepository.GetAllSubmissionPreviewsByUserAsync(id);
var allExam = _mapper.Map<List<AssignmentDto>>(result);
return ApiResponse.Success(result: allExam);
}
catch (Exception ex)
{
return ApiResponse.Error($"Submission 内部错误, {ex.Message}");
}
}
}
}