diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index 98df791..08b037c 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -1,7 +1,7 @@ var MessageHandler = (function () { // Handlers for each message type - let animation = "slideDown"; - const handlers = { + var animation = "slideDown"; + var handlers = { announcement: function (data) { var myObject = JSON.parse(data); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs index 3898509..8aa1344 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs @@ -1,38 +1,19 @@ -using AyCode.Core.Extensions; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; 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.Enums; using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Services.Catalog; using Nop.Services.Logging; -using Nop.Web.Areas.Admin.Factories; using Nop.Web.Framework.Controllers; using Nop.Web.Models.Catalog; 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() { //var a = new Auction(); @@ -43,7 +24,7 @@ public class AuctionController : BasePluginController public async Task PlaceBid([FromBody] AuctionBid model) { - await _logger.InformationAsync("PlaceBid called"); + await logger.InformationAsync("PlaceBid called"); //if (model.BidPrice < CurrentPrice + LicitStep) //{ @@ -51,8 +32,8 @@ public class AuctionController : BasePluginController //} // kéne valami visszajelzés - await _auctionService.InsertBidAsync(model); - bool bidSuccess = true; + await auctionService.InsertBidAsync(model); + var bidSuccess = true; if (bidSuccess) { return Ok(new { message = "Your bid was successfully placed!" }); @@ -66,17 +47,17 @@ public class AuctionController : BasePluginController [HttpPost] public async Task 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); - ProductDetailsModel detailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product); + var product = await productService.GetProductByIdAsync(request.ProductId); + var detailsModel = await productModelFactory.PrepareProductDetailsModelAsync(product); return ViewComponent("AuctionPublic", new { widgetZone = request.WidgetZone, additionalData = detailsModel }); } public async Task 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 isAnyItemLive = activeMapping != null; if (auctionDto == null) @@ -88,18 +69,18 @@ public class AuctionController : BasePluginController Product product; ProductDetailsModel productDetailsModel; - int activeProductId = 0; - int activeProductToAuctionId = 0; + int activeProductId; + int activeProductToAuctionId; decimal basePrice = 0; decimal currentPrice = 0; decimal nextStep = 0; if (isAnyItemLive) { - product = await _productService.GetProductByIdAsync(activeMapping.ProductId); + product = await productService.GetProductByIdAsync(activeMapping.ProductId); activeProductId = activeMapping.ProductId; activeProductToAuctionId = activeMapping.Id; - productDetailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product); + productDetailsModel = await productModelFactory.PrepareProductDetailsModelAsync(product); basePrice = activeMapping.StartingPrice; currentPrice = activeMapping.CurrentPrice; nextStep = AuctionService.GetStepAmount(currentPrice); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs index afc7b06..2336c87 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs @@ -1,7 +1,6 @@ using AyCode.Core.Extensions; using AyCode.Utils.Extensions; using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages; -using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Services.Catalog; using Nop.Services.Logging; @@ -12,10 +11,6 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Core.Domain.Customers; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; 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 { @@ -162,6 +157,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs { switch (auctionProductStatusRequest.AuctionStatus) { + case AuctionStatus.None: + return; //ez sosem futhat le a fenti if miatt... - J. + case AuctionStatus.Pause: productToAuction.AuctionStatus = AuctionStatus.Pause; break; @@ -179,7 +177,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId; 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; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index 7fa636f..fe5a948 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -1,19 +1,13 @@ -using AyCode.Core.Extensions; -using Nop.Core; -using Nop.Core.Caching; +using Nop.Core; 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.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; -using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages; using Nop.Services.Catalog; using Nop.Services.Logging; using Nop.Services.Orders; using Nop.Services.Payments; -using Org.BouncyCastle.Crypto; namespace Nop.Plugin.Misc.AuctionPlugin.Services; @@ -27,6 +21,7 @@ public class AuctionService : IAuctionService private readonly AuctionDbContext _ctx; private readonly IProductService _productService; private readonly IWorkContext _workContext; + private readonly IPaymentService _paymentService; private readonly IOrderProcessingService _orderProcessingService; private readonly ILogger _logger; #endregion @@ -39,13 +34,16 @@ public class AuctionService : IAuctionService /// /// /// + /// /// - public AuctionService(AuctionDbContext ctx, IProductService productService, IWorkContext workContext, IOrderProcessingService orderProcessingService, ILogger logger) + /// + public AuctionService(AuctionDbContext ctx, IProductService productService, IWorkContext workContext, IOrderProcessingService orderProcessingService, IPaymentService paymentService, ILogger logger) { _ctx = ctx; _productService = productService; _workContext = workContext; _orderProcessingService = orderProcessingService; + _paymentService = paymentService; _logger = logger; } @@ -201,16 +199,17 @@ public class AuctionService : IAuctionService { CustomerId = auctionItem.WinnerCustomerId, OrderTotal = auctionItem.CurrentPrice, - OrderGuid = auctionItem.OrderGuid.IsNullOrEmpty() ? Guid.NewGuid() : auctionItem.OrderGuid.Value }; 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); if (!placeOrderResult.Success) return null; - //placeOrderResult.PlacedOrder //TODO:... - J. - auctionItem.OrderId = placeOrderResult.PlacedOrder.Id; auctionItem.OrderGuid = placeOrderResult.PlacedOrder.OrderGuid; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml index c0a5bf1..7d3f7dc 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml @@ -14,7 +14,6 @@ @{ if (Model.IsAnyItemActive) { -
@@ -65,11 +64,11 @@
Base price - @(String.Format("{0:c}", Model.BasePrice)) + @($"{Model.BasePrice:c}")
Actual licit step - @(String.Format("{0:c}", Model.LicitStep)) + @($"{Model.LicitStep:c}")
@@ -84,7 +83,7 @@ @@ -115,7 +114,7 @@ $(document).ready(function () { - liveScreenPageViewModel = @Html.Raw(Json.Serialize(Model)); + var liveScreenPageViewModel = @Html.Raw(Json.Serialize(Model)); console.log("ViewModel:", liveScreenPageViewModel); // Extract and preprocess table data @@ -126,6 +125,7 @@ BidPrice: item.BidPrice, CustomerId: item.CustomerId })); + console.log("Table Data:", tableData); tableData.forEach((element) => console.log(element)); @@ -147,22 +147,22 @@ }); function addRowToTable(tableRow) { - const table = document.getElementById("bidHistoryTable"); - const row = table.insertRow(); + var table = document.getElementById("bidHistoryTable"); + var row = table.insertRow(); - const cell1 = row.insertCell(); + var cell1 = row.insertCell(); cell1.textContent = tableRow.Id; - const cell2 = row.insertCell(); + var cell2 = row.insertCell(); cell2.textContent = tableRow.BidPrice; - const cell3 = row.insertCell(); + var cell3 = row.insertCell(); cell3.textContent = tableRow.CustomerId; } function reloadOnUpdate() { - location.reload() + location.reload(); } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index c098d3e..7f78c43 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -328,7 +328,7 @@ budButtonElement.disabled = false; if (isMyBid) { console.log("This is my bid"); - const list = bidBox.classList; + var list = bidBox.classList; list.add("bg-success"); list.remove("bg-primary"); budButtonElement.textContent = "Good job"; @@ -343,7 +343,7 @@ } } else { - const list = bidBox.classList; + var list = bidBox.classList; list.add("bg-primary"); list.remove("bg-success"); bidBoxTitle.textContent = "Place a bid!" @@ -418,7 +418,7 @@ // Button IDs and their default states for each AuctionStatus //true = disabled - const buttonStates = { + var buttonStates = { [AuctionStatus.None]: { signalRBidButton: true, signalRFirstWarningButton: true, @@ -503,7 +503,7 @@ }; // Get the states for the given auctionStatus - const states = buttonStates[auctionStatus]; + var states = buttonStates[auctionStatus]; if (!states) { console.error("Unknown AuctionStatus: ", auctionStatus); return; @@ -511,7 +511,7 @@ // Apply the states to each button Object.keys(states).forEach((buttonId) => { - const button = document.getElementById(buttonId); + var button = document.getElementById(buttonId); if (button) { button.disabled = states[buttonId]; button.hidden = states[buttonId];