Example #1
0
        public async Task <CheckResult> CheckProblemAsync(int probid, ClaimsPrincipal user)
        {
            int cid    = Contest.Id;
            int?userId = user.IsInRole("Administrator") ? default(int?) : int.Parse(user.GetUserId() ?? "-110");

            if (await Db.ContestProblems.Where(cp => cp.ContestId == cid && cp.ProblemId == probid).AnyAsync())
            {
                return(CheckResult.Fail("Problem has been added."));
            }

            IQueryable <Problem> query;

            if (userId == null)
            {
                query = Db.Problems
                        .Where(p => p.Id == probid);
            }
            else
            {
                query = Db.ProblemAuthors
                        .Where(pa => pa.ProblemId == probid && pa.UserId == userId)
                        .Join(Db.Problems, pa => pa.ProblemId, p => p.Id, (pa, p) => p);
            }

            var prob = await query.FirstOrDefaultAsync();

            if (prob == null)
            {
                return(CheckResult.Fail("Problem not found or access denined."));
            }

            return(CheckResult.Succeed(prob.Title));
        }
Example #2
0
        async Task <CheckResult <Rejudging> > IRejudgingContext.SystemTestAsync(int uid)
        {
            if (Contest.GetState() < Entities.ContestState.Ended)
            {
                return(CheckResult <Rejudging> .Fail("Contest should be ended first."));
            }

            if (Contest.Settings.SystemTestRejudgingId != null)
            {
                var rej = await Polygon.Rejudgings.FindAsync(Contest.Id, Contest.Settings.SystemTestRejudgingId.Value);

                return(rej != null
                    ? CheckResult <Rejudging> .Succeed(rej)
                    : CheckResult <Rejudging> .Fail($"Rejudging {Contest.Settings.SystemTestRejudgingId.Value} not found."));
            }

            if (await Polygon.Rejudgings.CountUndoneAsync(Contest.Id) != 0)
            {
                return(CheckResult <Rejudging> .Fail("There's pending rejudgings."));
            }

            var rejudging = new Rejudging
            {
                ContestId  = Contest.Id,
                Reason     = "System Test",
                StartTime  = DateTimeOffset.Now,
                EndTime    = DateTimeOffset.Now,
                IssuedBy   = uid,
                OperatedBy = uid,
                Applied    = true,
            };

            rejudging = await Polygon.Rejudgings.CreateAsync(rejudging);

            var settings = Contest.Settings.Clone();

            settings.SystemTestRejudgingId = rejudging.Id;
            var settingsJson = settings.ToJson();

            await UpdateContestAsync(c => new Entities.Contest {
                SettingsJson = settingsJson
            });

            var startTime = Contest.StartTime !.Value;
            var endTime   = (Contest.StartTime + Contest.EndTime) !.Value;
            int count     = await Polygon.Rejudgings.BatchRejudgeAsync(
                (s, j) => j.Status == Verdict.Accepted && s.Time >= startTime && s.Time <= endTime,
                rejudging, immediateApply : true, stageAsRunning : true);

            if (count == 0)
            {
                await Polygon.Rejudgings.DeleteAsync(rejudging);

                return(CheckResult <Rejudging> .Fail("There's no accepted submissions in this contest."));
            }

            await Mediator.Publish(new Events.ScoreboardRefreshEvent(this));

            await Db.Judgings
            .Where(j => j.RejudgingId == rejudging.Id)
            .BatchUpdateAsync(j => new Judging {
                Status = Verdict.Pending
            });

            return(CheckResult <Rejudging> .Succeed(rejudging));
        }