Пример #1
0
        public async Task <ContestEditDto> UpdateContestAsync(int id, ContestEditDto dto)
        {
            await EnsureContestExistsAsync(id);
            await ValidateContestEditDtoAsync(dto);

            var contest = await Context.Contests.FindAsync(id);

            contest.Title                = dto.Title;
            contest.Description          = dto.Description;
            contest.IsPublic             = dto.IsPublic.GetValueOrDefault();
            contest.Mode                 = dto.Mode.GetValueOrDefault();
            contest.BeginTime            = dto.BeginTime;
            contest.EndTime              = dto.EndTime;
            contest.HasScoreBonus        = dto.HasScoreBonus.GetValueOrDefault();
            contest.ScoreBonusTime       = dto.ScoreBonusTime;
            contest.ScoreBonusPercentage = dto.ScoreBonusPercentage;
            contest.HasScoreDecay        = dto.HasScoreDecay.GetValueOrDefault();
            contest.IsScoreDecayLinear   = dto.IsScoreDecayLinear;
            contest.ScoreDecayTime       = dto.ScoreDecayTime;
            contest.ScoreDecayPercentage = dto.ScoreDecayPercentage;
            Context.Contests.Update(contest);
            await Context.SaveChangesAsync();

            await Context.Entry(contest).Collection(c => c.Problems).LoadAsync();

            foreach (var problem in contest.Problems)
            {
                await _problemStatisticsService.InvalidStatisticsAsync(problem.Id);
            }

            await LogInformation($"UpdateContest Id={contest.Id} Title={contest.Title} " +
                                 $"IsPublic={contest.IsPublic} Mode={contest.Mode}");

            return(new ContestEditDto(contest));
        }
Пример #2
0
        public async Task <ProblemEditDto> UpdateProblemAsync(int id, ProblemEditDto dto)
        {
            await EnsureProblemExists(id);
            await ValidateProblemEditDtoAsync(dto);

            var problem = await Context.Problems.FindAsync(id);

            problem.ContestId           = dto.ContestId.GetValueOrDefault();
            problem.Title               = dto.Title;
            problem.Type                = dto.Type;
            problem.Description         = dto.Description;
            problem.InputFormat         = dto.InputFormat;
            problem.OutputFormat        = dto.OutputFormat;
            problem.FootNote            = dto.FootNote;
            problem.TimeLimit           = dto.TimeLimit.GetValueOrDefault();
            problem.MemoryLimit         = dto.MemoryLimit.GetValueOrDefault();
            problem.HasSpecialJudge     = dto.HasSpecialJudge;
            problem.SpecialJudgeProgram = dto.HasSpecialJudge ? dto.SpecialJudgeProgram : null;
            problem.HasHacking          = false;
            problem.SampleCases         = dto.SampleCases;
            Context.Problems.Update(problem);
            await Context.SaveChangesAsync();

            await _statistics.InvalidStatisticsAsync(problem.Id);

            await LogInformation($"UpdateProblem Id={problem.Id} Contest={problem.ContestId} Title={problem.Id} " +
                                 $"HasSpecialJudge={problem.HasSpecialJudge} HasHacking={problem.HasHacking}");

            return(new ProblemEditDto(problem));
        }
Пример #3
0
        public async Task <SubmissionEditDto> UpdateSubmissionAsync(int id, SubmissionEditDto dto)
        {
            await EnsureSubmissionExists(id);
            await ValidateSubmissionEditDto(dto);

            var user = await Manager.FindByIdAsync(Accessor.HttpContext.User.GetSubjectId());

            var submission = await Context.Submissions.FindAsync(id);

            submission.Verdict  = dto.Verdict.GetValueOrDefault();
            submission.Time     = submission.Memory = null;
            submission.FailedOn = null;
            submission.Score    = submission.Verdict == Verdict.Accepted ? 100 : 0;
            submission.Message  = dto.Message;
            submission.JudgedBy = "[manual] " + user.ContestantId;
            submission.JudgedAt = DateTime.Now.ToUniversalTime();
            Context.Update(submission);
            await Context.SaveChangesAsync();

            var problem = await Context.Problems.FindAsync(submission.ProblemId);

            var registration = await Context.Registrations.FindAsync(submission.UserId, problem.ContestId);

            await registration.RebuildStatisticsAsync(Context);

            await Context.SaveChangesAsync();

            await _statistics.InvalidStatisticsAsync(submission.ProblemId);

            await LogInformation($"UpdateSubmission Id={submission.Id} Verdict={submission.Verdict}");

            await Context.Entry(submission).Reference(s => s.User).LoadAsync();

            return(new SubmissionEditDto(submission));
        }