src/ZKEACMS.Article/Service/ArticleSpecialDetailWidgetService.cs

(完整代码) 2KB

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

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

namespace ZKEACMS.Article.Service
{
    public class ArticleSpecialDetailWidgetService : SimpleWidgetService<ArticleSpecialDetailWidget>
    {
        private readonly IArticleService _articleService;
        public ArticleSpecialDetailWidgetService(IWidgetBasePartService widgetService, IArticleService articleService, IApplicationContext applicationContext, CMSDbContext dbContext)
            : base(widgetService, applicationContext, dbContext)
        {
            _articleService = articleService;
        }

        public override object Display(WidgetDisplayContext widgetDisplayContext)
        {
            var viewModel = new ArticleDetailViewModel();
            var articleWidget = widgetDisplayContext.Widget as ArticleSpecialDetailWidget;
            ArticleEntity article = null;
            int articleId = articleWidget.ArticleId ?? 0;
            if (articleId > 0)
            {
                article = _articleService.Get(articleId);
            }
            else if (articleWidget.ArticleName.IsNotNullAndWhiteSpace())
            {
                article = _articleService.GetByUrl(articleWidget.ArticleName);
            }
            if (article == null)
            {
                widgetDisplayContext.ActionContext.NotFoundResult();
            }
            else
            {
                _articleService.IncreaseCount(article);
                var layout = widgetDisplayContext.PageLayout;
                if (layout != null && layout.Page != null)
                {
                    layout.Page.ConfigSEO(article.Title, article.MetaKeyWords, article.MetaDescription);
                }
            }
            viewModel.Current = article;

            return viewModel;
        }
    }
}

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

AI 解读 AI

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

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