示例#1
0
        public int CreateArticleRevision(string articleID, CreateArticleRevisionData revision)
        {
            int iarticleID = int.Parse(articleID);
            using (MooDB db = new MooDB())
            {
                Article article = (from a in db.Articles
                                   where a.ID == iarticleID
                                   select a).SingleOrDefault<Article>();
                if (article == null) throw new ArgumentException("无此文章");

                ArticleRevision newRevision = new ArticleRevision
                {
                    Article = article,
                    Content = revision.Content,
                    CreatedBy = Security.CurrentUser.GetDBUser(db),
                    CreateTime = DateTime.Now,
                    Reason = revision.Reason
                };
                article.LatestRevision = newRevision;

                Access.Required(db, newRevision, Function.CreateArticleRevision);

                db.ArticleRevisions.AddObject(newRevision);
                db.SaveChanges();
                return newRevision.ID;
            }
        }
示例#2
0
 /// <summary>
 /// 创建新的 ArticleRevision 对象。
 /// </summary>
 /// <param name="id">ID 属性的初始值。</param>
 /// <param name="content">Content 属性的初始值。</param>
 /// <param name="createTime">CreateTime 属性的初始值。</param>
 /// <param name="reason">Reason 属性的初始值。</param>
 public static ArticleRevision CreateArticleRevision(global::System.Int32 id, global::System.String content, global::System.DateTime createTime, global::System.String reason)
 {
     ArticleRevision articleRevision = new ArticleRevision();
     articleRevision.ID = id;
     articleRevision.Content = content;
     articleRevision.CreateTime = createTime;
     articleRevision.Reason = reason;
     return articleRevision;
 }
示例#3
0
        public int CreateArticle(CreateArticleData article)
        {
            using (MooDB db = new MooDB())
            {
                Problem problem;
                if (article.ProblemID != null)
                {
                    problem = (from p in db.Problems
                               where p.ID == article.ProblemID
                               select p).SingleOrDefault<Problem>();
                    if (problem == null) throw new ArgumentException("无此题目");
                }
                else
                {
                    problem = null;
                }

                User currentUser = Security.CurrentUser.GetDBUser(db);
                Article newArticle = new Article()
                {
                    CreatedBy = currentUser,
                    CreateTime = DateTime.Now,
                    Name = article.Name,
                    Problem = problem,
                };
                Access.Required(db, newArticle, Function.CreateArticle);
                db.Articles.AddObject(newArticle);

                ArticleRevision revision = new ArticleRevision()
                {
                    Article = newArticle,
                    Content = article.Content,
                    CreatedBy = currentUser,
                    CreateTime = DateTime.Now,
                    Reason = "创建文章"
                };
                newArticle.LatestRevision = revision;
                Access.Required(db, revision, Function.CreateArticleRevision);
                db.ArticleRevisions.AddObject(revision);

                db.SaveChanges();
                return newArticle.ID;
            }
        }
示例#4
0
 /// <summary>
 /// 用于向 ArticleRevisions EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToArticleRevisions(ArticleRevision articleRevision)
 {
     base.AddObject("ArticleRevisions", articleRevision);
 }