public static Int64 SavePost(BoardPost boardPost) { if (boardPost.PostID > 0) { Update(boardPost); } else { //get the parent containers when a new post is created // to update their post counts BoardCategory bc = (from c in BoardCategory.All() join f in BoardForum.All() on c.CategoryID equals f.CategoryID where f.ForumID == boardPost.ForumID select c).FirstOrDefault(); BoardForum bf = (from f in BoardForum.All() where f.ForumID == boardPost.ForumID select f).FirstOrDefault(); //update the thread count if (boardPost.IsThread) { bc.ThreadCount = bc.ThreadCount + 1; bf.ThreadCount = bf.ThreadCount + 1; } //update the post count else { bc.PostCount = bc.PostCount + 1; bf.PostCount = bf.PostCount + 1; //update post count on thread BoardPost bThread = null; if (boardPost.ThreadID != 0) { bThread = (from p in BoardPost.All() where p.PostID == boardPost.ThreadID select p).FirstOrDefault(); } if (bThread != null) { bThread.ReplyCount = bThread.ReplyCount + 1; } } Add(boardPost); } return boardPost.PostID; }
public static void DeletePost(BoardPost boardPost) { //if this is a thread then we need to delete all of it's children if (boardPost.IsThread) { foreach (BoardPost i in All().Where(bp => bp.ThreadID == boardPost.PostID)) { Delete(i.Id); } } Delete(boardPost.Id); }