1
This commit is contained in:
@@ -67,15 +67,13 @@ namespace TechHelper.Services
|
||||
}
|
||||
}
|
||||
|
||||
// 实现 IBaseService<ClassDto, int>.GetAllAsync
|
||||
public async Task<ApiResponse> GetAllAsync(QueryParameter query)
|
||||
{
|
||||
try
|
||||
{
|
||||
var repository = _work.GetRepository<Class>();
|
||||
|
||||
// 构建查询条件 (可根据 QueryParameter.Search 进行筛选)
|
||||
Func<IQueryable<Class>, IOrderedQueryable<Class>> orderBy = null; // 默认不排序
|
||||
Func<IQueryable<Class>, IOrderedQueryable<Class>> orderBy = null;
|
||||
if (query.Search != null && !string.IsNullOrWhiteSpace(query.Search))
|
||||
{
|
||||
// 在 Name 字段中进行模糊搜索
|
||||
@@ -127,9 +125,22 @@ namespace TechHelper.Services
|
||||
}
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetClassStudents(ClassDto classDto)
|
||||
public async Task<ApiResponse> GetClassStudents(ClassDto classDto)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
try
|
||||
{
|
||||
var result = await _work.GetRepository<Class>().GetFirstOrDefaultAsync(predicate:
|
||||
c => c.Grade == classDto.Grade && c.Number == classDto.Class,
|
||||
include: i => i
|
||||
.Include(c => c.ClassStudents)
|
||||
.ThenInclude(cs => cs.Student));
|
||||
|
||||
return ApiResponse.Success(result: result.ClassStudents);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ApiResponse.Error($"获取学生列表错误, {ex.Message}, {ex.InnerException}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ApiResponse> GetUserClass(Guid id)
|
||||
@@ -185,9 +196,6 @@ namespace TechHelper.Services
|
||||
var existingClass = await _work.GetRepository<Class>().GetFirstOrDefaultAsync(
|
||||
predicate: (c => c.Number == user.ClassId && c.Grade == user.GradeId));
|
||||
|
||||
// finduser and usrinfo are redundant if they are for the same user.
|
||||
// Let's just use usrinfo
|
||||
// var finduser = await _userManager.FindByEmailAsync(user.User);
|
||||
|
||||
if (existingClass == null || usrinfo == null) // Simplified check
|
||||
{
|
||||
|
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,10 +2,10 @@
|
||||
{
|
||||
public interface IBaseService<T, TId>
|
||||
{
|
||||
Task<TechHelper.Services.ApiResponse> GetAllAsync(QueryParameter query);
|
||||
Task<TechHelper.Services.ApiResponse> GetAsync(TId id);
|
||||
Task<TechHelper.Services.ApiResponse> AddAsync(T model);
|
||||
Task<TechHelper.Services.ApiResponse> UpdateAsync(T model);
|
||||
Task<TechHelper.Services.ApiResponse> DeleteAsync(TId id);
|
||||
Task<ApiResponse> GetAllAsync(QueryParameter query);
|
||||
Task<ApiResponse> GetAsync(TId id);
|
||||
Task<ApiResponse> AddAsync(T model);
|
||||
Task<ApiResponse> UpdateAsync(T model);
|
||||
Task<ApiResponse> DeleteAsync(TId id);
|
||||
}
|
||||
}
|
||||
|
@@ -22,5 +22,17 @@ namespace TechHelper.Server.Services
|
||||
/// <returns>创建成功的试卷ID</returns>
|
||||
Task<ApiResponse> CreateExamAsync(AssignmentDto examDto);
|
||||
|
||||
|
||||
|
||||
Task<ApiResponse> SubmissionAssignment(SubmissionDto submissionDto);
|
||||
|
||||
|
||||
Task<ApiResponse> AssignmentToAllStudentsAsync(Guid id);
|
||||
|
||||
Task<ApiResponse> AssignmentToStudentsAsync(Guid assignementId, Guid studentId);
|
||||
|
||||
|
||||
Task<ApiResponse> GetAllSubmissionAsync(Guid id);
|
||||
|
||||
}
|
||||
}
|
||||
|
16
TechHelper.Server/Services/ISubmissionServices.cs
Normal file
16
TechHelper.Server/Services/ISubmissionServices.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Entities.Contracts;
|
||||
using TechHelper.Services;
|
||||
|
||||
namespace TechHelper.Server.Services
|
||||
{
|
||||
public interface ISubmissionServices : IBaseService<Submission, Guid>
|
||||
{
|
||||
Task<ApiResponse> GetAssignmentErrorQuestionsAsync(Guid assignmentId, Guid userId);
|
||||
Task<ApiResponse> GetAllErrorQuestionsAsync(Guid userId);
|
||||
Task<ApiResponse> GetAssignmentErrorQuestionTypeDisAsync(Guid assignmentId, Guid userId);
|
||||
Task<ApiResponse> GetAllErrorQuestionTypeDisAsync(Guid assignmentId, Guid userId);
|
||||
|
||||
Task<ApiResponse> GetAssignmentAllStudentsError(Guid assignmentId, Guid teacherId);
|
||||
Task<ApiResponse> GetQuestionErrorStudents(Guid assignmentId);
|
||||
}
|
||||
}
|
10
TechHelper.Server/Services/IUserSerivces.cs
Normal file
10
TechHelper.Server/Services/IUserSerivces.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Entities.Contracts;
|
||||
using TechHelper.Services;
|
||||
|
||||
namespace TechHelper.Server.Services
|
||||
{
|
||||
public interface IUserSerivces : IBaseService<User, Guid>
|
||||
{
|
||||
Task<ApiResponse> GetStudentDetailInfo(Guid userId);
|
||||
}
|
||||
}
|
91
TechHelper.Server/Services/SubmissionServices.cs
Normal file
91
TechHelper.Server/Services/SubmissionServices.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using AutoMapper;
|
||||
using Entities.Contracts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedDATA.Api;
|
||||
using TechHelper.Services;
|
||||
|
||||
namespace TechHelper.Server.Services
|
||||
{
|
||||
public class SubmissionServices : ISubmissionServices
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IRepository<Submission> _submissionRepository;
|
||||
private readonly IRepository<SubmissionDetail> _submissionDetailRepository;
|
||||
|
||||
public SubmissionServices(IMapper mapper, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_unitOfWork = unitOfWork;
|
||||
_submissionRepository = _unitOfWork.GetRepository<Submission>();
|
||||
_submissionDetailRepository = _unitOfWork.GetRepository<SubmissionDetail>();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> AddAsync(Submission model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> DeleteAsync(Guid id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAllAsync(QueryParameter query)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<ApiResponse> GetAllErrorQuestionsAsync(Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var errorSDs = await _submissionDetailRepository.GetPagedListAsync(predicate: sd => sd.StudentId == userId && sd.IsCorrect == false,
|
||||
include: i => i
|
||||
.Include(s => s.AssignmentQuestion)
|
||||
.ThenInclude(aq => aq.Question));
|
||||
var errorQuestion = errorSDs.Items.Select(sd => sd.AssignmentQuestion).ToList();
|
||||
return ApiResponse.Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ApiResponse.Error();
|
||||
}
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAllErrorQuestionTypeDisAsync(Guid assignmentId, Guid userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAssignmentAllStudentsError(Guid assignmentId, Guid teacherId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAssignmentErrorQuestionsAsync(Guid assignmentId, Guid userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAssignmentErrorQuestionTypeDisAsync(Guid assignmentId, Guid userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAsync(Guid id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetQuestionErrorStudents(Guid assignmentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> UpdateAsync(Submission model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
38
TechHelper.Server/Services/UserServices.cs
Normal file
38
TechHelper.Server/Services/UserServices.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Entities.Contracts;
|
||||
using TechHelper.Services;
|
||||
|
||||
namespace TechHelper.Server.Services
|
||||
{
|
||||
public class UserServices : IUserSerivces
|
||||
{
|
||||
public Task<ApiResponse> AddAsync(User model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> DeleteAsync(Guid id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAllAsync(QueryParameter query)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetAsync(Guid id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> GetStudentDetailInfo(Guid userId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task<ApiResponse> UpdateAsync(User model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user