improvements, fixes, etc..

This commit is contained in:
Loretta 2024-11-30 15:44:20 +01:00
parent dbb70fd201
commit 0b94fed2a7
1 changed files with 37 additions and 36 deletions

View File

@ -157,44 +157,43 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
switch (auctionProductStatusRequest.AuctionStatus) switch (auctionProductStatusRequest.AuctionStatus)
{ {
case AuctionStatus.None: case AuctionStatus.Active:
return; //ez sosem futhat le a fenti if miatt... - J. productToAuction.AuctionStatus = AuctionStatus.Active;
await UpdateProductCategoryIsFeaturedAsync(productToAuction.ProductId, auction.CategoryId, true);
break;
case AuctionStatus.FirstWarning:
case AuctionStatus.SecondWarning:
productToAuction.AuctionStatus = auctionProductStatusRequest.AuctionStatus;
break;
case AuctionStatus.Sold:
var lastAuctionBid = await auctionService.GetLastAuctionBidByProductToAuctionIdAsync(productToAuction.Id);
if (lastAuctionBid == null) productToAuction.AuctionStatus = AuctionStatus.NotSold;
else
{
productToAuction.AuctionStatus = AuctionStatus.Sold;
productToAuction.CurrentPrice = lastAuctionBid.BidPrice;
productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId;
var placeOrderResult = await auctionService.CreateOrderForWinnerAsync(productToAuction);
if (placeOrderResult == null || placeOrderResult.Id == 0)
{
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (placeOrderResult == null || placeOrderResult.Id == 0)", null, customer);
//return; //TODO: EGYELŐRE HAGYJUK LEZÁRNI AKKOR IS, HA NEM SIKERÜLT AZ ORDERPLACE()! - J.
}
}
await UpdateProductCategoryIsFeaturedAsync(productToAuction.ProductId, auction.CategoryId, false);
break;
case AuctionStatus.Pause: case AuctionStatus.Pause:
productToAuction.AuctionStatus = AuctionStatus.Pause; productToAuction.AuctionStatus = AuctionStatus.Pause;
break; break;
case AuctionStatus.Sold:
var lastAuctionBid = await auctionService.GetLastAuctionBidByProductToAuctionIdAsync(productToAuction.Id);
if (lastAuctionBid == null)
{
productToAuction.AuctionStatus = AuctionStatus.NotSold;
break;
}
productToAuction.AuctionStatus = AuctionStatus.Sold;
productToAuction.CurrentPrice = lastAuctionBid.BidPrice;
productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId;
var placeOrderResult = await auctionService.CreateOrderForWinnerAsync(productToAuction);
if (placeOrderResult == null || placeOrderResult.Id == 0)
{
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (placeOrderResult == null || placeOrderResult.Id == 0)", null, customer);
//return; //TODO: EGYELŐRE HAGYJUK LEZÁRNI AKKOR IS, HA NEM SIKERÜLT AZ ORDERPLACE()! - J.
}
break;
case AuctionStatus.NotSold:
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (auctionProductStatusRequest.AuctionStatus == AuctionStatus.NotSold)", null, customer);
break;
case AuctionStatus.FirstWarning:
case AuctionStatus.SecondWarning:
case AuctionStatus.Active:
default: default:
productToAuction.AuctionStatus = auctionProductStatusRequest.AuctionStatus; logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); AuctionStatus not found; (auctionProductStatusRequest.AuctionStatus == {auctionProductStatusRequest.AuctionStatus})", null, customer);
break; return;
} }
await auctionService.UpdateProductToAuctionMappingAsync(productToAuction); await auctionService.UpdateProductToAuctionMappingAsync(productToAuction);
@ -210,8 +209,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
await hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson()); await hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson());
var isFeaturedProduct = productToAuction.IsActiveItem || productToAuction.AuctionStatus == AuctionStatus.Pause; //if (productToAuction.AuctionStatus is AuctionStatus.FirstWarning or AuctionStatus.SecondWarning or AuctionStatus.Pause) return;
await UpdateProductCategoryIsFeaturedAsync(isFeaturedProduct, auction.CategoryId, productToAuction.ProductId);
//var isFeaturedProduct = productToAuction.IsActiveItem || productToAuction.AuctionStatus == AuctionStatus.Pause;
//await UpdateProductCategoryIsFeaturedAsync(isFeaturedProduct, auction.CategoryId, productToAuction.ProductId);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -316,10 +317,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
await auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice); await auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice);
categoryId ??= (await auctionService.GetAuctionByIdAsync(productToAuction.AuctionId))?.CategoryId; categoryId ??= (await auctionService.GetAuctionByIdAsync(productToAuction.AuctionId))?.CategoryId;
await UpdateProductCategoryIsFeaturedAsync(false, categoryId, productToAuction.ProductId); await UpdateProductCategoryIsFeaturedAsync(productToAuction.ProductId, categoryId, false);
} }
private async Task UpdateProductCategoryIsFeaturedAsync(bool isFeatured, int? categoryId, int productId) private async Task UpdateProductCategoryIsFeaturedAsync(int productId, int? categoryId, bool isFeatured)
{ {
//Leszarjuk ha elszáll, az aukció menjen tovább... - J. //Leszarjuk ha elszáll, az aukció menjen tovább... - J.
try try