diff --git a/Services/UI/OJS.Services.Ui.Business/Implementations/ContestsBusinessService.cs b/Services/UI/OJS.Services.Ui.Business/Implementations/ContestsBusinessService.cs index 31be3e37a0..219400c721 100644 --- a/Services/UI/OJS.Services.Ui.Business/Implementations/ContestsBusinessService.cs +++ b/Services/UI/OJS.Services.Ui.Business/Implementations/ContestsBusinessService.cs @@ -13,6 +13,7 @@ namespace OJS.Services.Ui.Business.Implementations; using OJS.Services.Infrastructure.Constants; using OJS.Services.Infrastructure.Extensions; using OJS.Services.Infrastructure.Models; +using OJS.Services.Infrastructure; using OJS.Services.Ui.Business.Cache; using OJS.Services.Ui.Business.Validations.Implementations.Contests; using OJS.Services.Ui.Data; @@ -34,7 +35,8 @@ public class ContestsBusinessService( IContestParticipantsCacheService contestParticipantsCacheService, IContestsCacheService contestsCacheService, ILecturersInContestsCacheService lecturersInContestsCache, - IContestDetailsValidationService contestDetailsValidationService) + IContestDetailsValidationService contestDetailsValidationService, + IDatesService datesService) : IContestsBusinessService { public async Task> GetContestDetails(int id) @@ -328,6 +330,8 @@ public async Task GetSearchContestsByName( .MapCollection() .ToPagedListAsync(model.PageNumber, model.ItemsPerPage); + this.SetContestVisibility(searchContests); + modelResult.Contests = searchContests; modelResult.TotalContestsCount = allContestsQueryable.Count(); @@ -344,6 +348,8 @@ public async Task> GetAllByFiltersAnd var pagedContests = await contestsData.GetAllAsPageByFiltersAndSorting(model, includeHidden); + this.SetContestVisibility(pagedContests.Items); + var participantResultsByContest = new Dictionary>(); if (user.IsAuthenticated) { @@ -390,6 +396,8 @@ public async Task> GetParticipatedByU participatedContests, sortAndFilterModel); + this.SetContestVisibility(participatedContestsInPage.Items); + var participantResultsByContest = new Dictionary>(); var loggedInUser = userProviderService.GetCurrentUser(); @@ -499,10 +507,16 @@ await pagedContests.Items.ForEachAsync(c => .ToListAsync(); public async Task> GetAllParticipatedContests(string username) - => await contestsData - .GetLatestForParticipantByUsername(username) - .MapCollection() - .ToListAsync(); + { + var contests = await contestsData + .GetLatestForParticipantByUsername(username) + .MapCollection() + .ToListAsync(); + + this.SetContestVisibility(contests); + + return contests; + } private static async Task>> MapParticipationResultsToContestsInPage( IQueryable participants) @@ -565,4 +579,13 @@ private async Task GetNestedFilterCategoriesIfAny(Co official, isUserAdminOrLecturerInContest); } + + private void SetContestVisibility(IEnumerable contests) + { + var now = datesService.GetUtcNow(); + foreach (var contest in contests) + { + contest.IsVisible = contest.IsVisible || contest.VisibleFrom <= now; + } + } } \ No newline at end of file diff --git a/Services/UI/OJS.Services.Ui.Models/Contests/ContestForListingServiceModel.cs b/Services/UI/OJS.Services.Ui.Models/Contests/ContestForListingServiceModel.cs index ed630a9ecf..c82be95875 100644 --- a/Services/UI/OJS.Services.Ui.Models/Contests/ContestForListingServiceModel.cs +++ b/Services/UI/OJS.Services.Ui.Models/Contests/ContestForListingServiceModel.cs @@ -84,9 +84,6 @@ public void RegisterMappings(IProfileExpression configuration) .SelectMany(pg => pg.Problems) .Where(x => !x.IsDeleted) .Sum(pr => pr.MaximumPoints))) - .ForMember( - c => c.IsVisible, - opt => opt.MapFrom(s => s.IsVisible || s.VisibleFrom <= DateTime.UtcNow)) // For online contests: // In a problem group with multiple problems, compete points are derived from a single problem, // unlike practice mode where points can be accumulated from all problems across groups.