Skip to content

Commit 47c29d6

Browse files
authored
Split query (#1449)
Closes https://github.com/SoftUni-Internal/exam-systems-issues/issues/your_issue_number **Summary of the changes made**: 1. {Describe your changes in the list} 2.
1 parent e717f43 commit 47c29d6

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

Services/UI/OJS.Services.Ui.Data/Implementations/ParticipantsDataService.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ namespace OJS.Services.Ui.Data.Implementations
1313

1414
public class ParticipantsDataService : DataService<Participant>, IParticipantsDataService
1515
{
16+
private readonly OjsDbContext db;
17+
1618
public ParticipantsDataService(OjsDbContext db)
17-
: base(db)
18-
{
19-
}
19+
: base(db) => this.db = db;
2020

2121
public Task<Participant?> GetByContestByUserAndByIsOfficial(
2222
int contestId,
@@ -26,19 +26,31 @@ public ParticipantsDataService(OjsDbContext db)
2626
.GetAllByContestByUserAndIsOfficial(contestId, userId, isOfficial)
2727
.FirstOrDefaultAsync();
2828

29-
public Task<Participant?> GetWithContestAndSubmissionDetailsByContestByUserAndIsOfficial(int contestId, string userId, bool isOfficial)
30-
=> this.GetAllByContestByUserAndIsOfficial(contestId, userId, isOfficial)
29+
public async Task<Participant?> GetWithContestAndSubmissionDetailsByContestByUserAndIsOfficial(int contestId, string userId, bool isOfficial)
30+
{
31+
var participant = await this.GetAllByContestByUserAndIsOfficial(contestId, userId, isOfficial)
3132
.Include(p => p.User)
32-
.Include(p => p.Contest)
33-
.ThenInclude(c => c.Category)
34-
.Include(p => p.Contest)
35-
.ThenInclude(c => c.ProblemGroups)
36-
.ThenInclude(pg => pg.Problems)
37-
.ThenInclude(p => p.SubmissionTypesInProblems)
38-
.ThenInclude(sp => sp.SubmissionType)
3933
.Include(p => p.ProblemsForParticipants)
4034
.FirstOrDefaultAsync();
4135

36+
var contest = await this.db.Contests.Where(c => contestId == c.Id)
37+
.Include(c => c.Category)
38+
.Include(c => c.ProblemGroups)
39+
.ThenInclude(pg => pg.Problems)
40+
.ThenInclude(p => p.SubmissionTypesInProblems)
41+
.ThenInclude(sp => sp.SubmissionType)
42+
.FirstOrDefaultAsync();
43+
44+
if (participant == null || contest == null)
45+
{
46+
return null;
47+
}
48+
49+
participant.ContestId = contestId;
50+
participant.Contest = contest;
51+
return participant;
52+
}
53+
4254
public IQueryable<Participant> GetWithProblemsForParticipantsByContestAndUser(int contestId,
4355
string userId)
4456
=> this.GetAllByContestAndUser(contestId, userId)

0 commit comments

Comments
 (0)