Mango.Nop.Plugins/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionAdminViewComponent.cs

74 lines
2.4 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Nop.Plugin.Misc.AuctionPlugin;
using Nop.Services.Catalog;
using Nop.Services.Cms;
using Nop.Services.Common;
using Nop.Web.Areas.Admin.Models.Orders;
using Nop.Web.Framework.Components;
using Nop.Web.Framework.Infrastructure;
using Nop.Web.Models.Catalog;
namespace Nop.Plugin.AuctionPlugin.Components
{
[ViewComponent(Name = "AuctionAdmin")]
public class AuctionAdminViewComponent : NopViewComponent
{
#region Fields
protected readonly IAddressService _addressService;
protected readonly IProductAttributeService _productAttributeService;
protected readonly IWidgetPluginManager _widgetPluginManager;
protected readonly AuctionSettings _auctionSettings;
#endregion
#region Ctor
public AuctionAdminViewComponent(IAddressService addressService,
IProductAttributeService productAttributeService,
IWidgetPluginManager widgetPluginManager,
AuctionSettings auctionSettings)
{
_addressService = addressService;
_productAttributeService = productAttributeService;
_widgetPluginManager = widgetPluginManager;
_auctionSettings = auctionSettings;
}
#endregion
#region Methods
/// <summary>
/// Invoke the widget view component
/// </summary>
/// <param name="widgetZone">Widget zone</param>
/// <param name="additionalData">Additional parameters</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the view component result
/// </returns>
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
{
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName))
return Content(string.Empty);
if (!_auctionSettings.Enabled)
return Content(string.Empty);
//if (additionalData is not ProductDetailsModel model)
// return Content(string.Empty);
var productId = 0;
if (widgetZone.Equals(AdminWidgetZones.ProductDetailsBlock))
productId = (additionalData as ProductDetailsModel).Id;
return View("~/Plugins/Misc.AuctionPlugin/Views/AdminProductAuctionSettingsBox.cshtml", productId.ToString());
}
#endregion
}
}