ExamEdit&Check
This commit is contained in:
@@ -1,15 +1,45 @@
|
||||
@page "/exam/edit/{ExamId:Guid}"
|
||||
@page "/exam/edit/{ExamId}"
|
||||
@using Entities.DTO
|
||||
@using TechHelper.Client.Exam
|
||||
|
||||
<ExamView ParsedExam="@ExamDto"/>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public Guid ExamId { get; set; }
|
||||
public string ExamId { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IExamService ExamService { get; set; }
|
||||
|
||||
[Inject]
|
||||
private NavigationManager Navigation { get; set; }
|
||||
|
||||
[Inject]
|
||||
private ISnackbar Snackbar { get; set; }
|
||||
|
||||
private ExamDto ExamDto { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await ExamService.GetExam(Guid.NewGuid());
|
||||
|
||||
if (Guid.TryParse(ExamId, out Guid parsedExamId))
|
||||
{
|
||||
Console.WriteLine($"ExamId 字符串成功解析为 Guid: {parsedExamId}");
|
||||
try
|
||||
{
|
||||
var result = await ExamService.GetExam(parsedExamId);
|
||||
if (result.Status) ExamDto = result.Result as ExamDto ?? new ExamDto();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar?.Add($"获取试卷失败: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine($"错误:路由参数 ExamId '{ExamId}' 不是一个有效的 GUID 格式。无法获取试卷信息。");
|
||||
Navigation.NavigateTo("/exam/manager");
|
||||
Snackbar?.Add("无效的试卷ID,无法加载。", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user