Example #1
0
        /// <summary>
        /// 分页获取博客文章
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <PaginationOut <List <BlogArticleVM> > > GetArticles(GetBlogArticleInput input)
        {
            var blogArticleVM = new List <BlogArticleVM>();
            var query         = await _blogArticle.GetAllIncludingAsyn(x => x.User, x => x.Category, x => x.BlogArticleLabels);

            var articles = query.OrderByDescending(x => x.CreateTime).Skip(input.SkipCount).Take(input.Limit);//分页核心

            foreach (var article in articles)
            {
                var articleVM = new BlogArticleVM(article);
                articleVM.Thumbnail = string.IsNullOrEmpty(article?.Thumbnail) ? _randomDataHepler.GetRandomAvatar() : article?.Thumbnail;
                articleVM.User      = await GetUserDtoByUser(article.User);

                articleVM.CommentsCount = await GetCommentCount(article.Id);

                articleVM.ViewCount = await GetArticleViewCount(article.Id);

                blogArticleVM.Add(articleVM);
            }
            var statusCode = HttpContext.Response.StatusCode.Equals(200) ? 0 : 1;

            return(new PaginationOut <List <BlogArticleVM> >
            {
                Code = statusCode,
                Msg = statusCode.Equals(0) ? "" : "请求错误Ծ‸Ծ",
                Count = query.Count(),
                Data = blogArticleVM
            });
        }
Example #2
0
        public async Task <PaginationOut <List <BlogArticleVM> > > GetBlogArticles(GetBlogArticleInput input)
        {
            var blogArticleVM = new List <BlogArticleVM>();
            var query         = await _blogArticle.GetAllAsyn();

            var articles = query.OrderBy(x => x.CreateTime).Skip(input.SkipCount).Take(input.Limit); //分页核心
            var counter  = 0;                                                                        //序号

            foreach (var article in articles)
            {
                var articleVM = new BlogArticleVM(article);
                articleVM.SortCode = ++counter + (input.Page - 1) * input.Limit;
                blogArticleVM.Add(articleVM);
            }
            var statusCode = HttpContext.Response.StatusCode.Equals(200);

            return(new PaginationOut <List <BlogArticleVM> >
            {
                Code = statusCode ? 0 : 1,
                Msg = statusCode ? "" : "Error",
                Count = query.Count(),
                Data = blogArticleVM
            });
        }