src/ZKEACMS.Article/Service/ArticleTopWidgetService.cs

(完整代码) 1KB

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Easy;
using Easy.RepositoryPattern;
using Microsoft.AspNetCore.Http;
using ZKEACMS.Article.Models;
using ZKEACMS.Article.ViewModel;
using ZKEACMS.Widget;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using System;
using Microsoft.AspNetCore.Mvc;

namespace ZKEACMS.Article.Service
{
    public class ArticleTopWidgetService : WidgetService<ArticleTopWidget>
    {
        private readonly IArticleService _articleService;
        private readonly IArticleTypeService _articleTypeService;
        public ArticleTopWidgetService(IWidgetBasePartService widgetService,
            IArticleService articleService,
            IApplicationContext applicationContext,
            IArticleTypeService articleTypeService,
            CMSDbContext dbContext) : base(widgetService, applicationContext, dbContext)
        {
            _articleService = articleService;
            _articleTypeService = articleTypeService;
        }

        public override object Display(WidgetDisplayContext widgetDisplayContext)
        {
            var currentWidget = widgetDisplayContext.Widget as ArticleTopWidget;
            var viewModel = new ArticleTopWidgetViewModel
            {
                Widget = currentWidget
            };
            var categoryIds = _articleTypeService.Get(m => m.ID == currentWidget.ArticleTypeID || m.ParentID == currentWidget.ArticleTypeID).Select(m => m.ID);
            viewModel.Articles = _articleService.Get(m => m.IsPublish && categoryIds.Contains(m.ArticleTypeID ?? 0)).OrderByDescending(m => m.PublishDate).Take(currentWidget.Tops ?? 10);
            return viewModel;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。