public PaperUtils() { defaultModel = new PaperViewModels { CreateTime = DateTime.Now, PaperName = "", PID = AppSettings.PID }; }
public ActionResult UpdatePaper(PaperViewModels paper) { string err = ""; if (!paperUtils.AppUpdatePaper(paper, out err)) { return Json(new { isErr = true, errMsg = HttpUtility.JavaScriptStringEncode(err) }); } return Json(new { isErr = false }); }
public bool AppUpdatePaper(PaperViewModels paper, out string ErrMsg) { ErrMsg = null; try { if (string.IsNullOrEmpty(paper.PaperName)) { throw new ArgumentNullException("试卷名称不能为空", "PaperName"); } using (var ctx = new EvaluationSysEntities()) { if (paper.PaperId == null || paper.PaperId == default(int)) { ctx.TestPage.Add(new TestPage { Name = paper.PaperName, TopicArr = paper.TopicArrs, CreateTime = DateTime.Now, PID = ProjectId }); } else { var query = ctx.TestPage.FirstOrDefault(f => f.Id == paper.PaperId); query.Name = paper.PaperName; query.TopicArr = paper.TopicArrs; query.CreateTime = DateTime.Now; } return ctx.SaveChanges() >= 0; } } catch (Exception ex) { ErrMsg = ex.GetBaseException().Message; return false; } }