public async Task <IActionResult> Submit(CodeSubmitModel model, [FromServices] UserManager userManager) { var sub = await SubmissionManager.CreateAsync( code : model.Code, langid : model.Language, probid : Problem.ProblemId, cid : 0, uid : int.Parse(userManager.GetUserId(User)), ipAddr : HttpContext.Connection.RemoteIpAddress, via : "polygon-page", username : userManager.GetUserName(User), expected : Verdict.Unknown); return(RedirectToAction(nameof(Detail), new { sid = sub.SubmissionId })); }
public async Task <IActionResult> Submit(string probid, CodeSubmitModel model) { if (model.ProblemId != probid) { return(BadRequest()); } var prob = await Context.FindProblemAsync(probid); if (prob == null) { return(NotFound()); } if (!prob.AllowSubmit) { ModelState.AddModelError("prob::notallow", $"Problem {probid} is not allowed for submitting."); } // check language blocking var langs = await Context.ListLanguagesAsync(); var lang = langs.FirstOrDefault(a => a.Id == model.Language); if (lang == null) { ModelState.AddModelError("lang::notallow", "You can't submit solutions with this language."); } if (ModelState.ErrorCount > 0) { ViewBag.Language = langs; return(Window(model)); } else { await Context.SubmitAsync( code : model.Code, language : lang, problem : prob, team : Contest.Team, ipAddr : HttpContext.Connection.RemoteIpAddress, via : "problem-list", username : User.GetUserName()); return(RedirectToAction(nameof(View))); } }
public async Task <IActionResult> Submit( CodeSubmitModel model, [FromServices] ILanguageStore langs) { var lang = await langs.FindAsync(model.Language); if (lang == null) { return(BadRequest()); } var sub = await Submissions.CreateAsync( code : model.Code, language : lang.Id, problemId : Problem.ProblemId, contestId : null, userId : int.Parse(User.GetUserId()), ipAddr : HttpContext.Connection.RemoteIpAddress, via : "polygon-page", username : User.GetUserName(), expected : Verdict.Unknown); return(RedirectToAction(nameof(Detail), new { sid = sub.SubmissionId })); }
public async Task <IActionResult> Submit( int pid, CodeSubmitModel model, [FromServices] SubmissionManager subMgr) { 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 probQuery = from a in DbContext.Archives where a.PublicId == pid join p in DbContext.Problems on a.ProblemId equals p.ProblemId select new { p.Title, p.Source, p.ProblemId, p.AllowSubmit }; var prob = await probQuery.SingleOrDefaultAsync(); if (prob == null) { return(NotFound()); } if (!prob.AllowSubmit) { StatusMessage = $"Problem {pid} is not allowed for submitting."; return(RedirectToAction(nameof(View))); } // check language blocking var lang = await DbContext.Languages .Where(l => l.LangId == model.Language) .SingleOrDefaultAsync(); if (lang == null) { ModelState.AddModelError("lang::notfound", "Language is not found."); } else if (!lang.AllowSubmit) { ModelState.AddModelError("lang::notallow", "You can't submit solutions with this language."); } if (ModelState.ErrorCount > 0) { ViewBag.ProblemTitle = prob.Title; ViewBag.Language = await LanguagesAsync(); return(View(model)); } else { var sub = await subMgr.CreateAsync( code : model.Code, langid : model.Language, probid : prob.ProblemId, cid : 0, uid : int.Parse(UserManager.GetUserId(User)), ipAddr : HttpContext.Connection.RemoteIpAddress, via : "problem-list", username : UserManager.GetUserName(User)); int id = sub.SubmissionId; return(RedirectToAction(nameof(View))); } }
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))); } }