@@ -13,6 +13,7 @@ namespace OJS.Services.Ui.Business.Implementations;
1313using OJS . Services . Infrastructure . Constants ;
1414using OJS . Services . Infrastructure . Extensions ;
1515using OJS . Services . Infrastructure . Models ;
16+ using OJS . Services . Infrastructure ;
1617using OJS . Services . Ui . Business . Cache ;
1718using OJS . Services . Ui . Business . Validations . Implementations . Contests ;
1819using OJS . Services . Ui . Data ;
@@ -34,7 +35,8 @@ public class ContestsBusinessService(
3435 IContestParticipantsCacheService contestParticipantsCacheService ,
3536 IContestsCacheService contestsCacheService ,
3637 ILecturersInContestsCacheService lecturersInContestsCache ,
37- IContestDetailsValidationService contestDetailsValidationService )
38+ IContestDetailsValidationService contestDetailsValidationService ,
39+ IDatesService datesService )
3840 : IContestsBusinessService
3941{
4042 public async Task < ServiceResult < ContestDetailsServiceModel > > GetContestDetails ( int id )
@@ -328,6 +330,8 @@ public async Task<ContestSearchServiceResultModel> GetSearchContestsByName(
328330 . MapCollection < ContestForListingServiceModel > ( )
329331 . ToPagedListAsync ( model . PageNumber , model . ItemsPerPage ) ;
330332
333+ this . SetContestVisibility ( searchContests ) ;
334+
331335 modelResult . Contests = searchContests ;
332336 modelResult . TotalContestsCount = allContestsQueryable . Count ( ) ;
333337
@@ -344,6 +348,8 @@ public async Task<PagedResult<ContestForListingServiceModel>> GetAllByFiltersAnd
344348 var pagedContests =
345349 await contestsData . GetAllAsPageByFiltersAndSorting < ContestForListingServiceModel > ( model , includeHidden ) ;
346350
351+ this . SetContestVisibility ( pagedContests . Items ) ;
352+
347353 var participantResultsByContest = new Dictionary < int , List < ParticipantResultServiceModel > > ( ) ;
348354 if ( user . IsAuthenticated )
349355 {
@@ -390,6 +396,8 @@ public async Task<PagedResult<ContestForListingServiceModel>> GetParticipatedByU
390396 participatedContests ,
391397 sortAndFilterModel ) ;
392398
399+ this . SetContestVisibility ( participatedContestsInPage . Items ) ;
400+
393401 var participantResultsByContest = new Dictionary < int , List < ParticipantResultServiceModel > > ( ) ;
394402 var loggedInUser = userProviderService . GetCurrentUser ( ) ;
395403
@@ -499,10 +507,16 @@ await pagedContests.Items.ForEachAsync(c =>
499507 . ToListAsync ( ) ;
500508
501509 public async Task < IEnumerable < ContestForListingServiceModel > > GetAllParticipatedContests ( string username )
502- => await contestsData
503- . GetLatestForParticipantByUsername ( username )
504- . MapCollection < ContestForListingServiceModel > ( )
505- . ToListAsync ( ) ;
510+ {
511+ var contests = await contestsData
512+ . GetLatestForParticipantByUsername ( username )
513+ . MapCollection < ContestForListingServiceModel > ( )
514+ . ToListAsync ( ) ;
515+
516+ this . SetContestVisibility ( contests ) ;
517+
518+ return contests ;
519+ }
506520
507521 private static async Task < Dictionary < int , List < ParticipantResultServiceModel > > > MapParticipationResultsToContestsInPage (
508522 IQueryable < Participant > participants )
@@ -565,4 +579,13 @@ private async Task<ContestFiltersServiceModel> GetNestedFilterCategoriesIfAny(Co
565579 official ,
566580 isUserAdminOrLecturerInContest ) ;
567581 }
582+
583+ private void SetContestVisibility ( IEnumerable < ContestForListingServiceModel > contests )
584+ {
585+ var now = datesService . GetUtcNow ( ) ;
586+ foreach ( var contest in contests )
587+ {
588+ contest . IsVisible = contest . IsVisible || contest . VisibleFrom <= now ;
589+ }
590+ }
568591}
0 commit comments