assigonmentDto

This commit is contained in:
SpecialX
2025-06-24 11:37:12 +08:00
parent 681c0862b6
commit 0ee411bf50
11 changed files with 260 additions and 214 deletions

View File

@@ -12,7 +12,7 @@ using TechHelper.Context;
namespace TechHelper.Server.Migrations
{
[DbContext(typeof(ApplicationContext))]
[Migration("20250620104952_init")]
[Migration("20250624030547_init")]
partial class init
{
/// <inheritdoc />
@@ -49,6 +49,10 @@ namespace TechHelper.Server.Migrations
.HasColumnType("datetime(6)")
.HasColumnName("due_date");
b.Property<Guid>("ExamStructId")
.HasColumnType("char(36)")
.HasColumnName("exam_struct_id");
b.Property<bool>("IsDeleted")
.HasColumnType("tinyint(1)")
.HasColumnName("deleted");
@@ -82,6 +86,9 @@ namespace TechHelper.Server.Migrations
b.HasIndex("CreatorId");
b.HasIndex("ExamStructId")
.IsUnique();
b.HasIndex("UserId");
b.ToTable("assignments", (string)null);
@@ -161,10 +168,6 @@ namespace TechHelper.Server.Migrations
.HasColumnType("char(36)")
.HasColumnName("id");
b.Property<Guid?>("AssignmentId")
.HasColumnType("char(36)")
.HasColumnName("assignment");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)")
.HasColumnName("created_at");
@@ -206,9 +209,6 @@ namespace TechHelper.Server.Migrations
b.HasKey("Id");
b.HasIndex("AssignmentId")
.IsUnique();
b.HasIndex("ParentAssignmentQuestionId");
b.HasIndex("QuestionContextId");
@@ -747,19 +747,19 @@ namespace TechHelper.Server.Migrations
b.HasData(
new
{
Id = new Guid("577dbfe8-7b77-4ead-9386-678f02dea5f4"),
Id = new Guid("6163bf44-8dc7-4ad4-8d4c-c4452123949e"),
Name = "Student",
NormalizedName = "STUDENT"
},
new
{
Id = new Guid("04b04eed-32b9-4eb0-b5f5-a97bb4626718"),
Id = new Guid("90caaab6-bfc7-4b70-891a-4c6f327e29d8"),
Name = "Teacher",
NormalizedName = "TEACHER"
},
new
{
Id = new Guid("82354e4d-902d-4dd6-9790-6ef50ba9bc11"),
Id = new Guid("bf88293a-32d6-4d73-bc83-fe763c143024"),
Name = "Administrator",
NormalizedName = "ADMINISTRATOR"
});
@@ -876,11 +876,19 @@ namespace TechHelper.Server.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.Contracts.AssignmentQuestion", "ExamStruct")
.WithOne("Assignment")
.HasForeignKey("Entities.Contracts.Assignment", "ExamStructId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.Contracts.User", null)
.WithMany("CreatedAssignments")
.HasForeignKey("UserId");
b.Navigation("Creator");
b.Navigation("ExamStruct");
});
modelBuilder.Entity("Entities.Contracts.AssignmentAttachment", b =>
@@ -915,10 +923,6 @@ namespace TechHelper.Server.Migrations
modelBuilder.Entity("Entities.Contracts.AssignmentQuestion", b =>
{
b.HasOne("Entities.Contracts.Assignment", "Assignment")
.WithOne("ExamStruct")
.HasForeignKey("Entities.Contracts.AssignmentQuestion", "AssignmentId");
b.HasOne("Entities.Contracts.AssignmentQuestion", "ParentAssignmentQuestion")
.WithMany("ChildrenAssignmentQuestion")
.HasForeignKey("ParentAssignmentQuestionId");
@@ -933,8 +937,6 @@ namespace TechHelper.Server.Migrations
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Assignment");
b.Navigation("ParentAssignmentQuestion");
b.Navigation("Question");
@@ -1159,14 +1161,13 @@ namespace TechHelper.Server.Migrations
b.Navigation("AssignmentClasses");
b.Navigation("ExamStruct")
.IsRequired();
b.Navigation("Submissions");
});
modelBuilder.Entity("Entities.Contracts.AssignmentQuestion", b =>
{
b.Navigation("Assignment");
b.Navigation("ChildrenAssignmentQuestion");
b.Navigation("SubmissionDetails");

View File

@@ -229,42 +229,6 @@ namespace TechHelper.Server.Migrations
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "assignments",
columns: table => new
{
id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
title = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
description = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
subject_area = table.Column<byte>(type: "tinyint unsigned", nullable: false),
due_date = table.Column<DateTime>(type: "datetime(6)", nullable: false),
total_points = table.Column<byte>(type: "tinyint unsigned", nullable: false),
score = table.Column<float>(type: "float", nullable: false),
created_by = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
created_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
updated_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
UserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_assignments", x => x.id);
table.ForeignKey(
name: "FK_assignments_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id");
table.ForeignKey(
name: "FK_assignments_AspNetUsers_created_by",
column: x => x.created_by,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "classes",
columns: table => new
@@ -316,99 +280,6 @@ namespace TechHelper.Server.Migrations
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "assignment_attachments",
columns: table => new
{
id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
assignment_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
file_path = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
file_name = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
uploaded_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_assignment_attachments", x => x.id);
table.ForeignKey(
name: "FK_assignment_attachments_assignments_assignment_id",
column: x => x.assignment_id,
principalTable: "assignments",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "submissions",
columns: table => new
{
id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
assignment_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
student_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
attempt_number = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
submission_time = table.Column<DateTime>(type: "datetime(6)", nullable: false),
overall_grade = table.Column<float>(type: "float", precision: 5, scale: 2, nullable: true),
overall_feedback = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
graded_by = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
graded_at = table.Column<DateTime>(type: "datetime(6)", nullable: true),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
status = table.Column<int>(type: "int", maxLength: 15, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_submissions", x => x.id);
table.ForeignKey(
name: "FK_submissions_AspNetUsers_graded_by",
column: x => x.graded_by,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_submissions_AspNetUsers_student_id",
column: x => x.student_id,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_submissions_assignments_assignment_id",
column: x => x.assignment_id,
principalTable: "assignments",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "assignment_class",
columns: table => new
{
assignment_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
class_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
assigned_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PK_assignment_class", x => new { x.assignment_id, x.class_id });
table.ForeignKey(
name: "FK_assignment_class_assignments_assignment_id",
column: x => x.assignment_id,
principalTable: "assignments",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_assignment_class_classes_class_id",
column: x => x.class_id,
principalTable: "classes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "class_student",
columns: table => new
@@ -556,7 +427,6 @@ namespace TechHelper.Server.Migrations
{
id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
question_id = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
assignment = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
title = table.Column<string>(type: "varchar(1024)", maxLength: 1024, nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
description = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
@@ -581,11 +451,6 @@ namespace TechHelper.Server.Migrations
column: x => x.parent_question_group_id,
principalTable: "assignment_questions",
principalColumn: "id");
table.ForeignKey(
name: "FK_assignment_questions_assignments_assignment",
column: x => x.assignment,
principalTable: "assignments",
principalColumn: "id");
table.ForeignKey(
name: "FK_assignment_questions_questions_question_id",
column: x => x.question_id,
@@ -595,6 +460,142 @@ namespace TechHelper.Server.Migrations
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "assignments",
columns: table => new
{
id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
title = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
description = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
subject_area = table.Column<byte>(type: "tinyint unsigned", nullable: false),
exam_struct_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
due_date = table.Column<DateTime>(type: "datetime(6)", nullable: false),
total_points = table.Column<byte>(type: "tinyint unsigned", nullable: false),
score = table.Column<float>(type: "float", nullable: false),
created_by = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
created_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
updated_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
UserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_assignments", x => x.id);
table.ForeignKey(
name: "FK_assignments_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id");
table.ForeignKey(
name: "FK_assignments_AspNetUsers_created_by",
column: x => x.created_by,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_assignments_assignment_questions_exam_struct_id",
column: x => x.exam_struct_id,
principalTable: "assignment_questions",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "assignment_attachments",
columns: table => new
{
id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
assignment_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
file_path = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
file_name = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
uploaded_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_assignment_attachments", x => x.id);
table.ForeignKey(
name: "FK_assignment_attachments_assignments_assignment_id",
column: x => x.assignment_id,
principalTable: "assignments",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "assignment_class",
columns: table => new
{
assignment_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
class_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
assigned_at = table.Column<DateTime>(type: "datetime(6)", nullable: false),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false)
},
constraints: table =>
{
table.PrimaryKey("PK_assignment_class", x => new { x.assignment_id, x.class_id });
table.ForeignKey(
name: "FK_assignment_class_assignments_assignment_id",
column: x => x.assignment_id,
principalTable: "assignments",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_assignment_class_classes_class_id",
column: x => x.class_id,
principalTable: "classes",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "submissions",
columns: table => new
{
id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
assignment_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
student_id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
attempt_number = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
submission_time = table.Column<DateTime>(type: "datetime(6)", nullable: false),
overall_grade = table.Column<float>(type: "float", precision: 5, scale: 2, nullable: true),
overall_feedback = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
graded_by = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
graded_at = table.Column<DateTime>(type: "datetime(6)", nullable: true),
deleted = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false),
status = table.Column<int>(type: "int", maxLength: 15, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_submissions", x => x.id);
table.ForeignKey(
name: "FK_submissions_AspNetUsers_graded_by",
column: x => x.graded_by,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_submissions_AspNetUsers_student_id",
column: x => x.student_id,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_submissions_assignments_assignment_id",
column: x => x.assignment_id,
principalTable: "assignments",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "submission_details",
columns: table => new
@@ -643,9 +644,9 @@ namespace TechHelper.Server.Migrations
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
values: new object[,]
{
{ new Guid("04b04eed-32b9-4eb0-b5f5-a97bb4626718"), null, "Teacher", "TEACHER" },
{ new Guid("577dbfe8-7b77-4ead-9386-678f02dea5f4"), null, "Student", "STUDENT" },
{ new Guid("82354e4d-902d-4dd6-9790-6ef50ba9bc11"), null, "Administrator", "ADMINISTRATOR" }
{ new Guid("6163bf44-8dc7-4ad4-8d4c-c4452123949e"), null, "Student", "STUDENT" },
{ new Guid("90caaab6-bfc7-4b70-891a-4c6f327e29d8"), null, "Teacher", "TEACHER" },
{ new Guid("bf88293a-32d6-4d73-bc83-fe763c143024"), null, "Administrator", "ADMINISTRATOR" }
});
migrationBuilder.CreateIndex(
@@ -695,12 +696,6 @@ namespace TechHelper.Server.Migrations
table: "assignment_class",
column: "class_id");
migrationBuilder.CreateIndex(
name: "IX_assignment_questions_assignment",
table: "assignment_questions",
column: "assignment",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_assignment_questions_description",
table: "assignment_questions",
@@ -721,6 +716,12 @@ namespace TechHelper.Server.Migrations
table: "assignments",
column: "created_by");
migrationBuilder.CreateIndex(
name: "IX_assignments_exam_struct_id",
table: "assignments",
column: "exam_struct_id",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_assignments_UserId",
table: "assignments",
@@ -851,10 +852,13 @@ namespace TechHelper.Server.Migrations
name: "classes");
migrationBuilder.DropTable(
name: "assignment_questions");
name: "submissions");
migrationBuilder.DropTable(
name: "submissions");
name: "assignments");
migrationBuilder.DropTable(
name: "assignment_questions");
migrationBuilder.DropTable(
name: "QuestionContexts");
@@ -863,14 +867,11 @@ namespace TechHelper.Server.Migrations
name: "questions");
migrationBuilder.DropTable(
name: "assignments");
name: "AspNetUsers");
migrationBuilder.DropTable(
name: "key_point");
migrationBuilder.DropTable(
name: "AspNetUsers");
migrationBuilder.DropTable(
name: "lesson");

View File

@@ -46,6 +46,10 @@ namespace TechHelper.Server.Migrations
.HasColumnType("datetime(6)")
.HasColumnName("due_date");
b.Property<Guid>("ExamStructId")
.HasColumnType("char(36)")
.HasColumnName("exam_struct_id");
b.Property<bool>("IsDeleted")
.HasColumnType("tinyint(1)")
.HasColumnName("deleted");
@@ -79,6 +83,9 @@ namespace TechHelper.Server.Migrations
b.HasIndex("CreatorId");
b.HasIndex("ExamStructId")
.IsUnique();
b.HasIndex("UserId");
b.ToTable("assignments", (string)null);
@@ -158,10 +165,6 @@ namespace TechHelper.Server.Migrations
.HasColumnType("char(36)")
.HasColumnName("id");
b.Property<Guid?>("AssignmentId")
.HasColumnType("char(36)")
.HasColumnName("assignment");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime(6)")
.HasColumnName("created_at");
@@ -203,9 +206,6 @@ namespace TechHelper.Server.Migrations
b.HasKey("Id");
b.HasIndex("AssignmentId")
.IsUnique();
b.HasIndex("ParentAssignmentQuestionId");
b.HasIndex("QuestionContextId");
@@ -744,19 +744,19 @@ namespace TechHelper.Server.Migrations
b.HasData(
new
{
Id = new Guid("577dbfe8-7b77-4ead-9386-678f02dea5f4"),
Id = new Guid("6163bf44-8dc7-4ad4-8d4c-c4452123949e"),
Name = "Student",
NormalizedName = "STUDENT"
},
new
{
Id = new Guid("04b04eed-32b9-4eb0-b5f5-a97bb4626718"),
Id = new Guid("90caaab6-bfc7-4b70-891a-4c6f327e29d8"),
Name = "Teacher",
NormalizedName = "TEACHER"
},
new
{
Id = new Guid("82354e4d-902d-4dd6-9790-6ef50ba9bc11"),
Id = new Guid("bf88293a-32d6-4d73-bc83-fe763c143024"),
Name = "Administrator",
NormalizedName = "ADMINISTRATOR"
});
@@ -873,11 +873,19 @@ namespace TechHelper.Server.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.Contracts.AssignmentQuestion", "ExamStruct")
.WithOne("Assignment")
.HasForeignKey("Entities.Contracts.Assignment", "ExamStructId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.Contracts.User", null)
.WithMany("CreatedAssignments")
.HasForeignKey("UserId");
b.Navigation("Creator");
b.Navigation("ExamStruct");
});
modelBuilder.Entity("Entities.Contracts.AssignmentAttachment", b =>
@@ -912,10 +920,6 @@ namespace TechHelper.Server.Migrations
modelBuilder.Entity("Entities.Contracts.AssignmentQuestion", b =>
{
b.HasOne("Entities.Contracts.Assignment", "Assignment")
.WithOne("ExamStruct")
.HasForeignKey("Entities.Contracts.AssignmentQuestion", "AssignmentId");
b.HasOne("Entities.Contracts.AssignmentQuestion", "ParentAssignmentQuestion")
.WithMany("ChildrenAssignmentQuestion")
.HasForeignKey("ParentAssignmentQuestionId");
@@ -930,8 +934,6 @@ namespace TechHelper.Server.Migrations
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Assignment");
b.Navigation("ParentAssignmentQuestion");
b.Navigation("Question");
@@ -1156,14 +1158,13 @@ namespace TechHelper.Server.Migrations
b.Navigation("AssignmentClasses");
b.Navigation("ExamStruct")
.IsRequired();
b.Navigation("Submissions");
});
modelBuilder.Entity("Entities.Contracts.AssignmentQuestion", b =>
{
b.Navigation("Assignment");
b.Navigation("ChildrenAssignmentQuestion");
b.Navigation("SubmissionDetails");

View File

@@ -11,6 +11,7 @@ namespace TechHelper.Server.Repositories
private readonly IUnitOfWork _unitOfWork;
private readonly IRepository<Assignment> _assignmentRepo;
private readonly IRepository<Question> _questionRepo;
private readonly IRepository<AssignmentQuestion> _assignQuestionRepo;
public ExamRepository(IUnitOfWork unitOfWork)
{
@@ -20,11 +21,50 @@ namespace TechHelper.Server.Repositories
public async Task<Assignment?> GetFullExamByIdAsync(Guid assignmentId)
{
var result = await _assignmentRepo.GetFirstOrDefaultAsync(
predicate:
a => a.Id == assignmentId,
include:
i => i.Include(a => a.ExamStruct)
);
return null;
result.ExamStruct = await GetNeed(result.ExamStructId)?? null;
return result;
}
public async Task<AssignmentQuestion?> GetNeed(Guid id)
{
var result = await _assignQuestionRepo.GetFirstOrDefaultAsync(
predicate: aq => aq.Id == id,
include: i => i
.Include(aq => aq.ChildrenAssignmentQuestion)
.Include(aq => aq.Question)
.ThenInclude(q => q.Lesson)
.Include(aq => aq.Question)
.ThenInclude(q => q.KeyPoint)
);
if (result == null)
{
return null;
}
var loadedChildren = new List<AssignmentQuestion>();
foreach (var child in result.ChildrenAssignmentQuestion)
{
var loadedChild = await GetNeed(child.Id);
if (loadedChild != null)
{
loadedChildren.Add(loadedChild);
}
}
result.ChildrenAssignmentQuestion = loadedChildren;
return result;
}
public async Task<IEnumerable<Assignment>> GetExamPreviewsByUserAsync(Guid userId)

View File

@@ -75,10 +75,11 @@ namespace TechHelper.Server.Services
return _mapper.Map<AssignmentDto>(assignment);
}
public async Task<IEnumerable<AssignmentDto>> GetAllExamPreviewsAsync(Guid userId)
public async Task<ApiResponse> GetAllExamPreviewsAsync(Guid userId)
{
var assignments = await _examRepository.GetExamPreviewsByUserAsync(userId);
return _mapper.Map<IEnumerable<AssignmentDto>>(assignments);
var result = _mapper.Map<List<AssignmentDto>>(assignments);
return ApiResponse.Success(result: result);
}
@@ -87,9 +88,15 @@ namespace TechHelper.Server.Services
throw new NotImplementedException();
}
public Task<ApiResponse> GetAsync(Guid id)
public async Task<ApiResponse> GetAsync(Guid id)
{
throw new NotImplementedException();
var assignment = await _examRepository.GetFullExamByIdAsync(id);
if (assignment == null)
{
return ApiResponse.Error("获取失败");
}
var result = _mapper.Map<AssignmentDto>(assignment);
return ApiResponse.Success(result: result);
}
public Task<ApiResponse> AddAsync(AssignmentDto model)
@@ -107,10 +114,6 @@ namespace TechHelper.Server.Services
throw new NotImplementedException();
}
Task<ApiResponse> IExamService.GetAllExamPreviewsAsync(Guid userId)
{
throw new NotImplementedException();
}
}
}