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 () {
// Handlers for each message type
let animation = "slideDown";
const handlers = {
var animation = "slideDown";
var handlers = {
announcement: function (data) {
var myObject = JSON.parse(data);

View File

@ -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<IActionResult> 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<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);
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<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 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);

View File

@ -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;

View File

@ -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
/// <param name="ctx"></param>
/// <param name="productService"></param>
/// <param name="workContext"></param>
/// <param name="paymentService"></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;
_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;

View File

@ -14,7 +14,6 @@
@{
if (Model.IsAnyItemActive)
{
<div class="row py-3">
<!-- Item Image -->
<div class="col-lg-4 col-md-6 mb-4" style="height: calc(100vh - 100px);">
@ -65,11 +64,11 @@
</div>
<div>
<span>Base price</span>
<span>@(String.Format("{0:c}", Model.BasePrice))</span>
<span>@($"{Model.BasePrice:c}")</span>
</div>
<div>
<span>Actual licit step</span>
<span>@(String.Format("{0:c}", Model.LicitStep))</span>
<span>@($"{Model.LicitStep:c}")</span>
</div>
</li>
@ -84,7 +83,7 @@
<div class="card-footer h-50 border-0 align-items-center text-center bg-transparent">
<span>Current state price</span>
<h3 style="font-size: 72px;">
@(String.Format("{0:c}", Model.CurrentPrice))
@($"{Model.CurrentPrice:c}")
</h3>
</div>
@ -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();
}
</script>

View File

@ -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];