GetRootCategoryId() private method

private GetRootCategoryId ( int categoryId ) : int
categoryId int
return int
Exemplo n.º 1
0
        public ReturnResult <long> InsertArticleComment(ArticleCommentDataContract model, int articleCategoryId)
        {
            if (null == model)
            {
                return(new ReturnResult <long>(101, 0, "参数异常,未找到数据"));
            }
            if (string.IsNullOrWhiteSpace(model.CommentContent))
            {
                return(new ReturnResult <long>(102, 0, "参数异常,内容不允许为空"));
            }
            int rootCategoryId = articleCategoryService.GetRootCategoryId(articleCategoryId);

            if (rootCategoryId == -1)
            {
                return(new ReturnResult <long>(103, 0, "参数异常,文章分类错误"));
            }

            model.PostTime   = DateTime.Now;
            model.UpdateTime = DateTime.Now;
            model.TableName  = "SA_ArticleContent" + rootCategoryId;

            if (ArticleCommentRepository.Instance.InsertArticleComment(model))
            {
                System.Threading.Tasks.Task.Factory.StartNew(() => articleContentService.UpdateArticleCount(model.ArticleID, articleCategoryId, model.UserKeyId, ArticleCountEnum.CommentCount));
                return(new ReturnResult <long>(model.CommentID));
            }
            else
            {
                return(new ReturnResult <long>(104, 0, "评论发表失败"));
            }
        }
        /// <summary>
        /// 收藏帖子
        /// </summary>
        public ReturnResult <bool> AddArticleCollect(ArticleCollectDataContract articleCollect, int categoryId)
        {
            int rootCategoryId = articleCategoryService.GetRootCategoryId(categoryId);

            if (rootCategoryId == -1)
            {
                return(new ReturnResult <bool>(101, false, "分类参数错误"));
            }
            articleCollect.TableName = "SA_ArticleContent" + rootCategoryId;
            if (ArticleCollectRepository.Instance.IsExists(articleCollect.ArticleID, articleCollect.TableName))
            {
                return(new ReturnResult <bool>(true));
            }
            var article = ArticleContentRepository.Instance.GetArticle(rootCategoryId, articleCollect.ArticleID);

            if (null == article)
            {
                return(new ReturnResult <bool>(102, false, "未找到指定的帖子"));
            }
            articleCollect.Title           = article.Title;
            articleCollect.Author          = article.Author;
            articleCollect.AuthorUserKeyId = article.UserKeyId;
            articleCollect.CollectTime     = DateTime.Now;

            if (ArticleCollectRepository.Instance.InsertArticleCollect(articleCollect))
            {
                System.Threading.Tasks.Task.Factory.StartNew(() => articleContentService.UpdateArticleCount(article.ArticleID, article.CategoryId, articleCollect.UserKeyId, ArticleCountEnum.CollectCount));
                return(new ReturnResult <bool>(true));
            }
            return(new ReturnResult <bool>(103, false, "收藏失败"));
        }
Exemplo n.º 3
0
        public ReturnResult <bool> UpdateArticleCount(long articleId, int categoryId, long userKeyId, ArticleCountEnum articleCountEnum)
        {
            int rootCategoryId = articleCategoryService.GetRootCategoryId(categoryId);

            if (rootCategoryId == -1)
            {
                return(new ReturnResult <bool>(101, false, "分类参数错误"));
            }

            var isNeedVerification = articleCountEnum == ArticleCountEnum.EggCount || articleCountEnum == ArticleCountEnum.FlowerCount || articleCountEnum == ArticleCountEnum.WarnCount;

            if (isNeedVerification && ArticleContentRepository.Instance.IsReview(articleId, categoryId, userKeyId, (int)articleCountEnum))
            {
                return(new ReturnResult <bool>(102, false, "已经有过相同操作,不允许重复"));
            }

            var ret = ArticleContentRepository.Instance.UpdateArticleCount(articleId, rootCategoryId, articleCountEnum);

            if (isNeedVerification && ret)
            {
                var article = ArticleContentRepository.Instance.GetArticle(rootCategoryId, articleId);
                if (null != article)
                {
                    System.Threading.Tasks.Task.Factory.StartNew(() => ArticleContentRepository.Instance.InsertReViewRecord(new ReviewRecordDataContract()
                    {
                        ArticleID       = articleId,
                        CategoryId      = categoryId,
                        AuthorUserKeyId = article.UserKeyId,
                        ReviewType      = articleCountEnum,
                        Title           = article.Title,
                        UserKeyId       = userKeyId,
                        PostTime        = DateTime.Now
                    }));
                }
            }

            return(new ReturnResult <bool>(ret));
        }