This commit is contained in:
Loretta 2024-11-28 06:49:02 +01:00
parent b28443c6c4
commit d9146a2a62
6 changed files with 51 additions and 69 deletions

View File

@ -1,7 +1,7 @@
var MessageHandler = (function () { var MessageHandler = (function () {
// Handlers for each message type // Handlers for each message type
let animation = "slideDown"; var animation = "slideDown";
const handlers = { var handlers = {
announcement: function (data) { announcement: function (data) {
var myObject = JSON.parse(data); var myObject = JSON.parse(data);

View File

@ -1,37 +1,18 @@
using AyCode.Core.Extensions; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Catalog;
using Nop.Data;
using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Models;
using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Catalog; using Nop.Services.Catalog;
using Nop.Services.Logging; using Nop.Services.Logging;
using Nop.Web.Areas.Admin.Factories;
using Nop.Web.Framework.Controllers; using Nop.Web.Framework.Controllers;
using Nop.Web.Models.Catalog; using Nop.Web.Models.Catalog;
namespace Nop.Plugin.Misc.AuctionPlugin.Controllers; namespace Nop.Plugin.Misc.AuctionPlugin.Controllers;
public class AuctionController : BasePluginController public class AuctionController(AuctionService auctionService, ILogger logger, IProductService productService, MyProductModelFactory productModelFactory)
: BasePluginController
{ {
protected readonly AuctionService _auctionService;
protected readonly ILogger _logger;
protected readonly IProductService _productService;
protected readonly MyProductModelFactory _productModelFactory;
public AuctionController(AuctionService auctionService, ILogger logger, IProductService productService, MyProductModelFactory productModelFactory)
{
_auctionService = auctionService;
_logger = logger;
_productService = productService;
_productModelFactory = productModelFactory;
}
// GET // GET
public IActionResult Index() public IActionResult Index()
{ {
@ -43,7 +24,7 @@ public class AuctionController : BasePluginController
public async Task<IActionResult> PlaceBid([FromBody] AuctionBid model) public async Task<IActionResult> PlaceBid([FromBody] AuctionBid model)
{ {
await _logger.InformationAsync("PlaceBid called"); await logger.InformationAsync("PlaceBid called");
//if (model.BidPrice < CurrentPrice + LicitStep) //if (model.BidPrice < CurrentPrice + LicitStep)
//{ //{
@ -51,8 +32,8 @@ public class AuctionController : BasePluginController
//} //}
// kéne valami visszajelzés // kéne valami visszajelzés
await _auctionService.InsertBidAsync(model); await auctionService.InsertBidAsync(model);
bool bidSuccess = true; var bidSuccess = true;
if (bidSuccess) if (bidSuccess)
{ {
return Ok(new { message = "Your bid was successfully placed!" }); return Ok(new { message = "Your bid was successfully placed!" });
@ -66,17 +47,17 @@ public class AuctionController : BasePluginController
[HttpPost] [HttpPost]
public async Task<IActionResult> RefreshAuctionWidget([FromBody] RefreshWidgetRequest request) public async Task<IActionResult> RefreshAuctionWidget([FromBody] RefreshWidgetRequest request)
{ {
await _logger.InformationAsync($"Refresh auction widget called from {request.WidgetZone} with data of {request.ProductId}"); await logger.InformationAsync($"Refresh auction widget called from {request.WidgetZone} with data of {request.ProductId}");
var product = await _productService.GetProductByIdAsync(request.ProductId); var product = await productService.GetProductByIdAsync(request.ProductId);
ProductDetailsModel detailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product); var detailsModel = await productModelFactory.PrepareProductDetailsModelAsync(product);
return ViewComponent("AuctionPublic", new { widgetZone = request.WidgetZone, additionalData = detailsModel }); return ViewComponent("AuctionPublic", new { widgetZone = request.WidgetZone, additionalData = detailsModel });
} }
public async Task<IActionResult> LiveScreen(int auctionId) public async Task<IActionResult> LiveScreen(int auctionId)
{ {
var auctionDto = await _auctionService.GetAuctionDtoWithAuctionBids(auctionId, true, 5); var auctionDto = await auctionService.GetAuctionDtoWithAuctionBids(auctionId, true, 5); //A javascript-ben az első 6-ot vágod le, melyik a valid? - J.
var activeMapping = auctionDto?.ProductToAuctionDtos.MinBy(x => x.SortIndex); var activeMapping = auctionDto?.ProductToAuctionDtos.MinBy(x => x.SortIndex);
var isAnyItemLive = activeMapping != null; var isAnyItemLive = activeMapping != null;
if (auctionDto == null) if (auctionDto == null)
@ -88,18 +69,18 @@ public class AuctionController : BasePluginController
Product product; Product product;
ProductDetailsModel productDetailsModel; ProductDetailsModel productDetailsModel;
int activeProductId = 0; int activeProductId;
int activeProductToAuctionId = 0; int activeProductToAuctionId;
decimal basePrice = 0; decimal basePrice = 0;
decimal currentPrice = 0; decimal currentPrice = 0;
decimal nextStep = 0; decimal nextStep = 0;
if (isAnyItemLive) if (isAnyItemLive)
{ {
product = await _productService.GetProductByIdAsync(activeMapping.ProductId); product = await productService.GetProductByIdAsync(activeMapping.ProductId);
activeProductId = activeMapping.ProductId; activeProductId = activeMapping.ProductId;
activeProductToAuctionId = activeMapping.Id; activeProductToAuctionId = activeMapping.Id;
productDetailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product); productDetailsModel = await productModelFactory.PrepareProductDetailsModelAsync(product);
basePrice = activeMapping.StartingPrice; basePrice = activeMapping.StartingPrice;
currentPrice = activeMapping.CurrentPrice; currentPrice = activeMapping.CurrentPrice;
nextStep = AuctionService.GetStepAmount(currentPrice); nextStep = AuctionService.GetStepAmount(currentPrice);

View File

@ -1,7 +1,6 @@
using AyCode.Core.Extensions; using AyCode.Core.Extensions;
using AyCode.Utils.Extensions; using AyCode.Utils.Extensions;
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.Services; using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Catalog; using Nop.Services.Catalog;
using Nop.Services.Logging; using Nop.Services.Logging;
@ -12,10 +11,6 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Core.Domain.Customers; using Nop.Core.Domain.Customers;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Services.Customers; using Nop.Services.Customers;
using DocumentFormat.OpenXml.Wordprocessing;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
@ -162,6 +157,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
switch (auctionProductStatusRequest.AuctionStatus) switch (auctionProductStatusRequest.AuctionStatus)
{ {
case AuctionStatus.None:
return; //ez sosem futhat le a fenti if miatt... - J.
case AuctionStatus.Pause: case AuctionStatus.Pause:
productToAuction.AuctionStatus = AuctionStatus.Pause; productToAuction.AuctionStatus = AuctionStatus.Pause;
break; break;
@ -179,7 +177,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId; productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId;
var placeOrderResult = await auctionService.CreateOrderForWinnerAsync(productToAuction); var placeOrderResult = await auctionService.CreateOrderForWinnerAsync(productToAuction);
if (placeOrderResult is not { Success: true }) return; if (placeOrderResult is not { Success: true })
{
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (placeOrderResult is not {{ Success: true }})", null, customer);
return;
}
break; break;

View File

@ -1,19 +1,13 @@
using AyCode.Core.Extensions; using Nop.Core;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Orders;
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer; using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
using Nop.Services.Catalog; using Nop.Services.Catalog;
using Nop.Services.Logging; using Nop.Services.Logging;
using Nop.Services.Orders; using Nop.Services.Orders;
using Nop.Services.Payments; using Nop.Services.Payments;
using Org.BouncyCastle.Crypto;
namespace Nop.Plugin.Misc.AuctionPlugin.Services; namespace Nop.Plugin.Misc.AuctionPlugin.Services;
@ -27,6 +21,7 @@ public class AuctionService : IAuctionService
private readonly AuctionDbContext _ctx; private readonly AuctionDbContext _ctx;
private readonly IProductService _productService; private readonly IProductService _productService;
private readonly IWorkContext _workContext; private readonly IWorkContext _workContext;
private readonly IPaymentService _paymentService;
private readonly IOrderProcessingService _orderProcessingService; private readonly IOrderProcessingService _orderProcessingService;
private readonly ILogger _logger; private readonly ILogger _logger;
#endregion #endregion
@ -39,13 +34,16 @@ public class AuctionService : IAuctionService
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="productService"></param> /// <param name="productService"></param>
/// <param name="workContext"></param> /// <param name="workContext"></param>
/// <param name="paymentService"></param>
/// <param name="logger"></param> /// <param name="logger"></param>
public AuctionService(AuctionDbContext ctx, IProductService productService, IWorkContext workContext, IOrderProcessingService orderProcessingService, ILogger logger) /// <param name="orderProcessingService"></param>
public AuctionService(AuctionDbContext ctx, IProductService productService, IWorkContext workContext, IOrderProcessingService orderProcessingService, IPaymentService paymentService, ILogger logger)
{ {
_ctx = ctx; _ctx = ctx;
_productService = productService; _productService = productService;
_workContext = workContext; _workContext = workContext;
_orderProcessingService = orderProcessingService; _orderProcessingService = orderProcessingService;
_paymentService = paymentService;
_logger = logger; _logger = logger;
} }
@ -201,16 +199,17 @@ public class AuctionService : IAuctionService
{ {
CustomerId = auctionItem.WinnerCustomerId, CustomerId = auctionItem.WinnerCustomerId,
OrderTotal = auctionItem.CurrentPrice, OrderTotal = auctionItem.CurrentPrice,
OrderGuid = auctionItem.OrderGuid.IsNullOrEmpty() ? Guid.NewGuid() : auctionItem.OrderGuid.Value
}; };
processPaymentRequest.CustomValues.Add("ProductToAuctionMappingId", auctionItem.Id); processPaymentRequest.CustomValues.Add("ProductToAuctionMappingId", auctionItem.Id);
//TODO: valszeg a GenerateOrderGuidAsync-ot kell használni, de nemtom egy példában láttam... - J.
await _paymentService.GenerateOrderGuidAsync(processPaymentRequest);
var placeOrderResult = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest); var placeOrderResult = await _orderProcessingService.PlaceOrderAsync(processPaymentRequest);
if (!placeOrderResult.Success) return null; if (!placeOrderResult.Success) return null;
//placeOrderResult.PlacedOrder //TODO:... - J.
auctionItem.OrderId = placeOrderResult.PlacedOrder.Id; auctionItem.OrderId = placeOrderResult.PlacedOrder.Id;
auctionItem.OrderGuid = placeOrderResult.PlacedOrder.OrderGuid; auctionItem.OrderGuid = placeOrderResult.PlacedOrder.OrderGuid;

View File

@ -14,7 +14,6 @@
@{ @{
if (Model.IsAnyItemActive) if (Model.IsAnyItemActive)
{ {
<div class="row py-3"> <div class="row py-3">
<!-- Item Image --> <!-- Item Image -->
<div class="col-lg-4 col-md-6 mb-4" style="height: calc(100vh - 100px);"> <div class="col-lg-4 col-md-6 mb-4" style="height: calc(100vh - 100px);">
@ -65,11 +64,11 @@
</div> </div>
<div> <div>
<span>Base price</span> <span>Base price</span>
<span>@(String.Format("{0:c}", Model.BasePrice))</span> <span>@($"{Model.BasePrice:c}")</span>
</div> </div>
<div> <div>
<span>Actual licit step</span> <span>Actual licit step</span>
<span>@(String.Format("{0:c}", Model.LicitStep))</span> <span>@($"{Model.LicitStep:c}")</span>
</div> </div>
</li> </li>
@ -84,7 +83,7 @@
<div class="card-footer h-50 border-0 align-items-center text-center bg-transparent"> <div class="card-footer h-50 border-0 align-items-center text-center bg-transparent">
<span>Current state price</span> <span>Current state price</span>
<h3 style="font-size: 72px;"> <h3 style="font-size: 72px;">
@(String.Format("{0:c}", Model.CurrentPrice)) @($"{Model.CurrentPrice:c}")
</h3> </h3>
</div> </div>
@ -115,7 +114,7 @@
$(document).ready(function () { $(document).ready(function () {
liveScreenPageViewModel = @Html.Raw(Json.Serialize(Model)); var liveScreenPageViewModel = @Html.Raw(Json.Serialize(Model));
console.log("ViewModel:", liveScreenPageViewModel); console.log("ViewModel:", liveScreenPageViewModel);
// Extract and preprocess table data // Extract and preprocess table data
@ -126,6 +125,7 @@
BidPrice: item.BidPrice, BidPrice: item.BidPrice,
CustomerId: item.CustomerId CustomerId: item.CustomerId
})); }));
console.log("Table Data:", tableData); console.log("Table Data:", tableData);
tableData.forEach((element) => console.log(element)); tableData.forEach((element) => console.log(element));
@ -147,22 +147,22 @@
}); });
function addRowToTable(tableRow) { function addRowToTable(tableRow) {
const table = document.getElementById("bidHistoryTable"); var table = document.getElementById("bidHistoryTable");
const row = table.insertRow(); var row = table.insertRow();
const cell1 = row.insertCell(); var cell1 = row.insertCell();
cell1.textContent = tableRow.Id; cell1.textContent = tableRow.Id;
const cell2 = row.insertCell(); var cell2 = row.insertCell();
cell2.textContent = tableRow.BidPrice; cell2.textContent = tableRow.BidPrice;
const cell3 = row.insertCell(); var cell3 = row.insertCell();
cell3.textContent = tableRow.CustomerId; cell3.textContent = tableRow.CustomerId;
} }
function reloadOnUpdate() { function reloadOnUpdate() {
location.reload() location.reload();
} }
</script> </script>

View File

@ -328,7 +328,7 @@
budButtonElement.disabled = false; budButtonElement.disabled = false;
if (isMyBid) { if (isMyBid) {
console.log("This is my bid"); console.log("This is my bid");
const list = bidBox.classList; var list = bidBox.classList;
list.add("bg-success"); list.add("bg-success");
list.remove("bg-primary"); list.remove("bg-primary");
budButtonElement.textContent = "Good job"; budButtonElement.textContent = "Good job";
@ -343,7 +343,7 @@
} }
} }
else { else {
const list = bidBox.classList; var list = bidBox.classList;
list.add("bg-primary"); list.add("bg-primary");
list.remove("bg-success"); list.remove("bg-success");
bidBoxTitle.textContent = "Place a bid!" bidBoxTitle.textContent = "Place a bid!"
@ -418,7 +418,7 @@
// Button IDs and their default states for each AuctionStatus // Button IDs and their default states for each AuctionStatus
//true = disabled //true = disabled
const buttonStates = { var buttonStates = {
[AuctionStatus.None]: { [AuctionStatus.None]: {
signalRBidButton: true, signalRBidButton: true,
signalRFirstWarningButton: true, signalRFirstWarningButton: true,
@ -503,7 +503,7 @@
}; };
// Get the states for the given auctionStatus // Get the states for the given auctionStatus
const states = buttonStates[auctionStatus]; var states = buttonStates[auctionStatus];
if (!states) { if (!states) {
console.error("Unknown AuctionStatus: ", auctionStatus); console.error("Unknown AuctionStatus: ", auctionStatus);
return; return;
@ -511,7 +511,7 @@
// Apply the states to each button // Apply the states to each button
Object.keys(states).forEach((buttonId) => { Object.keys(states).forEach((buttonId) => {
const button = document.getElementById(buttonId); var button = document.getElementById(buttonId);
if (button) { if (button) {
button.disabled = states[buttonId]; button.disabled = states[buttonId];
button.hidden = states[buttonId]; button.hidden = states[buttonId];