src/ZKEACMS.Product/Service/ProductDetailWidgetService.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
/* 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.Product.Models;
using ZKEACMS.Widget;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Easy.Extend;
using System.Collections.Concurrent;
namespace ZKEACMS.Product.Service
{
public class ProductDetailWidgetService : WidgetService<ProductDetailWidget>
{
private const string ProductDetailWidgetRelatedPageUrls = "ProductDetailWidgetRelatedPageUrls";
private readonly ConcurrentDictionary<string, object> _allRelatedUrlCache;
private readonly IProductService _productService;
public ProductDetailWidgetService(IWidgetBasePartService widgetService,
IProductService productService,
IApplicationContext applicationContext,
Easy.Cache.ICacheManager<ConcurrentDictionary<string, object>> cacheManager,
CMSDbContext dbContext)
: base(widgetService, applicationContext, dbContext)
{
_productService = productService;
_allRelatedUrlCache = cacheManager.GetOrAdd(ProductDetailWidgetRelatedPageUrls, new ConcurrentDictionary<string, object>());
}
private void DismissRelatedPageUrls()
{
_allRelatedUrlCache.TryRemove(ProductDetailWidgetRelatedPageUrls, out var urls);
}
public override void AddWidget(WidgetBase widget)
{
base.AddWidget(widget);
DismissRelatedPageUrls();
}
public override void DeleteWidget(string widgetId)
{
base.DeleteWidget(widgetId);
DismissRelatedPageUrls();
}
public override object Display(WidgetDisplayContext widgetDisplayContext)
{
var actionContext = widgetDisplayContext.ActionContext;
int productId = actionContext.RouteData.GetPost();
ProductEntity product = null;
if (productId != 0)
{
product = actionContext.RouteData.GetProduct(productId) ?? _productService.Get(productId);
if (product != null && product.Url.IsNotNullAndWhiteSpace() && actionContext.RouteData.GetProductUrl().IsNullOrWhiteSpace())
{
actionContext.RedirectTo($"{actionContext.RouteData.GetPath()}/{product.Url}.html", true);
}
后面还有 35 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。