improvements, fixes, etc...
This commit is contained in:
parent
070f634069
commit
7353efadc4
|
|
@ -98,11 +98,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Components
|
|||
|
||||
productId = productModel.Id;
|
||||
|
||||
var auctions = await _auctionService.GetAllAuctionsAsync() ?? new List<Auction>();
|
||||
var auctions = await _auctionService.GetAllAuctionsAsync() ?? [];
|
||||
|
||||
// Assign the auctions to the ViewBag
|
||||
ViewBag.Auctions = auctions;
|
||||
ProductAssignToAuctionViewModel viewModel = new ProductAssignToAuctionViewModel();
|
||||
var viewModel = new ProductAssignToAuctionViewModel();
|
||||
viewModel.ProductId = productId;
|
||||
viewModel.StartingPrice = productModel.OldPrice;
|
||||
viewModel.BidPrice = productModel.OldPrice;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using AyCode.Core.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.Services;
|
||||
using Nop.Services.Cms;
|
||||
using Nop.Services.Logging;
|
||||
using Nop.Web.Framework.Components;
|
||||
|
|
@ -9,31 +16,64 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Components
|
|||
{
|
||||
|
||||
[ViewComponent(Name = "LiveAnnouncement")]
|
||||
public class LiveAnnouncementViewComponent : NopViewComponent
|
||||
public class LiveAnnouncementViewComponent(ILogger logger, IWorkContext workContext, IWidgetPluginManager widgetPluginManager, AuctionService auctionService, IHubContext<AuctionHub> auctionHubContext)
|
||||
: NopViewComponent
|
||||
{
|
||||
protected readonly ILogger _logger;
|
||||
protected readonly IWorkContext _workContext;
|
||||
protected readonly IWidgetPluginManager _widgetPluginManager;
|
||||
|
||||
public LiveAnnouncementViewComponent(ILogger logger, IWorkContext workContext, IWidgetPluginManager widgetPluginManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_workContext = workContext;
|
||||
_widgetPluginManager = widgetPluginManager;
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
|
||||
{
|
||||
await _logger.InformationAsync("SignalR Widget called");
|
||||
//await logger.InformationAsync("LiveAnnouncementViewComponent.InvokeAsync called");
|
||||
|
||||
//lock... - J.
|
||||
var auctions = await auctionService.GetAllCurrentAutoOpenAndClosedAuctionsAsync();
|
||||
if (auctions.Count > 0)
|
||||
{
|
||||
await logger.InformationAsync($"LiveAnnouncementViewComponent.InvokeAsync auctions.Count > 0; count: {auctions.Count}; names: {string.Join("; ", auctions.Select(x => x.AuctionName))}");
|
||||
|
||||
var statusChangedMessageWrapper = new MessageWrapper
|
||||
{
|
||||
MessageType = nameof(ProductToAuctionStatusNotification),
|
||||
SenderId = 0,
|
||||
ResponseType = ResponseType.ToAllClients
|
||||
};
|
||||
|
||||
foreach (var auction in auctions)
|
||||
{
|
||||
auction.Closed = false;
|
||||
await auctionService.UpdateAuctionAsync(auction);
|
||||
|
||||
var auctionDto = new AuctionDto(auction);
|
||||
var productToAuctions = (await auctionService.GetProductToAuctionsByAuctionIdAsync(auction.Id, false)).Where(x => x.AuctionStatus == AuctionStatus.None).ToList();
|
||||
|
||||
foreach (var productToAuction in productToAuctions)
|
||||
{
|
||||
productToAuction.AuctionStatus = AuctionStatus.Active;
|
||||
|
||||
await auctionService.UpdateProductToAuctionMappingAsync(productToAuction);
|
||||
|
||||
auctionDto.ProductToAuctionDtos.Clear();//TEMPOPRARY - J.
|
||||
auctionDto.ProductToAuctionDtos.Add(new ProductToAuctionDto(productToAuction));
|
||||
|
||||
////TEMPOPRARY - J.
|
||||
//statusChangedMessageWrapper.Data = new ProductToAuctionStatusNotification(auctionDto, 0, $"Az aukciót megnyitottuk: {auction.AuctionName}").ToJson();
|
||||
//await _auctionHubContext.Clients.All.SendAsync("send", statusChangedMessageWrapper.ToJson());
|
||||
////TEMPOPRARY - J.
|
||||
}
|
||||
|
||||
await auctionService.UpdateProductToAuctionMappingAsync(productToAuctions);
|
||||
|
||||
statusChangedMessageWrapper.Data = new ProductToAuctionStatusNotification(auctionDto, 0, $"Az aukciót megnyitottuk: {auction.AuctionName}").ToJson();
|
||||
await auctionHubContext.Clients.All.SendAsync("send", statusChangedMessageWrapper.ToJson());
|
||||
}
|
||||
}
|
||||
|
||||
//ensure that what3words widget is active and enabled
|
||||
var customer = await _workContext.GetCurrentCustomerAsync();
|
||||
await _logger.InformationAsync($"SignalR Widget called customer: {customer.Email}");
|
||||
var customer = await workContext.GetCurrentCustomerAsync();
|
||||
await logger.InformationAsync($"SignalR Widget called customer: {customer.Email}");
|
||||
|
||||
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
|
||||
if (!await widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
|
||||
return Content(string.Empty);
|
||||
|
||||
await _logger.InformationAsync("SignalR Widget: widget active");
|
||||
await logger.InformationAsync("SignalR Widget: widget active");
|
||||
|
||||
if (!widgetZone.Equals(PublicWidgetZones.BodyStartHtmlTagAfter))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Nop.Core.Configuration;
|
|||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||
using Nop.Services.Logging;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||
|
|
@ -16,9 +17,18 @@ public class AuctionDbTable: MgDbTableBase<Auction>
|
|||
{
|
||||
}
|
||||
|
||||
public Task<IList<Auction>> GetAllAuctionsAsync()
|
||||
public IQueryable<Auction> GetAllAuctions()
|
||||
{
|
||||
return GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default);
|
||||
return Table; //GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// x.StartDateUtc <= utcNow && x.EndDateUtc >= utcNow
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IQueryable<Auction> GetAllCurrentAutoOpenAndClosedAuctions()
|
||||
{
|
||||
var utcNow = DateTime.UtcNow;
|
||||
return Table.Where(x => x.AuctionType == AuctionType.AutomaticAll && x.Closed && x.StartDateUtc <= utcNow && x.EndDateUtc >= utcNow).OrderByDescending(x=>x.StartDateUtc);
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ using Nop.Core.Domain.Catalog;
|
|||
using Nop.Core.Domain.Customers;
|
||||
using Nop.Services.Catalog;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||
{
|
||||
|
|
@ -34,8 +35,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
if (httpContext == null) await logger.ErrorAsync($"AuctionHub.OnConnectedAsync(); (httpContext == null); connectionId: {connectionId}");
|
||||
else
|
||||
{
|
||||
if (sessionService.GetOrCreateSessionItem(httpContext.Session.Id) == null)
|
||||
await logger.ErrorAsync($"AuctionHub.OnConnectedAsync(); (sessionItem == null); connectionId: {connectionId}; sessionId: {httpContext.Session.Id}");
|
||||
var sessionItem = sessionService.GetOrCreateSessionItem(httpContext.Session.Id);
|
||||
|
||||
if (sessionItem == null) await logger.ErrorAsync($"AuctionHub.OnConnectedAsync(); (sessionItem == null); connectionId: {connectionId}; sessionId: {httpContext.Session.Id}");
|
||||
else sessionItem.SignaRConnectionId = connectionId;
|
||||
|
||||
var userName = httpContext.Request.Query["ConnectionId"];
|
||||
if (!string.IsNullOrEmpty(userName))
|
||||
|
|
@ -43,7 +46,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
await logger.InformationAsync($"AuctionHub.OnConnectedAsync(); Caller connected with name: {userName}; connectionId: {connectionId}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
|
|
@ -67,6 +70,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
var customer = await workContext.GetCurrentCustomerAsync();
|
||||
//var connectionId = sessionItem?.SessionId;
|
||||
|
||||
//ArgumentNullException.ThrowIfNull(messageWrapper?.Data);
|
||||
|
||||
if (messageWrapper?.Data == null)
|
||||
{
|
||||
logger.Error($"AuctionHub.HandleMessageAsync(); message?.Data == null; connectionId: {connectionId}", null, customer);
|
||||
|
|
|
|||
|
|
@ -396,10 +396,8 @@ public class AuctionService(
|
|||
await ctx.Auctions.UpdateAsync(auction);
|
||||
}
|
||||
|
||||
public async Task<IList<Auction>> GetAllAuctionsAsync()
|
||||
{
|
||||
return await ctx.Auctions.GetAllAuctionsAsync();
|
||||
}
|
||||
public Task<List<Auction>> GetAllAuctionsAsync() =>ctx.Auctions.GetAllAuctions().ToListAsync();
|
||||
public Task<List<Auction>> GetAllCurrentAutoOpenAndClosedAuctionsAsync() =>ctx.Auctions.GetAllCurrentAutoOpenAndClosedAuctions().ToListAsync();
|
||||
|
||||
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems)
|
||||
=> await ctx.ProductToAuctions.GetProductToAuctionsByAuctionId(auctionId, onlyActiveItems).OrderBy(x => x.SortIndex).ToListAsync();
|
||||
|
|
@ -535,5 +533,10 @@ public class AuctionService(
|
|||
await ctx.ProductToAuctions.UpdateAsync(productToAuctionMapping);
|
||||
}
|
||||
|
||||
public async Task UpdateProductToAuctionMappingAsync(IList<ProductToAuctionMapping> productToAuctionMappings)
|
||||
{
|
||||
await ctx.ProductToAuctions.UpdateAsync(productToAuctionMappings);
|
||||
}
|
||||
|
||||
#endregion Dtos
|
||||
}
|
||||
|
|
@ -41,7 +41,8 @@ public interface IAuctionService
|
|||
Task InsertAuctionAsync(Auction auction);
|
||||
Task UpdateAuctionAsync(Auction auction);
|
||||
|
||||
Task<IList<Auction>> GetAllAuctionsAsync();
|
||||
Task<List<Auction>> GetAllAuctionsAsync();
|
||||
Task<List<Auction>> GetAllCurrentAutoOpenAndClosedAuctionsAsync();
|
||||
|
||||
Task<AuctionDto> GetAuctionDtoWithAuctionBids(int auctionId, bool activeProductOnly, int maxBidsCount);
|
||||
Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems);
|
||||
|
|
@ -65,6 +66,7 @@ public interface IAuctionService
|
|||
Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly);
|
||||
Task<ProductToAuctionMapping> GetProductToAuctionMappingByIdAsync(int productToAuctionMappingId);
|
||||
Task UpdateProductToAuctionMappingAsync(ProductToAuctionMapping productToAuctionMapping);
|
||||
Task UpdateProductToAuctionMappingAsync(IList<ProductToAuctionMapping> productToAuctionMappings);
|
||||
|
||||
Task<Order> CreateOrderForWinnerAsync(ProductToAuctionMapping productToAuctionMapping);
|
||||
}
|
||||
Loading…
Reference in New Issue