Exemplo n.º 1
0
        public IList <ArticleModel> SelectByPage(ArticleConditionModel articleConditionModel)
        {
            ArticleCondition            condition     = ConvertCondition(articleConditionModel);
            IEnumerable <Article>       articles      = _articleRepository.SelectByPage(articleConditionModel.PageSize, articleConditionModel.PageIndex, condition);
            Dictionary <string, string> userNames     = _userRepository.SelectNameWithAccountDic(articles.Select(s => s.Author));
            IList <ArticleModel>        articleModels = new List <ArticleModel>();

            foreach (var item in articles)
            {
                ArticleModel articleModel = new ArticleModel();
                articleModel.Id            = item.Id;
                articleModel.ArticleType   = item.ArticleType.GetEnumText();
                articleModel.TextSection   = item.TextSection.Trim();
                articleModel.Title         = item.Title;
                articleModel.AuthorAccount = item.Author;
                articleModel.Author        = userNames[item.Author];
                articleModel.CreateTime    = item.CreateTime.Value.ToString("yyyy-MM-dd hh:mm");
                articleModel.IsDraft       = item.IsDraft ? "是" : "否";
                articleModel.PraiseCount   = item.PraiseCount;
                articleModel.BrowserCount  = item.BrowserCount;
                articleModel.CommentCount  = string.IsNullOrEmpty(item.CommentIds) ? 0 : item.CommentIds.Split(',').Length;
                articleModels.Add(articleModel);
            }
            return(articleModels);
        }
Exemplo n.º 2
0
        public int SelectCount(ArticleConditionModel articleConditionModel = null)
        {
            ArticleCondition articleCondition = null;

            if (articleConditionModel != null)
            {
                articleCondition = ConvertCondition(articleConditionModel);
            }
            return(_articleRepository.SelectCount(articleCondition));
        }
Exemplo n.º 3
0
        public ApiResult SelectArticle([FromBody] ArticleConditionModel condition)
        {
            if (condition.LoginUser)
            {
                condition.Account = Auth.GetLoginUser(_httpContext).Account;
            }
            IList <ArticleModel> articleModels = _articleService.SelectByPage(condition);
            int total = _articleService.SelectCount(condition);

            return(ApiResult.Success(new { list = articleModels, total = total }));
        }
Exemplo n.º 4
0
        private ArticleCondition ConvertCondition(ArticleConditionModel articleConditionModel)
        {
            ArticleCondition articleCondition = new ArticleCondition();

            articleCondition.ArticleType  = articleConditionModel.ArticleType;
            articleCondition.FullText     = articleConditionModel.FullText;
            articleCondition.IsDraft      = Convert.ToBoolean(articleConditionModel.IsDraft);
            articleCondition.TitleContain = articleConditionModel.TitleContain;
            if (!string.IsNullOrEmpty(articleConditionModel.Account))
            {
                articleCondition.Account = articleConditionModel.Account;
            }
            return(articleCondition);
        }