public async Task <IActionResult> Submit( [FromServices] ILanguageStore langs) { ViewBag.Language = await langs.ListAsync(); return(Window(new CodeSubmitModel())); }
public async Task <IActionResult> Submit(int pid, [FromServices] ILanguageStore lang) { var prob = await Store.FindAsync(pid); if (prob == null) { return(NotFound()); } if (!prob.AllowSubmit.Value) { return(Message( title: $"Submit Problem {pid}", message: $"Problem {pid} is not allowed for submitting.", MessageType.Danger)); } ViewBag.ProblemTitle = prob.Title; ViewBag.Language = await lang.ListAsync(true); return(Window(new CodeSubmitModel { Code = "", Language = "cpp", ProblemId = pid, })); }
public async Task <IActionResult> ChangeExpected( int pid, int sid, [FromServices] ILanguageStore langs) { var sub = await Submissions.FindAsync(sid); if (sub == null || sub.ProblemId != pid) { return(NotFound()); } ViewBag.Languages = await langs.ListAsync(); return(Window(new ChangeExpectedModel { Verdict = !sub.ExpectedResult.HasValue ? -1 : (int)sub.ExpectedResult.Value, Language = sub.Language, })); }
public async Task <IActionResult> Submit( int pid, CodeSubmitModel model, [FromServices] ILanguageStore lang) { if (model.ProblemId != pid) { return(BadRequest()); } // check user blocking if (User.IsInRole("Blocked")) { ModelState.AddModelError("xys::blocked", "You are not permitted to submit code."); } // check problem submit var prob = await Store.FindAsync(pid); if (prob == null) { return(NotFound()); } if (!prob.AllowSubmit.Value) { StatusMessage = $"Problem {pid} is not allowed for submitting."; return(RedirectToAction(nameof(View))); } // check language blocking var langs = await lang.ListAsync(true); if (!langs.Any(a => a.Id == model.Language)) { ModelState.AddModelError("lang::notallow", "You can't submit solutions with this language."); } if (ModelState.ErrorCount > 0) { ViewBag.ProblemTitle = prob.Title; ViewBag.Language = langs; return(View(model)); } else { var sub = await Submits.CreateAsync( code : model.Code, language : model.Language, problemId : prob.ProblemId, contestId : null, userId : int.Parse(User.GetUserId()), ipAddr : HttpContext.Connection.RemoteIpAddress, via : "problem-list", username : User.GetUserName()); int id = sub.SubmissionId; return(RedirectToAction(nameof(View))); } }