This commit is contained in:
Loretta 2024-11-24 19:18:51 +01:00
parent 52a1768480
commit f1e022523e
12 changed files with 61 additions and 69 deletions

View File

@ -105,11 +105,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
[HttpPost] [HttpPost]
public async Task<IActionResult> SendBidNotificationViewModel(BidNotificationViewModel viewModel) public async Task<IActionResult> SendBidNotificationViewModel(BidNotificationViewModel viewModel)
{ {
AuctionBid objOfAuctionBid = new AuctionBid(); //AuctionBid objOfAuctionBid = new AuctionBid();
objOfAuctionBid.ProductId = 4; //objOfAuctionBid.ProductId = 4;
objOfAuctionBid.BidPrice = viewModel.BidPrice; //objOfAuctionBid.BidPrice = viewModel.BidPrice;
objOfAuctionBid.Created = DateTime.UtcNow; //objOfAuctionBid.Created = DateTime.UtcNow;
//await _announcementService.InsertAsync(objOfAuctionBid); //await _announcementService.InsertAsync(objOfAuctionBid);

View File

@ -106,17 +106,7 @@ public class AuctionPluginAdminController : BasePluginController
[HttpPost] [HttpPost]
public async Task<IActionResult> GetAuctionViewModel(AuctionViewModel viewModel) public async Task<IActionResult> GetAuctionViewModel(AuctionViewModel viewModel)
{ {
Auction objOfAuctionDomain = new Auction(); var objOfAuctionDomain = viewModel.AuctionDto.CreateMainEntity();
objOfAuctionDomain.AuctionName = viewModel.AuctionName;
objOfAuctionDomain.AuctionType = viewModel.AuctionType;
objOfAuctionDomain.StartDateUtc = viewModel.StartDateUtc;
objOfAuctionDomain.EndDateUtc = viewModel.EndDateUtc;
objOfAuctionDomain.Closed = viewModel.Closed;
objOfAuctionDomain.Created = DateTime.UtcNow;
//TODO: ezt kell majd használni! - J.
//var objOfAuctionDomain = viewModel.AuctionDto.CreateMainEntity();
await _auctionService.InsertAuctionAsync(objOfAuctionDomain); await _auctionService.InsertAuctionAsync(objOfAuctionDomain);
//if (viewModel.IsActive == true) //if (viewModel.IsActive == true)

View File

@ -7,22 +7,23 @@
Active: 1, Active: 1,
FirstWarning: 2, FirstWarning: 2,
SecondWarning: 4, SecondWarning: 4,
Sold: 8, Pause: 8,
NotSold: 16 Sold: 16,
NotSold: 32
}); });
// HUF Formatter // HUF Formatter
window.HUFFormatter = new Intl.NumberFormat('hu-HU', { window.HUFFormatter = new Intl.NumberFormat("hu-HU", {
style: 'currency', style: "currency",
currency: 'HUF', currency: "HUF",
}); });
// SignalR connection setup // SignalR connection setup
var connection = new signalR.HubConnectionBuilder() var connection = new signalR.HubConnectionBuilder()
.withUrl('/auctionhub') .withUrl("/auctionhub")
.build(); .build();
connection.on('send', data => { connection.on("send", data => {
MessageHandler.handle(data); MessageHandler.handle(data);
}); });

View File

@ -94,8 +94,6 @@ public class AuctionController : BasePluginController
if (isAnyItemLive) if (isAnyItemLive)
{ {
activeMapping = auctionDto.ProductToAuctionDtos.Where(x => x.AuctionStatus == AuctionStatus.Active).FirstOrDefault();
product = await _productService.GetProductByIdAsync(activeMapping.ProductId); product = await _productService.GetProductByIdAsync(activeMapping.ProductId);
activeProductId = activeMapping.ProductId; activeProductId = activeMapping.ProductId;
activeProductToAuctionId = activeMapping.Id; activeProductToAuctionId = activeMapping.Id;
@ -103,9 +101,7 @@ public class AuctionController : BasePluginController
basePrice = activeMapping.StartingPrice; basePrice = activeMapping.StartingPrice;
currentPrice = activeMapping.CurrentPrice; currentPrice = activeMapping.CurrentPrice;
nextStep = AuctionService.GetStepAmount(currentPrice); nextStep = AuctionService.GetStepAmount(currentPrice);
} }
else else
{ {
activeMapping = null; activeMapping = null;

View File

@ -33,4 +33,15 @@ public class AuctionDbContext : MgDbContextBase, IAuctionDbSet<AuctionDbTable>,
// Auctions2 = _auctionRepository as EntityRepository<Auction>; // Auctions2 = _auctionRepository as EntityRepository<Auction>;
// AuctionBids2 = _auctionBidRepository; // AuctionBids2 = _auctionBidRepository;
//} //}
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
{
return [..await ProductToAuctions.GetByProductId(productId).ToListAsync()];
}
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly)
{
return [..await ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()];
}
} }

