improvements

This commit is contained in:
Loretta 2024-11-22 06:42:59 +01:00
parent d9f95dd8e1
commit f583cbe51f
5 changed files with 68 additions and 19 deletions

View File

@ -120,8 +120,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
{ {
//AuctionDto = TODO: ??? - J. //AuctionDto = TODO: ??? - J.
ProductName = viewModel.ProductName, ProductName = viewModel.ProductName,
BidPrice = viewModel.BidPrice.ToString(), BidPrice = viewModel.BidPrice,
NextStepAmount = viewModel.NextStepAmount.ToString() NextStepAmount = viewModel.NextStepAmount
}.ToJson() }.ToJson()
}; };
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented, var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,

View File

@ -12,8 +12,8 @@ public partial class Auction: MgEntityBase, IAuction
{ {
public string AuctionName { get; set; } public string AuctionName { get; set; }
[NotMapped] //[NotMapped]
[NotColumn] //[NotColumn]
public AuctionType AuctionType{ get; set; } public AuctionType AuctionType{ get; set; }
public DateTime StartDateUtc { get; set; } public DateTime StartDateUtc { get; set; }

View File

@ -14,8 +14,8 @@ public partial class ProductToAuctionMapping : MgEntityBase, IProductToAuctionMa
public int AuctionId { get; set; } public int AuctionId { get; set; }
public int WinnerCustomerId { get; set; } public int WinnerCustomerId { get; set; }
[NotMapped] //[NotMapped]
[NotColumn] //[NotColumn]
public AuctionStatus AuctionStatus { get; set; } public AuctionStatus AuctionStatus { get; set; }
public decimal StartingPrice { get; set; } public decimal StartingPrice { get; set; }

View File

@ -15,9 +15,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
public class BidNotificationMessage : AuctionNotificationBase public class BidNotificationMessage : AuctionNotificationBase
{ {
public string ProductName { get; set; } public string ProductName { get; set; }
public string BidPrice { get; set; } public decimal BidPrice { get; set; }
public string NextStepAmount { get; set; } public decimal NextBidPrice { get; set; }
public decimal NextStepAmount { get; set; }
public BidNotificationMessage() { } public BidNotificationMessage() { }
public BidNotificationMessage(AuctionDto auctionDto):base(auctionDto) { } public BidNotificationMessage(AuctionDto auctionDto):base(auctionDto) { }
} }

View File

@ -11,6 +11,9 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
//- FirstWarning, SecondWarning,
//- ProductToAuctionDto ne lista legyen
//- GetFullAuctionDto
//- SortIndex //- SortIndex
//- Rátettem egy unique-ot az AuctionId és a ProductId-ra!!! //- Rátettem egy unique-ot az AuctionId és a ProductId-ra!!!
//- Új field-ek a db-be! pl.: WinnerCustomerId, stb... //- Új field-ek a db-be! pl.: WinnerCustomerId, stb...
@ -76,7 +79,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
private async Task HandleProductToAuctionStatusChangedRequest(int senderId, AuctionProductStatusRequest auctionProductStatusRequest) private async Task HandleProductToAuctionStatusChangedRequest(int senderId, AuctionProductStatusRequest auctionProductStatusRequest)
{ {
if (auctionProductStatusRequest == null) if (auctionProductStatusRequest == null)
{ {
_logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); auctionProductStatusRequest == null"); _logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); auctionProductStatusRequest == null");
return; return;
@ -85,7 +88,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
try try
{ {
await _logger.InformationAsync($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); ProductToAuctionMappingId: {auctionProductStatusRequest.ProductToAuctionId}; Status: {auctionProductStatusRequest.AuctionStatus}({(int)auctionProductStatusRequest.AuctionStatus})"); await _logger.InformationAsync($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); ProductToAuctionMappingId: {auctionProductStatusRequest.ProductToAuctionId}; Status: {auctionProductStatusRequest.AuctionStatus}({(int)auctionProductStatusRequest.AuctionStatus})");
//TODO: if IsAdmin.. - J. //TODO: if IsAdmin.. - J.
//TODO: if nincs aktív item.. - J. //TODO: if nincs aktív item.. - J.
@ -128,17 +131,17 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
SenderId = senderId, SenderId = senderId,
Data = new ProductToAuctionStatusNotification(await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true)) Data = new ProductToAuctionStatusNotification(await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true))
{ {
ToasterMessage = string.Empty, //TODO: - J. ToasterMessage = "string.Empty", //TODO: - J.
}.ToJson() }.ToJson()
}; };
await _hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson()); await _hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson());
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); Error {ex.Message}"); _logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); Error {ex.Message}");
} }
} }
private async Task HandleBidRequest(int senderId, AuctionBidRequest bidRequestMessage) private async Task HandleBidRequest(int senderId, AuctionBidRequest bidRequestMessage)
@ -203,7 +206,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
activeProductAuction.BidPrice = product.Price; activeProductAuction.BidPrice = product.Price;
await _auctionService.UpdateProductToAuctionMappingAsync(activeProductAuction); await _auctionService.UpdateProductToAuctionMappingAsync(activeProductAuction);
// Optionally broadcast to all clients var stepAmount = GetStepAmount(auctionBid.BidPrice);
var nextBidPrice = auctionBid.BidPrice + stepAmount;
//stepAmount = GetStepAmount(nextBidPrice); //Direkt van 2x, különben a sávváltásoknál lehet gond! - J.
var bid = new MessageWrapper var bid = new MessageWrapper
{ {
MessageType = "bidNotification", MessageType = "bidNotification",
@ -211,9 +217,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
Data = new BidNotificationMessage(await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true)) Data = new BidNotificationMessage(await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true))
{ {
ProductName = auctionBid.ProductId.ToString(), ProductName = auctionBid.ProductId.ToString(),
BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture), BidPrice = auctionBid.BidPrice,
NextStepAmount = "50000", //TODO: - J. NextStepAmount = stepAmount,
NextBidPrice = nextBidPrice,
ToasterMessage = string.Empty, //TODO: - J. ToasterMessage = string.Empty, //TODO: - J.
}.ToJson() }.ToJson()
}; };
@ -225,5 +231,47 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
_logger.Error($"SignalRMessageHandler.HandleBidRequest(); MessageHandling error: {ex}"); _logger.Error($"SignalRMessageHandler.HandleBidRequest(); MessageHandling error: {ex}");
} }
} }
private static decimal GetStepAmount(decimal currentPrice)
{
return currentPrice switch
{
>= 0 and < 100000 => 1000, //Ezt csak hasraütésszerűen adtam meg!!! - J.
//100 000 - 1 000 000
>= 100000 and < 200000 => 10000,
>= 200000 and < 500000 => 20000,
>= 500000 and < 1000000 => 50000,
//1 000 000 - 10 000 000
>= 1000000 and < 2000000 => 100000,
>= 2000000 and < 5000000 => 200000,
>= 5000000 and < 10000000 => 500000,
//10 000 000 - 100 000 000
>= 10000000 and < 20000000 => 1000000,
>= 20000000 and < 50000000 => 2000000,
>= 50000000 and < 100000000 => 5000000,
//100 000 000 - ~
>= 100000000 and < 200000000 => 10000000,
_ => 20000000
};
//100 000 Ft 200 000 Ft között 10 000 Ft-tal
//200 000 Ft 500 000 Ft között 20 000 Ft-tal
//500 000 Ft 1 000 000 Ft között 50 000 Ft-tal
//1 000 000 Ft 2 000 000 Ft között 100 000 Ft-tal
//2 000 000 Ft 5 000 000 Ft között 200 000 Ft-tal
//5 000 000 Ft 10 000 000 Ft között 500 000 Ft-tal
//10 000 000 Ft 20 000 000 Ft között 1 000 000 Ft-tal
//20 000 000 Ft 50 000 000 Ft között 2 000 000 Ft-tal
//50 000 000 Ft 100 000 000 Ft között 5 000 000 Ft-tal
//100 000 000 Ft 200 000 000 Ft között 10 000 000 Ft-tal
//200 000 000 Ft fölött 20 000 000 Ft-tal
}
} }
} }