public int AddArticle(Model.Article article)
 {
     if (_roleService.AddArticlePower())
     {
         if (string.IsNullOrEmpty(article.Title))
         {
             throw new DomainException("Title", "文章标题不能为空!");
         }
         else if (string.IsNullOrEmpty(article.Content))
         {
             throw new DomainException("Content", "文章内容不能为空!");
         }
         else if (article.Categorys.Count == 0)
         {
             throw new DomainException("Category", "文章必须要有一个分类!");
         }
         article.Status = ArticleStatus.Open;
         article.Author = _userService.GetLoginUser();
         IList <Category> categorys = article.Categorys;
         article.Categorys = null;
         int id = _articleRepository.Add(article);
         article.Categorys = categorys;
         _articleRepository.Update(article);
         return(id);
     }
     else
     {
         throw new DomainException("NoPower", "对不起,您没有权限添加文章。");
     }
 }
        /// <summary>
        /// 添加评论
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public int AddComment(Comment comment)
        {
            if (!_roleService.AddCommentPower())
            {
                throw new DomainException("NoPower", "对不起,您没有权限发表评论。");
            }
            else
            {
                if (_sessionManager.User == null)
                {
                    if (string.IsNullOrEmpty(comment.Author))
                    {
                        throw new DomainException("NoAuthor", "对不起,需要填写昵称才能发表评论。");
                    }
                    else if (string.IsNullOrEmpty(comment.AuthorMail))
                    {
                        throw new DomainException("NoAuthor", "对不起,需要填写邮箱才能发表评论。");
                    }
                }
                else
                {
                    comment.User       = _sessionManager.User;
                    comment.Author     = comment.User.UserName;
                    comment.AuthorMail = comment.User.Email;
                }
                int id = 0;
                try
                {
                    //打开事务
                    _commentRepository.BeginTransaction();

                    //取得评论所在文章
                    comment.Article = _articleService.GetArticle(comment.Article.ArticleId);

                    //如果父评论不为空,而且父评论的文章ID跟当前的文章ID不一致,抛出异常
                    if (comment.Parent != null && comment.Article.ArticleId != comment.Parent.Article.ArticleId)
                    {
                        throw new DomainException("DataError", "对不起,您提交的数据异常!");
                    }
                    //检查镶套层数
                    CheckCommentLevel(comment);

                    //给文章添加评论个数
                    comment.Article.CommentCount++;

                    //评论的创建时间
                    comment.CreateDate = DateTime.Now;

                    //评论默认状态
                    if (_roleService.AddArticlePower())
                    {
                        comment.Status = CommentStatus.Open;
                    }
                    else
                    {
                        comment.Status = int.Parse(_settiongService.GetSetting("CommentSatus"));
                    }

                    //添加文章
                    id = _commentRepository.Add(comment);

                    //事务提交
                    _commentRepository.CommitTransaction();
                }
                catch (Exception ex)
                {
                    //回滚事务
                    _commentRepository.RollbackTransaction();
                    throw ex;
                }
                return(id);
            }
        }