View File

@ -54,6 +54,7 @@ public class ProductToAuctionDbTable : MgDbTableBase<ProductToAuctionMapping>
return; return;
} }
//TODO: ezt kivegyem egyelőre? amíg a Product.Price-t használjuk, addig nem sok értelme
productToAuction.StartingPrice = basePrice; productToAuction.StartingPrice = basePrice;
productToAuction.CurrentPrice = basePrice; productToAuction.CurrentPrice = basePrice;
productToAuction.WinnerCustomerId = 0; productToAuction.WinnerCustomerId = 0;

View File

@ -17,7 +17,7 @@ public enum AuctionStatus : byte
Active = 1, Active = 1,
FirstWarning = 2, FirstWarning = 2,
SecondWarning = 4, SecondWarning = 4,
Sold = 8, Pause = 8,
NotSold = 16, Sold = 16,
Pause = 32 NotSold = 32,
} }

View File

@ -14,6 +14,7 @@ public class AuctionEventConsumer(IHttpContextAccessor httpContextAccessor, Auct
//TODO: itt lehetne ciklussal az összes ProductToAuction-re! - J. //TODO: itt lehetne ciklussal az összes ProductToAuction-re! - J.
var productToAuction = await ctx.ProductToAuctions.GetByProductId(eventMessage.Entity.Id).FirstOrDefaultAsync(); var productToAuction = await ctx.ProductToAuctions.GetByProductId(eventMessage.Entity.Id).FirstOrDefaultAsync();
//foreach
if (productToAuction is { AuctionStatus: AuctionStatus.None }) if (productToAuction is { AuctionStatus: AuctionStatus.None })
{ {
await ctx.ProductToAuctions.DeactivateItem(productToAuction, eventMessage.Entity.Price); await ctx.ProductToAuctions.DeactivateItem(productToAuction, eventMessage.Entity.Price);

View File

@ -1,7 +1,5 @@
using System.Globalization; using AyCode.Core.Extensions;
using AyCode.Core.Extensions;
using AyCode.Utils.Extensions; using AyCode.Utils.Extensions;
using AyCode.Utils.Wrappers;
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages; using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Models;
using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Plugin.Misc.AuctionPlugin.Services;
@ -9,27 +7,21 @@ using Nop.Services.Catalog;
using Nop.Services.Logging; using Nop.Services.Logging;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Nop.Core; using Nop.Core;
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer.Interfaces;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
//- FirstWarning, SecondWarning, //- Dollár currency
//- ProductToAuctionDto ne lista legyen //- Pipa, ha tied a licit
//- GetFullAuctionDto //- Pause, Lezárás, Revert,
//- SortIndex
//- Rátettem egy unique-ot az AuctionId és a ProductId-ra!!!
//- Új field-ek a db-be! pl.: WinnerCustomerId, stb...
//- IsActiveItem
//- Product onupdate
//- lock
//- ha saját licit a legjobb vagy lezárt, ne lehessen bid-elni //- ha saját licit a legjobb vagy lezárt, ne lehessen bid-elni
//- az előző esetben a kliensen a gombot is tiltani, már a.cshtml-ben ellenőrizni! //- az előző esetben a kliensen a gombot is tiltani, már a.cshtml-ben ellenőrizni!
//- ha nincs login elszállhat a kliens
//- csak a watch-olt item-eknél legyen announcment //- csak a watch-olt item-eknél legyen announcment
//- ha bid-elt 1x is, kerüljön a watch-ba //- ha bid-elt 1x is, kerüljön a watch-ba
//- DbTransaction-t vhogy megcsinánli! //- DbTransaction-t vhogy megcsinánli!
//- NextStepAmount
public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext) public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext)
{ {
@ -91,6 +83,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
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.
//productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
//productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
//TODO: if nincs aktív item.. - J. //TODO: if nincs aktív item.. - J.
var auction = await auctionService.GetAuctionDtoByProductToAuctionIdAsync(auctionProductStatusRequest.ProductToAuctionId, false); var auction = await auctionService.GetAuctionDtoByProductToAuctionIdAsync(auctionProductStatusRequest.ProductToAuctionId, false);
@ -119,7 +114,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
switch (auctionProductStatusRequest.AuctionStatus) switch (auctionProductStatusRequest.AuctionStatus)
{ {
case AuctionStatus.Pause: case AuctionStatus.Pause:
//TODO: - J. //TODO: Pause - J.
break; break;
case AuctionStatus.Sold: case AuctionStatus.Sold:
@ -155,7 +150,7 @@ 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 = "EMPTY", //TODO: - J.
}.ToJson() }.ToJson()
}; };
@ -180,9 +175,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
await logger.InformationAsync($"SignalRMessageHandler.HandleBidRequest(); Bid received; Auction: {bidRequestMessage.AuctionId}; Product: {bidRequestMessage.ProductId}; Bid: {bidRequestMessage.BidPrice}; Customer: {bidRequestMessage.CustomerId}"); await logger.InformationAsync($"SignalRMessageHandler.HandleBidRequest(); Bid received; Auction: {bidRequestMessage.AuctionId}; Product: {bidRequestMessage.ProductId}; Bid: {bidRequestMessage.BidPrice}; Customer: {bidRequestMessage.CustomerId}");
//CustomerService a = new CustomerService()a.IsGuestAsync() //CustomerService a = new CustomerService()a.IsGuestAsync() //TODO: IsGuestAsync??? - J.
var customer = await workContext.GetCurrentCustomerAsync(); var customer = await workContext.GetCurrentCustomerAsync();
if (customer == null || bidRequestMessage.CustomerId != customer.Id) //|| !customer.Active) //TODO: ??? - J. if (customer == null || bidRequestMessage.CustomerId != customer.Id) //|| !customer.Active)
{ {
logger.Error($"SignalRMessageHandler.HandleBidRequest(); (customer == null || bidRequestMessage.CustomerId != customer.Id)"); logger.Error($"SignalRMessageHandler.HandleBidRequest(); (customer == null || bidRequestMessage.CustomerId != customer.Id)");
return; return;
@ -234,7 +230,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
var stepAmount = AuctionService.GetStepAmount(auctionBid.BidPrice); var stepAmount = AuctionService.GetStepAmount(auctionBid.BidPrice);
var nextBidPrice = auctionBid.BidPrice + stepAmount; 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
{ {
@ -246,7 +241,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
CurrentPrice = auctionBid.BidPrice, CurrentPrice = auctionBid.BidPrice,
NextStepAmount = stepAmount, NextStepAmount = stepAmount,
NextBidPrice = nextBidPrice, NextBidPrice = nextBidPrice,
ToasterMessage = string.Empty, //TODO: - J. ToasterMessage = "EMPTY", //TODO: - J.
}.ToJson() }.ToJson()
}; };

View File

@ -25,7 +25,7 @@ public class ProductToAuctionMappingBuilder : NopEntityBuilder<ProductToAuctionM
.WithColumn(nameof(ProductToAuctionMapping.AuctionId)).AsInt32().ForeignKey<Auction>(onDelete: Rule.Cascade) //Rule.Cascade?? .WithColumn(nameof(ProductToAuctionMapping.AuctionId)).AsInt32().ForeignKey<Auction>(onDelete: Rule.Cascade) //Rule.Cascade??
.WithColumn(nameof(ProductToAuctionMapping.ProductId)).AsInt32().ForeignKey<Product>(onDelete: Rule.Cascade) //Rule.Cascade?? .WithColumn(nameof(ProductToAuctionMapping.ProductId)).AsInt32().ForeignKey<Product>(onDelete: Rule.Cascade) //Rule.Cascade??
.WithColumn(nameof(ProductToAuctionMapping.AuctionStatus)).AsByte().NotNullable() //enum??? - J. .WithColumn(nameof(ProductToAuctionMapping.AuctionStatus)).AsByte().NotNullable()
.WithColumn(nameof(ProductToAuctionMapping.StartingPrice)).AsInt32().NotNullable() .WithColumn(nameof(ProductToAuctionMapping.StartingPrice)).AsInt32().NotNullable()
.WithColumn(nameof(ProductToAuctionMapping.CurrentPrice)).AsInt32().NotNullable() .WithColumn(nameof(ProductToAuctionMapping.CurrentPrice)).AsInt32().NotNullable()

View File

@ -24,7 +24,7 @@ public class AuctionService : IAuctionService
/// <remarks> /// <remarks>
/// {0} : current store ID /// {0} : current store ID
/// </remarks> /// </remarks>
private readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY); //nem ezt használjuk a kódban, nem gond?! - J. private readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY);
private const string AUCTION_PATTERN_KEY = "Nop.auction."; private const string AUCTION_PATTERN_KEY = "Nop.auction.";
#endregion #endregion
@ -78,7 +78,7 @@ public class AuctionService : IAuctionService
{ {
return currentPrice switch return currentPrice switch
{ {
>= 0 and < 100000 => 10000, //Ezt csak hasraütésszerűen adtam meg!!! - J. >= 0 and < 100000 => 10000,
//100 000 - 1 000 000 //100 000 - 1 000 000
>= 100000 and < 200000 => 10000, >= 100000 and < 200000 => 10000,
@ -284,7 +284,7 @@ public class AuctionService : IAuctionService
var productTouctionDto = await GetProductToAuctionDtoByIdAsync(productToAuctionId); var productTouctionDto = await GetProductToAuctionDtoByIdAsync(productToAuctionId);
if (productTouctionDto == null) return null; if (productTouctionDto == null) return null;
var auctionDto = await GetAuctionDtoByIdAsync(productTouctionDto.AuctionId, false, false); //Ez sosem lehet null! - J. var auctionDto = await GetAuctionDtoByIdAsync(productTouctionDto.AuctionId, false, false);
if (includeProductToAuctionDto) auctionDto.ProductToAuctionDtos.Add(productTouctionDto); if (includeProductToAuctionDto) auctionDto.ProductToAuctionDtos.Add(productTouctionDto);
return auctionDto; return auctionDto;
@ -302,15 +302,12 @@ public class AuctionService : IAuctionService
return auctionBid == null ? null : new AuctionBidDto(auctionBid); return auctionBid == null ? null : new AuctionBidDto(auctionBid);
} }
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId) public Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
{ => _ctx.GetProductToAuctionsByProductIdAsync(productId);
return [..await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync()];
}
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly) public Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly)
{ => _ctx.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productId, activeProductOnly);
return [..await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()];
}
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId) public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
{ {

View File

@ -15,17 +15,17 @@
<div> <div>
<strong>Base Price:</strong> <strong>Base Price:</strong>
<span class="value"> <span class="value">
@String.Format("{0:c}", Model.BasePrice) @($"{Model.BasePrice:c}")
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@ @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
</span> </span>
</div> </div>
<div> <div>
<strong>Bid Step:</strong> <strong>Bid Step:</strong>
<span id="licitStepText" class="value">@String.Format("{0:c}", Model.LicitStep)</span> <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
</div> </div>
<div> <div>
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)"> <button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)">
Bid @String.Format("{0:c}", Model.NextBidPrice) Bid @($"{Model.NextBidPrice:c}")
</button> </button>
@* <button id="bidButton" class="btn btn-success"> @* <button id="bidButton" class="btn btn-success">
@ -51,10 +51,10 @@
@{ @{
if(Model.IsItemActive) if(Model.IsItemActive)
{ {
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" disabled="@((byte)Model.AuctionStatus >= (byte)AuctionStatus.FirstWarning))"> <button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus >= AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
First warning First warning
</button> </button>
<button id="signalRSecondWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" disabled="@((byte)Model.AuctionStatus >= (byte)AuctionStatus.SecondWarning))"> <button id="signalRSecondWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
Second warning Second warning
</button> </button>
<button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button"> <button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
@ -148,7 +148,7 @@
document.getElementById("signalRCloseItemButton").disabled = true; document.getElementById("signalRCloseItemButton").disabled = true;
event.preventDefault(); event.preventDefault();
handleAuctionStatusChange(AuctionStatus.SoldOut); handleAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J.
return false; return false;
}); });