Esempio n. 1
0
        public int CreatePostItem(string postID, FullPostItem postItem)
        {
            int ipostID = int.Parse(postID);
            using (MooDB db = new MooDB())
            {
                Post post = (from p in db.Posts
                             where p.ID == ipostID
                             select p).SingleOrDefault<Post>();
                if (post == null) throw new ArgumentException("无此帖子");

                PostItem newPostItem = new PostItem()
                {
                    Content = postItem.Content,
                    CreateTime = DateTime.Now,
                    CreatedBy = Security.CurrentUser.GetDBUser(db),
                    Post = post,
                };
                post.ReplyTime = DateTime.Now;

                Access.Required(db, newPostItem, Function.CreatePostItem);

                db.PostItems.AddObject(newPostItem);
                db.SaveChanges();
                return newPostItem.ID;
            }
        }
Esempio n. 2
0
        public void ModifyPostItem(string postID, string id, FullPostItem postItem)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                PostItem thePostItem = (from i in db.PostItems
                                        where i.ID == iid
                                        select i).SingleOrDefault<PostItem>();
                if (thePostItem == null) throw new ArgumentException("无此帖子楼层");

                Access.Required(db, thePostItem, Function.ModifyPostItem);

                if (postItem.Content != null)
                {
                    thePostItem.Content = postItem.Content;
                }

                db.SaveChanges();
            }
        }