
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 30s
- 添加学生提交管理服务 (StudentSubmissionService, StudentSubmissionDetailService) - 新增学生提交相关控制器 (StudentSubmissionController, StudentSubmissionDetailController) - 添加学生提交数据传输对象 (StudentSubmissionDetailDto, StudentSubmissionSummaryDto) - 新增学生提交相关页面组件 (StudentExamView, ExamDetailView, StudentCard等) - 添加学生提交信息卡片组件 (SubmissionInfoCard, TeacherSubmissionInfoCard) - 更新数据库迁移文件以支持提交系统
86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using Entities.Contracts;
|
|
using Entities.DTO;
|
|
using Newtonsoft.Json;
|
|
using System.Net.Http.Json;
|
|
using TechHelper.Client.HttpRepository;
|
|
using TechHelper.Services;
|
|
|
|
namespace TechHelper.Client.Services
|
|
{
|
|
public class ClasssServices : IClassServices
|
|
{
|
|
private readonly HttpClient _client;
|
|
private readonly IAuthenticationClientService _authenticationClientService;
|
|
|
|
public ClasssServices(HttpClient client, IAuthenticationClientService authenticationClientService)
|
|
{
|
|
_client = client;
|
|
_authenticationClientService = authenticationClientService;
|
|
}
|
|
|
|
public Task<ResponseDto> CreateClass(UserRegistrationToClassDto userClass)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<ApiResponse> GetClassStudents()
|
|
{
|
|
try
|
|
{
|
|
var result = await _client.PostAsJsonAsync("class/getClassStudents","");
|
|
var content = await result.Content.ReadAsStringAsync();
|
|
var users = JsonConvert.DeserializeObject<List<StudentDto>>(content);
|
|
return ApiResponse.Success(result: users);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
return ApiResponse.Error($"获取失败,{ex.Message}, InnerException: {ex.InnerException}");
|
|
}
|
|
}
|
|
|
|
public async Task<ApiResponse> GetGradeClasses(byte grade)
|
|
{
|
|
try
|
|
{
|
|
var result = await _client.PostAsJsonAsync("class/GetGradeClasses", grade);
|
|
var content = await result.Content.ReadAsStringAsync();
|
|
Console.WriteLine($"服务器返回的原始内容是: {content}");
|
|
var users = JsonConvert.DeserializeObject<List<byte>>(content);
|
|
return ApiResponse.Success(result: users);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ApiResponse.Error($"获取失败,{ex.Message}, InnerException: {ex.InnerException}");
|
|
}
|
|
}
|
|
|
|
public StudentDto GetStudents(byte Class)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public async Task<ResponseDto> UserRegister(UserRegistrationToClassDto userRegistrationToClassDto)
|
|
{
|
|
try
|
|
{
|
|
var result = await _client.PostAsJsonAsync("class/userRegiste",
|
|
userRegistrationToClassDto);
|
|
var data = await result.Content.ReadAsStringAsync();
|
|
|
|
await _authenticationClientService.RefreshTokenAsync();
|
|
|
|
return new ResponseDto
|
|
{
|
|
IsSuccessfulRegistration = result.IsSuccessStatusCode,
|
|
Errors = result.IsSuccessStatusCode ? null : new string[] { data }
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// 实际应用中,这里应该加入日志记录
|
|
Console.WriteLine($"Error in UserRegister: {ex.Message}");
|
|
return new ResponseDto { IsSuccessfulRegistration = false, Errors = new string[] { ex.Message } };
|
|
}
|
|
}
|
|
}
|
|
} |