public IActionResult Create(string Title) { var exp = new Experiment { Title = Title }; DB.Experiments.Add(exp); DB.SaveChanges(); return RedirectToAction("Edit", "Experiment", new { id = exp.Id }); }
public async Task<IActionResult> Edit(long id, IFormFile TestArchive, IFormFile AnswerArchive, Experiment Model, bool IsChecked) { var exp = DB.Experiments .Where(x => x.Id == id) .SingleOrDefault(); if (exp == null) return Prompt(x => { x.Title = "资源没有找到"; x.Details = "您请求的资源没有找到,请返回重试!"; x.StatusCode = 404; }); exp.Title = Model.Title; exp.Namespace = Model.Namespace; exp.NuGet = Model.NuGet; exp.OS = Model.OS; exp.CheckPassed = IsChecked; exp.TimeLimit = Model.TimeLimit; if (TestArchive != null) exp.TestArchive = await TestArchive.ReadAllBytesAsync(); if (AnswerArchive != null) exp.AnswerArchive = await AnswerArchive.ReadAllBytesAsync(); exp.Difficulty = Model.Difficulty; exp.Version = Model.Version; DB.SaveChanges(); return Prompt(x => { x.Title = "修改成功"; x.Details = "该实验已保存成功!"; }); }