public async Task <ResultModel> DeleteProblemData([FromBody] ProblemIdModel model) { var ret = new ResultModel { IsSucceeded = true }; var(user, privilege) = await GetUserPrivilegeAsync(); if (!HasTeacherPrivilege(privilege)) { ret.IsSucceeded = false; ret.ErrorMessage = "没有权限"; return(ret); } using (var db = new ApplicationDbContext(_dbContextOptions)) { var problem = await db.Problem.FindAsync(model.Id); if (problem == null) { ret.IsSucceeded = false; ret.ErrorMessage = "找不到此题目"; return(ret); } } var datadir = System.IO.Path.Combine(Environment.CurrentDirectory, "AppData", "Data", model.Id.ToString()); if (System.IO.Directory.Exists(datadir)) { System.IO.Directory.Delete(datadir, true); } return(ret); }
public async Task <ProblemIdModel> UpdateProblemConfig([FromBody] ProblemEditModel model) { var(user, privilege) = await GetUserPrivilegeAsync(); var ret = new ProblemIdModel { IsSucceeded = true }; if (!HasTeacherPrivilege(privilege)) { ret.IsSucceeded = false; ret.ErrorMessage = "没有权限"; return(ret); } using (var db = new ApplicationDbContext(_dbContextOptions)) { var problem = model.Id == 0 ? new Problem() : await db.Problem.FindAsync(model.Id); if (problem == null) { ret.IsSucceeded = false; ret.ErrorMessage = "题目不存在"; return(ret); } problem.Name = model.Name; problem.Level = model.Level; for (var i = (model.Config?.ExtraFiles?.Count ?? 0) - 1; i >= 0; i--) { if (string.IsNullOrEmpty(model.Config.ExtraFiles[i])) { model.Config.ExtraFiles.RemoveAt(i); } } problem.Config = JsonConvert.SerializeObject(model.Config); problem.Type = model.Type; problem.Description = model.Description; problem.Hidden = model.Hidden; if (model.Id == 0) { problem.CreationTime = DateTime.Now; problem.UserId = user.Id; await db.Problem.AddAsync(problem); } ; await db.SaveChangesAsync(); ret.Id = problem.Id; return(ret); } }
public IActionResult Create(ProblemIdModel model) { string name = this.submissionService.GetProblemName(model.Id); CreateSubmissionsModel problemData = new CreateSubmissionsModel { Name = name, ProblemId = model.Id }; return(this.View(problemData)); }
public IActionResult Create(PostSubmissionModel model) { if (!this.ModelState.IsValid) { ProblemIdModel navigationModel = new ProblemIdModel { Id = model.ProblemId }; return(this.Create(navigationModel)); } this.submissionService.CreateSubmission(model.ProblemId, model.Code, this.User.Id); return(this.Redirect("/")); }