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]
public async Task<IActionResult> SendBidNotificationViewModel(BidNotificationViewModel viewModel)
{
AuctionBid objOfAuctionBid = new AuctionBid();
objOfAuctionBid.ProductId = 4;
objOfAuctionBid.BidPrice = viewModel.BidPrice;
//AuctionBid objOfAuctionBid = new AuctionBid();
//objOfAuctionBid.ProductId = 4;
//objOfAuctionBid.BidPrice = viewModel.BidPrice;
objOfAuctionBid.Created = DateTime.UtcNow;
//objOfAuctionBid.Created = DateTime.UtcNow;
//await _announcementService.InsertAsync(objOfAuctionBid);

View File

@ -106,17 +106,7 @@ public class AuctionPluginAdminController : BasePluginController
[HttpPost]
public async Task<IActionResult> GetAuctionViewModel(AuctionViewModel viewModel)
{
Auction objOfAuctionDomain = new Auction();
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();
var objOfAuctionDomain = viewModel.AuctionDto.CreateMainEntity();
await _auctionService.InsertAuctionAsync(objOfAuctionDomain);
//if (viewModel.IsActive == true)

View File

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

View File

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

View File

@ -33,4 +33,15 @@ public class AuctionDbContext : MgDbContextBase, IAuctionDbSet<AuctionDbTable>,
// Auctions2 = _auctionRepository as EntityRepository<Auction>;
// 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;
}
//TODO: ezt kivegyem egyelőre? amíg a Product.Price-t használjuk, addig nem sok értelme
productToAuction.StartingPrice = basePrice;
productToAuction.CurrentPrice = basePrice;
productToAuction.WinnerCustomerId = 0;

View File

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

View File

@ -14,6 +14,7 @@ public class AuctionEventConsumer(IHttpContextAccessor httpContextAccessor, Auct
//TODO: itt lehetne ciklussal az összes ProductToAuction-re! - J.
var productToAuction = await ctx.ProductToAuctions.GetByProductId(eventMessage.Entity.Id).FirstOrDefaultAsync();
//foreach
if (productToAuction is { AuctionStatus: AuctionStatus.None })
{
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.Wrappers;
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
using Nop.Plugin.Misc.AuctionPlugin.Models;
using Nop.Plugin.Misc.AuctionPlugin.Services;
@ -9,27 +7,21 @@ using Nop.Services.Catalog;
using Nop.Services.Logging;
using Microsoft.AspNetCore.SignalR;
using Nop.Core;
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer.Interfaces;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
//- FirstWarning, SecondWarning,
//- ProductToAuctionDto ne lista legyen
//- GetFullAuctionDto
//- 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
//- Dollár currency
//- Pipa, ha tied a licit
//- Pause, Lezárás, Revert,
//- 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!
//- ha nincs login elszállhat a kliens
//- csak a watch-olt item-eknél legyen announcment
//- ha bid-elt 1x is, kerüljön a watch-ba
//- DbTransaction-t vhogy megcsinánli!
//- NextStepAmount
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})");
//TODO: if IsAdmin.. - J.
//productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
//productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
//TODO: if nincs aktív item.. - J.
var auction = await auctionService.GetAuctionDtoByProductToAuctionIdAsync(auctionProductStatusRequest.ProductToAuctionId, false);
@ -119,7 +114,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
switch (auctionProductStatusRequest.AuctionStatus)
{
case AuctionStatus.Pause:
//TODO: - J.
//TODO: Pause - J.
break;
case AuctionStatus.Sold:
@ -155,7 +150,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
SenderId = senderId,
Data = new ProductToAuctionStatusNotification(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true))
{
ToasterMessage = "string.Empty", //TODO: - J.
ToasterMessage = "EMPTY", //TODO: - J.
}.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}");
//CustomerService a = new CustomerService()a.IsGuestAsync()
//CustomerService a = new CustomerService()a.IsGuestAsync() //TODO: IsGuestAsync??? - J.
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)");
return;
@ -234,7 +230,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
var stepAmount = AuctionService.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
{
@ -246,7 +241,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
CurrentPrice = auctionBid.BidPrice,
NextStepAmount = stepAmount,
NextBidPrice = nextBidPrice,
ToasterMessage = string.Empty, //TODO: - J.
ToasterMessage = "EMPTY", //TODO: - J.
}.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.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.CurrentPrice)).AsInt32().NotNullable()

View File

@ -24,7 +24,7 @@ public class AuctionService : IAuctionService
/// <remarks>
/// {0} : current store ID
/// </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.";
#endregion
@ -78,7 +78,7 @@ public class AuctionService : IAuctionService
{
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
>= 100000 and < 200000 => 10000,
@ -284,7 +284,7 @@ public class AuctionService : IAuctionService
var productTouctionDto = await GetProductToAuctionDtoByIdAsync(productToAuctionId);
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);
return auctionDto;
@ -302,15 +302,12 @@ public class AuctionService : IAuctionService
return auctionBid == null ? null : new AuctionBidDto(auctionBid);
}
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
{
return [..await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync()];
}
public Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
=> _ctx.GetProductToAuctionsByProductIdAsync(productId);
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly)
{
return [..await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()];
}
public Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly)
=> _ctx.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productId, activeProductOnly);
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
{

View File

@ -15,17 +15,17 @@
<div>
<strong>Base Price:</strong>
<span class="value">
@String.Format("{0:c}", Model.BasePrice)
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
@($"{Model.BasePrice:c}")
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
</span>
</div>
<div>
<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>
<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 id="bidButton" class="btn btn-success">
@ -51,10 +51,10 @@
@{
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
</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
</button>
<button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
@ -148,7 +148,7 @@
document.getElementById("signalRCloseItemButton").disabled = true;
event.preventDefault();
handleAuctionStatusChange(AuctionStatus.SoldOut);
handleAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J.
return false;
});