Skip to content

Commit 1831cbd

Browse files
committed
Fixed bug concerning exercise queries
1 parent fcd0eea commit 1831cbd

File tree

6 files changed

+884
-8
lines changed

6 files changed

+884
-8
lines changed

grade-management-new/GradeManagement.Bll/Profiles/AutoMapperProfile.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public AutoMapperProfile()
2222
{
2323
CreateMap<Assignment, Shared.Dtos.Assignment>();
2424
CreateMap<Course, Shared.Dtos.Course>();
25-
CreateMap<Exercise, ExerciseResponse>();
25+
CreateMap<Exercise, ExerciseResponse>().ForMember(dest => dest.ScoreTypes,
26+
opt => opt.MapFrom(src =>
27+
src.ScoreTypeExercises.Where(ste => ste.ExerciseId == src.Id)
28+
.ToDictionary(ste => ste.Order, ste => ste.ScoreType.Type)));
2629
CreateMap<Group, GroupResponse>();
2730
CreateMap<Language, Shared.Dtos.Language>();
2831
CreateMap<PullRequest, Shared.Dtos.PullRequest>();
@@ -32,7 +35,7 @@ public AutoMapperProfile()
3235
CreateMap<ScoreTypeExercise, Shared.Dtos.ScoreTypeExercise>();
3336
CreateMap<Semester, Shared.Dtos.Semester>();
3437
CreateMap<Student, StudentResponse>();
35-
CreateMap<Subject, SubjectResponse>() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SubjectId));;
38+
CreateMap<Subject, SubjectResponse>().ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SubjectId));
3639
CreateMap<User, Shared.Dtos.User>();
3740
}
3841
}

grade-management-new/GradeManagement.Bll/Services/CourseService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ public async Task DeleteAsync(long id)
8787

8888
public async Task<IEnumerable<ExerciseResponse>> GetAllExercisesByIdAsync(long id)
8989
{
90-
return await gradeManagementDbContext.Exercise
90+
var exercises = await gradeManagementDbContext.Exercise
9191
.Where(e => e.CourseId == id)
92-
.ProjectTo<ExerciseResponse>(mapper.ConfigurationProvider)
92+
.Include(e => e.ScoreTypeExercises).ThenInclude(ste => ste.ScoreType)
9393
.ToListAsync();
94+
return mapper.Map<List<ExerciseResponse>>(exercises);
9495
}
9596

9697
public async Task<IEnumerable<GroupResponse>> GetAllGroupsByIdAsync(long id)

grade-management-new/GradeManagement.Bll/Services/ExerciseService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public class ExerciseService(
3232
public async Task<IEnumerable<ExerciseResponse>> GetAllAsync()
3333
{
3434
return await gradeManagementDbContext.Exercise
35-
.Include(e => e.ScoreTypeExercises)
35+
.Include(e => e.ScoreTypeExercises).ThenInclude(ste => ste.ScoreType)
3636
.ProjectTo<ExerciseResponse>(mapper.ConfigurationProvider)
3737
.ToListAsync();
3838
}
3939

4040
public async Task<ExerciseResponse> GetByIdAsync(long id)
4141
{
4242
return await gradeManagementDbContext.Exercise
43-
.Include(e => e.ScoreTypeExercises)
43+
.Include(e => e.ScoreTypeExercises).ThenInclude(ste => ste.ScoreType)
4444
.ProjectTo<ExerciseResponse>(mapper.ConfigurationProvider)
4545
.SingleEntityAsync(e => e.Id == id, id);
4646
}

0 commit comments

Comments
 (0)