public async Task <IActionResult> Add(AddRejudgingModel model) { if (!ModelState.IsValid) { return(View(await model.LoadAsync(Context))); } var r = await Context.CreateAsync(new Rejudging { ContestId = Contest.Id, Reason = model.Reason, StartTime = DateTimeOffset.Now, IssuedBy = int.Parse(User.GetUserId()), }); var tb = model.TimeBefore.TryParseAsTimeSpan(out var timeBefore) && timeBefore.HasValue; var ta = model.TimeAfter.TryParseAsTimeSpan(out var timeAfter) && timeAfter.HasValue; var tat = ta ? (Contest.StartTime ?? DateTimeOffset.Now) + timeAfter.Value : DateTimeOffset.UnixEpoch; var tbt = tb ? (Contest.StartTime ?? DateTimeOffset.Now) + timeBefore.Value : DateTimeOffset.UnixEpoch; model.Problems ??= Array.Empty <int>(); model.Teams ??= Array.Empty <int>(); model.Languages ??= Array.Empty <string>(); model.Judgehosts ??= Array.Empty <string>(); model.Verdicts ??= Array.Empty <Verdict>(); var cond = Expr .Of <Submission, Judging>((s, j) => true) .CombineIf(model.Submission.HasValue, (s, j) => s.Id == model.Submission) .CombineIf(model.Problems.Length > 0, (s, j) => model.Problems.Contains(s.ProblemId)) .CombineIf(model.Teams.Length > 0, (s, j) => model.Teams.Contains(s.TeamId)) .CombineIf(model.Languages.Length > 0, (s, j) => model.Languages.Contains(s.Language)) .CombineIf(model.Judgehosts.Length > 0, (s, j) => model.Judgehosts.Contains(j.Server)) .CombineIf(model.Verdicts.Length > 0, (s, j) => model.Verdicts.Contains(j.Status)) .CombineIf(ta, (s, j) => s.Time >= tat) .CombineIf(tb, (s, j) => s.Time <= tbt); int tok = await Context.RejudgeAsync(cond, r, fullTest : Contest.RankingStrategy == CcsDefaults.RuleIOI); if (tok == 0) { await Context.DeleteAsync(r); StatusMessage = "Error no submissions was rejudged."; return(RedirectToAction(nameof(List))); } else { StatusMessage = $"{tok} submissions will be rejudged."; await HttpContext.AuditAsync("added", $"{r.Id}", $"with {tok} submissions"); return(RedirectToAction(nameof(Detail), new { rejudgingid = r.Id })); } }
public async Task <IActionResult> Add(int cid, AddRejudgingModel model) { if (!ModelState.IsValid) { return(View(model)); } var r = await Store.CreateAsync(new Rejudge { ContestId = Contest.ContestId, Reason = model.Reason, StartTime = DateTimeOffset.Now, IssuedBy = int.Parse(User.GetUserId()) }); Expression <Func <Submission, Judging, bool> > cond = (s, j) => s.RejudgeId == null && s.ContestId == cid; if (model.Submission.HasValue) { int sid = model.Submission.Value; cond = cond.Combine((s, j) => s.SubmissionId == sid); } else { var probs = model.Problems ?? Array.Empty <int>(); if (probs.Length > 0) { cond = cond.Combine((s, j) => probs.Contains(s.ProblemId)); } var teams = model.Teams ?? Array.Empty <int>(); if (teams.Length > 0) { cond = cond.Combine((s, j) => teams.Contains(s.Author)); } var langs = model.Languages ?? Array.Empty <string>(); if (langs.Length > 0) { cond = cond.Combine((s, j) => langs.Contains(s.Language)); } if (model.TimeBefore.TryParseAsTimeSpan(out var tb) && tb.HasValue) { var timed = (Contest.StartTime ?? DateTimeOffset.Now) + tb.Value; cond = cond.Combine((s, j) => s.Time <= timed); } if (model.TimeAfter.TryParseAsTimeSpan(out var ta) && ta.HasValue) { var timed = (Contest.StartTime ?? DateTimeOffset.Now) + ta.Value; cond = cond.Combine((s, j) => s.Time >= timed); } var hosts = model.Judgehosts ?? Array.Empty <string>(); if (hosts.Length > 0) { cond = cond.Combine((s, j) => hosts.Contains(j.Server)); } var verds = model.Verdicts ?? Array.Empty <Verdict>(); if (model.Verdicts.Length > 0) { cond = cond.Combine((s, j) => verds.Contains(j.Status)); } } int tok = await Store.BatchRejudgeAsync(cond, r, fullTest : Contest.RankingStrategy == 2); // if oi mode, force full judge if (tok == 0) { await Store.DeleteAsync(r); StatusMessage = "Error no submissions was rejudged."; return(RedirectToAction(nameof(List))); } else { StatusMessage = $"{tok} submissions will be rejudged."; await HttpContext.AuditAsync("added", $"{r.RejudgeId}", $"with {tok} submissions"); return(RedirectToAction(nameof(Detail), new { rid = r.RejudgeId })); } }