52 lines
2.3 KiB
C#
52 lines
2.3 KiB
C#
using AyCode.Core.Extensions;
|
|
using AyCode.Utils.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Nop.Core;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Hubs;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
|
using Nop.Services.Cms;
|
|
using Nop.Services.Customers;
|
|
using Nop.Services.Logging;
|
|
using Nop.Web.Framework.Components;
|
|
using Nop.Web.Framework.Infrastructure;
|
|
|
|
namespace Nop.Plugin.Misc.AuctionPlugin.Components
|
|
{
|
|
|
|
[ViewComponent(Name = "LiveAnnouncement")]
|
|
public class LiveAnnouncementViewComponent(ILogger logger, ILockService lockService, IWorkContext workContext, IWidgetPluginManager widgetPluginManager, AuctionService auctionService, IHubContext<AuctionHub> auctionHubContext, ICustomerService customerService)
|
|
: NopViewComponent
|
|
{
|
|
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
|
|
{
|
|
var customer = await workContext.GetCurrentCustomerAsync();
|
|
var currency = await workContext.GetWorkingCurrencyAsync();
|
|
|
|
await logger.InformationAsync($"LiveAnnouncementViewComponent.InvokeAsync(); widgetZone: {widgetZone}, customer: {customer.Email}", null, customer);
|
|
|
|
if (!await widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
|
|
return Content(string.Empty);
|
|
|
|
await logger.InformationAsync("LiveAnnouncementViewComponent.InvokeAsync(); SignalR Widget: widget active");
|
|
|
|
if (!widgetZone.Equals(PublicWidgetZones.BodyStartHtmlTagAfter))
|
|
return Content(string.Empty);
|
|
|
|
LiveAnnouncementViewModel myModel = new LiveAnnouncementViewModel();
|
|
|
|
myModel.CustomerId = customer.Id;
|
|
myModel.StoreId = customer.RegisteredInStoreId; //Temporary - A.
|
|
myModel.WorkingCurrency = currency;
|
|
myModel.IsAdmin = await customerService.IsAdminAsync(customer);
|
|
myModel.IsGuest = await customerService.IsGuestAsync(customer);
|
|
|
|
return View("~/Plugins/Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml", myModel);
|
|
}
|
|
}
|
|
}
|