|
|
|
|
@ -26,7 +26,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
|
|
|
//- ha bid-elt 1x is, kerüljön a watch-ba
|
|
|
|
|
//- DbTransaction-t vhogy megcsinánli!
|
|
|
|
|
|
|
|
|
|
public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext, ICustomerService customerService)
|
|
|
|
|
public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext, ICustomerService customerService, ICategoryService categoryService)
|
|
|
|
|
{
|
|
|
|
|
private readonly Mutex _handleMessageMutex = new();
|
|
|
|
|
|
|
|
|
|
@ -132,13 +132,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
|
|
|
{
|
|
|
|
|
await logger.InformationAsync($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); ProductToAuctionMappingId: {auctionProductStatusRequest.ProductToAuctionId}; Status: {auctionProductStatusRequest.AuctionStatus}({(int)auctionProductStatusRequest.AuctionStatus})", null, customer);
|
|
|
|
|
|
|
|
|
|
var auction = await auctionService.GetAuctionDtoByProductToAuctionIdAsync(auctionProductStatusRequest.ProductToAuctionId, false);
|
|
|
|
|
if (auction == null || auction.Closed)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (auction == null || auction.Closed); Closed: {auction?.Closed}", null, customer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var productToAuction = await auctionService.GetProductToAuctionMappingByIdAsync(auctionProductStatusRequest.ProductToAuctionId);
|
|
|
|
|
if (productToAuction == null)
|
|
|
|
|
{
|
|
|
|
|
@ -146,13 +139,20 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var auction = await auctionService.GetAuctionByIdAsync(productToAuction.AuctionId);
|
|
|
|
|
if (auction == null || auction.Closed)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (auction == null || auction.Closed); Closed: {auction?.Closed}", null, customer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IsValidRequestAuctionStatus(auctionProductStatusRequest.AuctionStatus, productToAuction.AuctionStatus))
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); RequestAuctionStatusIsValid() == false; newStatus: {auctionProductStatusRequest.AuctionStatus}; oldStatus: {productToAuction.AuctionStatus}", null, customer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (auctionProductStatusRequest.AuctionStatus == AuctionStatus.None) await ResetProductToAuction(productToAuction);
|
|
|
|
|
if (auctionProductStatusRequest.AuctionStatus == AuctionStatus.None) await ResetProductToAuction(productToAuction, auction.CategoryId);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (auctionProductStatusRequest.AuctionStatus)
|
|
|
|
|
@ -207,8 +207,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
|
|
|
SenderId = customer.Id,
|
|
|
|
|
Data = new ProductToAuctionStatusNotification(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true), bidsCount, "EMPTY").ToJson()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson());
|
|
|
|
|
|
|
|
|
|
var isFeaturedProduct = productToAuction.IsActiveItem || productToAuction.AuctionStatus == AuctionStatus.Pause;
|
|
|
|
|
await UpdateProductCategoryIsFeaturedAsync(isFeaturedProduct, auction.CategoryId, productToAuction.ProductId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
@ -245,7 +248,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
|
|
|
var product = await auctionService.GetProductById(bidRequestMessage.ProductId);
|
|
|
|
|
if (product == null) return;
|
|
|
|
|
|
|
|
|
|
if (IsValidBidPrice(product.Price, activeProductAuction.CurrentPrice, bidRequestMessage.BidPrice, customer)) return;
|
|
|
|
|
if (!IsValidBidPrice(product.Price, activeProductAuction.CurrentPrice, bidRequestMessage.BidPrice, customer)) return;
|
|
|
|
|
|
|
|
|
|
var auctionBid = bidRequestMessage.CreateMainEntity();
|
|
|
|
|
auctionBid.ProductAuctionMappingId = activeProductAuction.Id;
|
|
|
|
|
@ -307,10 +310,34 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
|
|
|
await hubContext.Clients.All.SendAsync("send", bidMessage.ToJson());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task ResetProductToAuction(ProductToAuctionMapping productToAuction)
|
|
|
|
|
private async Task ResetProductToAuction(ProductToAuctionMapping productToAuction, int? categoryId = null)
|
|
|
|
|
{
|
|
|
|
|
productToAuction.AuctionStatus = AuctionStatus.None;
|
|
|
|
|
return auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice);
|
|
|
|
|
await auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice);
|
|
|
|
|
|
|
|
|
|
categoryId ??= (await auctionService.GetAuctionByIdAsync(productToAuction.AuctionId))?.CategoryId;
|
|
|
|
|
await UpdateProductCategoryIsFeaturedAsync(false, categoryId, productToAuction.ProductId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task UpdateProductCategoryIsFeaturedAsync(bool isFeatured, int? categoryId, int productId)
|
|
|
|
|
{
|
|
|
|
|
//Leszarjuk ha elszáll, az aukció menjen tovább... - J.
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (categoryId.GetValueOrDefault(0) == 0) return;
|
|
|
|
|
|
|
|
|
|
var productCategory = (await categoryService.GetProductCategoriesByProductIdAsync(productId)).FirstOrDefault(x => x.CategoryId == categoryId);
|
|
|
|
|
if (productCategory == null) return;
|
|
|
|
|
|
|
|
|
|
if (productCategory.IsFeaturedProduct == isFeatured) return;
|
|
|
|
|
|
|
|
|
|
productCategory.IsFeaturedProduct = isFeatured;
|
|
|
|
|
await categoryService.UpdateProductCategoryAsync(productCategory);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"SignalRMessageHandler.UpdateProductCategoryIsFeaturedAsync(); categoryId: {categoryId}; productId: {productId}; isFeatured: {isFeatured}", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsValidBidPrice(decimal productPrice, decimal productToAuctionCurrentPrice, decimal bidRequestPrice, Customer customer = null)
|
|
|
|
|
@ -318,10 +345,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|
|
|
|
if (productPrice >= bidRequestPrice || productToAuctionCurrentPrice >= bidRequestPrice || bidRequestPrice != GetNextBidPrice(productToAuctionCurrentPrice))
|
|
|
|
|
{
|
|
|
|
|
logger.Warning($"SignalRMessageHandler.IsValidBidPrice(); (productPrice >= bidRequestPrice || productToAuctionCurrentPrice >= bidRequestPrice || bidRequestPrice != GetNextBidPrice(productToAuctionCurrentPrice)); productPrice: {productPrice}; productToAuctionCurrentPrice: {productToAuctionCurrentPrice}; bidRequestPrice: {bidRequestPrice}", null, customer);
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static decimal GetStepAmount(decimal currentBidPrice) => AuctionService.GetStepAmount(currentBidPrice);
|
|
|
|
|
|