public int CreateProblemRevision(string problemID, FullProblemRevision revision) { int iproblemID = int.Parse(problemID); using (MooDB db = new MooDB()) { Problem problem = (from p in db.Problems where p.ID == iproblemID select p).SingleOrDefault<Problem>(); if (problem == null) throw new ArgumentException("无此题目"); ProblemRevision problemRevision = new ProblemRevision() { CreatedBy = Security.CurrentUser.GetDBUser(db), Content = revision.Content, Problem = problem, Reason = revision.Reason, CreateTime = DateTime.Now }; problem.LatestRevision = problemRevision; Access.Required(db, problemRevision, Function.CreateProblemRevision); db.ProblemRevisions.AddObject(problemRevision); db.SaveChanges(); return problemRevision.ID; } }
/// <summary> /// 用于向 ProblemRevisions EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToProblemRevisions(ProblemRevision problemRevision) { base.AddObject("ProblemRevisions", problemRevision); }
public int CreateProblem(CreateProblemData problem) { if (!new[] { "Traditional", "SpecialJudged", "Interactive", "AnswerOnly" }.Contains(problem.Type)) { throw new NotSupportedException("不支持的题目类型:" + problem.Type); } using (MooDB db = new MooDB()) { User currentUser = Security.CurrentUser.GetDBUser(db); Problem newProblem = new Problem() { Name = problem.Name, Type = problem.Type, CreateTime = DateTime.Now, CreatedBy = currentUser, ArticleLocked = false, EnableTesting = true, Hidden = false, Locked = false, PostLocked = false, RecordLocked = false, TestCaseHidden = false, TestCaseLocked = false, }; Access.Required(db, newProblem, Function.CreateProblem); db.Problems.AddObject(newProblem); ProblemRevision revision = new ProblemRevision() { Content = problem.Content, CreatedBy = currentUser, CreateTime = DateTime.Now, Problem = newProblem, Reason = "创建题目", }; newProblem.LatestRevision = revision; Access.Required(db, revision, Function.CreateProblemRevision); db.ProblemRevisions.AddObject(revision); db.SaveChanges(); return newProblem.ID; } }
/// <summary> /// 创建新的 ProblemRevision 对象。 /// </summary> /// <param name="id">ID 属性的初始值。</param> /// <param name="content">Content 属性的初始值。</param> /// <param name="reason">Reason 属性的初始值。</param> /// <param name="createTime">CreateTime 属性的初始值。</param> public static ProblemRevision CreateProblemRevision(global::System.Int32 id, global::System.String content, global::System.String reason, global::System.DateTime createTime) { ProblemRevision problemRevision = new ProblemRevision(); problemRevision.ID = id; problemRevision.Content = content; problemRevision.Reason = reason; problemRevision.CreateTime = createTime; return problemRevision; }