src/ZKEACMS.Product/Service/ProductGalleryWidgetService.cs
(完整代码) 2KB/* http://www.zkea.net/
* Copyright (c) ZKEASOFT. All rights reserved.
* http://www.zkea.net/licenses */
using Easy;
using Easy.Constant;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZKEACMS.Product.Models;
using ZKEACMS.Product.ViewModel;
using ZKEACMS.Widget;
namespace ZKEACMS.Product.Service
{
public class ProductGalleryWidgetService : SimpleWidgetService<ProductGalleryWidget>
{
private readonly IProductService _productService;
private readonly IProductGalleryService _productGalleryService;
public ProductGalleryWidgetService(IWidgetBasePartService widgetBasePartService,
IApplicationContext applicationContext,
CMSDbContext dbContext,
IProductService productService,
IProductGalleryService ProductGalleryService)
: base(widgetBasePartService, applicationContext, dbContext)
{
_productService = productService;
_productGalleryService = ProductGalleryService;
}
public override object Display(WidgetDisplayContext widgetDisplayContext)
{
var widget = widgetDisplayContext.Widget as ProductGalleryWidget;
ProductGalleryWidgetViewModel viewModel = new ProductGalleryWidgetViewModel { DetailPageUrl = widget.DetailPageUrl };
var productGallery = _productGalleryService.Get(widget.ProductGalleryId);
if (productGallery == null || productGallery.Products.Count() == 0)
{
viewModel.Products = Enumerable.Empty<ProductEntity>();
}
else
{
var productIds = productGallery.Products.Where(m => m.Product != null && m.Status == (int)RecordStatus.Active)
.Select(m => m.Product.ProductID)
.ToArray();
viewModel.Products = _productService
.Get(m => productIds.Contains(m.ID) && m.IsPublish && m.Status == (int)RecordStatus.Active)
.OrderBy(m => Array.IndexOf(productIds, m.ID))
.ToList();
}
return viewModel;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。