Exemplo n.º 1
0
        /// <summary>
        /// 刪除文章及回覆
        /// </summary>
        /// <param name="id">The identifier.</param>
        public void DeletePostAndReply(int id)
        {
            using (var transScope = new TransactionScope())
            {
                using (var connection = _connFactory.GetConnection())
                {
                    // Delete Post
                    _postRepo.Delete(connection, id);
                    // Delete Reply
                    _replyRepo.DeleteByPostId(connection, id);
                }
                transScope.Complete();
            }

            // 刪除文章、回復,有可能刪除到管理者或是其他人的資料,因此直接重新刷新目前User的文章數量資訊
            var artCnt = new UserArticleCount()
            {
                PostCount  = _postRepo.GetPostCountByUserId(_conn, SignInUser.User.Id),
                ReplyCount = _replyRepo.GetReplyCountByUserId(_conn, SignInUser.User.Id)
            };

            SignInUser.SetArticleCount(artCnt);
        }