Compare commits

..

No commits in common. "a2a6f2def3f869c913d46c77d6a9f0b0779c8b4a" and "816eb7f3789776adf68ecb0f3b0d87a319469b97" have entirely different histories.

10 changed files with 810 additions and 822 deletions

View File

@ -1,7 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using ExCSS;
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Core.Domain.Catalog;
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.Cms;
@ -12,6 +15,7 @@ using Nop.Web.Framework.Components;
using Nop.Web.Framework.Infrastructure;
using Nop.Web.Models.Catalog;
using Nop.Web.Framework.Mvc.Routing;
using DocumentFormat.OpenXml.EMMA;
using Nop.Services.Catalog;
namespace Nop.Plugin.Misc.AuctionPlugin.Components;
@ -20,41 +24,40 @@ public class AuctionPublicViewComponent : NopViewComponent
{
#region Fields
//private readonly IAddressService _addressService;
//private readonly IGenericAttributeService _genericAttributeService;
private readonly IWidgetPluginManager _widgetPluginManager;
private readonly IWorkContext _workContext;
private readonly AuctionService _auctionService;
//private readonly AuctionSettings _auctionSettings;
private readonly ICustomerService _customerService;
private readonly IWebHelper _webHelper;
private readonly IProductService _productService;
private readonly ILogger _logger;
private readonly MyProductModelFactory _myProductModelFactory;
protected readonly IAddressService _addressService;
protected readonly IGenericAttributeService _genericAttributeService;
protected readonly IWidgetPluginManager _widgetPluginManager;
protected readonly IWorkContext _workContext;
protected readonly AuctionService _auctionService;
protected readonly AuctionSettings _auctionSettings;
protected readonly ICustomerService _customerService;
protected readonly IWebHelper _webHelper;
protected readonly IProductService _productService;
protected readonly ILogger _logger;
protected readonly MyProductModelFactory _myProductModelFactory;
#endregion
#region Ctor
public AuctionPublicViewComponent(
//IAddressService addressService,
//IGenericAttributeService genericAttributeService,
public AuctionPublicViewComponent(IAddressService addressService,
IGenericAttributeService genericAttributeService,
IWidgetPluginManager widgetPluginManager,
IWorkContext workContext,
AuctionService auctionService,
//AuctionSettings auctionSettings,
AuctionSettings auctionSettings,
ICustomerService customerService,
IWebHelper webHelper,
IProductService productService,
MyProductModelFactory myProductModelFactory,
ILogger logger)
{
//_addressService = addressService;
//_genericAttributeService = genericAttributeService;
_addressService = addressService;
_genericAttributeService = genericAttributeService;
_widgetPluginManager = widgetPluginManager;
_workContext = workContext;
_auctionService = auctionService;
//_auctionSettings = auctionSettings;
_auctionSettings = auctionSettings;
_customerService = customerService;
_webHelper = webHelper;
_productService = productService;
@ -93,7 +96,7 @@ public class AuctionPublicViewComponent : NopViewComponent
//if (!_auctionSettings.Enabled)
// return Content(string.Empty);
var productDetailsModel = (additionalData as ProductDetailsModel)!;
var productDetailsModel = additionalData as ProductDetailsModel;
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
@ -129,7 +132,7 @@ public class AuctionPublicViewComponent : NopViewComponent
var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto);
//List<ProductToAuctionMapping> productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id);
var status = productToAuction.AuctionStatus;
AuctionStatus status = productToAuction.AuctionStatus;
//bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning;
//bool isFirstWarning = status == AuctionStatus.FirstWarning;
@ -137,25 +140,23 @@ public class AuctionPublicViewComponent : NopViewComponent
ProductToAuctionDto nextProductToAuction;
ProductToAuctionDto lastProductToAuction;
var nextUrl = "";
var lastUrl = "";
var nextImageUrl = "";
var lastImageUrl = "";
var nextProductName = "";
var lastProductName = "";
string nextUrl = "";
string lastUrl = "";
string nextImageUrl = "";
string lastImageUrl = "";
string nextProductName = "";
string lastProductName = "";
if (productToAuction.SortIndex < detailedAuctionDto.ProductToAuctionDtos.Count)
{
nextProductToAuction = detailedAuctionDto.ProductToAuctionDtos.FirstOrDefault(x => x.SortIndex == productToAuction.SortIndex + 1);
if (nextProductToAuction != null)
{
nextProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex + 1).FirstOrDefault();
var nextProductId = nextProductToAuction.ProductId;
var nextProduct = await _productService.GetProductByIdAsync(nextProductId);
var nextDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(nextProduct);
nextUrl = Url.RouteUrl<Product>(new { nextDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
nextImageUrl = nextDetails.DefaultPictureModel.FullSizeImageUrl;
nextProductName = nextDetails.SeName;
}
}
else
{
@ -164,9 +165,7 @@ public class AuctionPublicViewComponent : NopViewComponent
if (productToAuction.SortIndex > 1)
{
lastProductToAuction = detailedAuctionDto.ProductToAuctionDtos.FirstOrDefault(x => x.SortIndex == productToAuction.SortIndex - 1);
if (lastProductToAuction != null)
{
lastProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex - 1).FirstOrDefault();
var lastProductId = lastProductToAuction.ProductId;
var lastProduct = await _productService.GetProductByIdAsync(lastProductId);
var lastDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(lastProduct);
@ -174,12 +173,12 @@ public class AuctionPublicViewComponent : NopViewComponent
lastImageUrl = lastDetails.DefaultPictureModel.FullSizeImageUrl;
lastProductName = lastDetails.SeName;
}
}
else
{
lastProductToAuction = null;
}
productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
productBidBoxViewModel.AuctionClosed = auctionDto.Closed;
@ -199,7 +198,7 @@ public class AuctionPublicViewComponent : NopViewComponent
productBidBoxViewModel.LastProductName = lastProductName;
productBidBoxViewModel.NextProductName = nextProductName;
productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation
productBidBoxViewModel.NextBidPrice = AuctionService.GetNextBidPrice(productToAuction.CurrentPrice, productBidBoxViewModel.LicitStep);
productBidBoxViewModel.NextBidPrice = productToAuction.CurrentPrice + productBidBoxViewModel.LicitStep;
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel);

View File

@ -1,7 +1,7 @@
var MessageHandler = (function () {
// Handlers for each message type
var animation = "slideDown";
var handlers = {
let animation = "slideDown";
const handlers = {
announcement: function (data) {
var myObject = JSON.parse(data);
@ -31,30 +31,20 @@
//console.log(data);
var myObject = JSON.parse(data);
//console.log(myObject);
var auctionDto = myObject.auctionDto;
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
//var productAuctionMappingId = productToAuctionDto.id;
var productAuctionMappingId = myObject.auctionDto.productToAuctionDtos[0].id;
//console.log(productAuctionMappingId);
var publicProductBidBox = document.getElementById("publicProductBidBox");
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
if (publicProductBidBox)
{
refreshPublicBidBox(myObject);
}
if (publicInfo) {
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
window[functionName](auctionDto);
}
if (liveScreen)
{
reloadOnUpdate();
}
else {
if (!liveScreen) {
toastr.success(`<div class="item bidToast"><p>${myObject.currentPrice}</p><p>${myObject.productName}</p></div>`, "New bid arrived", {
"closeButton": true,
"positionClass": "toast-bottom-left",
@ -76,14 +66,12 @@
},
ProductToAuctionStatusNotification: function (data) {
console.log(data);
var myObject = JSON.parse(data);
var auctionDto = myObject.auctionDto;
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
var productToAuctionDto = myObject.auctionDto.productToAuctionDtos[0];
var publicProductBidBox = document.getElementById("publicProductBidBox");
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
if (!liveScreen) {
var messageTitle = "";
var messageText = "";
@ -155,7 +143,11 @@
}
if (publicInfo) {
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
window[functionName](auctionDto);
/*if (typeof window[functionName] === "function" + productToAuctionDto.productId) {*/
window[functionName](myObject); // Dynamically call the function
//} else {
//console.error("Function " + functionName + " does not exist.");
//}
}
// var publicProductBidBox = document.getElementById("publicProductBidBox");

View File

@ -1,18 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using AyCode.Core.Extensions;
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(AuctionService auctionService, ILogger logger, IProductService productService, MyProductModelFactory productModelFactory)
: BasePluginController
public class AuctionController : 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
public IActionResult Index()
{
@ -24,7 +43,7 @@ public class AuctionController(AuctionService auctionService, ILogger logger, IP
public async Task<IActionResult> PlaceBid([FromBody] AuctionBid model)
{
await logger.InformationAsync("PlaceBid called");
await _logger.InformationAsync("PlaceBid called");
//if (model.BidPrice < CurrentPrice + LicitStep)
//{
@ -32,8 +51,8 @@ public class AuctionController(AuctionService auctionService, ILogger logger, IP
//}
// kéne valami visszajelzés
await auctionService.InsertBidAsync(model);
var bidSuccess = true;
await _auctionService.InsertBidAsync(model);
bool bidSuccess = true;
if (bidSuccess)
{
return Ok(new { message = "Your bid was successfully placed!" });
@ -47,17 +66,17 @@ public class AuctionController(AuctionService auctionService, ILogger logger, IP
[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);
var detailsModel = await productModelFactory.PrepareProductDetailsModelAsync(product);
var product = await _productService.GetProductByIdAsync(request.ProductId);
ProductDetailsModel 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); //A javascript-ben az első 6-ot vágod le, melyik a valid? - J.
var auctionDto = await _auctionService.GetAuctionDtoWithAuctionBids(auctionId, true, 5);
var activeMapping = auctionDto?.ProductToAuctionDtos.MinBy(x => x.SortIndex);
var isAnyItemLive = activeMapping != null;
if (auctionDto == null)
@ -69,18 +88,18 @@ public class AuctionController(AuctionService auctionService, ILogger logger, IP
Product product;
ProductDetailsModel productDetailsModel;
int activeProductId;
int activeProductToAuctionId;
int activeProductId = 0;
int activeProductToAuctionId = 0;
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,6 +1,7 @@
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;
@ -11,6 +12,10 @@ 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
{
@ -157,9 +162,6 @@ 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;
@ -177,11 +179,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
productToAuction.WinnerCustomerId = lastAuctionBid.CustomerId;
var placeOrderResult = await auctionService.CreateOrderForWinnerAsync(productToAuction);
if (placeOrderResult is not { Success: true })
{
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (placeOrderResult is not {{ Success: true }})", null, customer);
return;
}
if (placeOrderResult is not { Success: true }) return;
break;
@ -325,8 +323,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
}
private static decimal GetStepAmount(decimal currentBidPrice) => AuctionService.GetStepAmount(currentBidPrice);
private static decimal GetNextBidPrice(decimal currentBidPrice) => AuctionService.GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
private static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount) => AuctionService.GetNextBidPrice(currentBidPrice, stepAmount);
private static decimal GetNextBidPrice(decimal currentBidPrice) => GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
private static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount)
{
return currentBidPrice + stepAmount;
}
private static bool IsValidRequestAuctionStatus(AuctionStatus newStatus, AuctionStatus oldStatus)
{

View File

@ -1,41 +1,40 @@
using Newtonsoft.Json;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Web.Framework.Models;
using Nop.Web.Framework.Mvc.ModelBinding;
namespace Nop.Plugin.Misc.AuctionPlugin.Models
{
public record AuctionPublicInfoModel : BaseNopModel
{
//[JsonIgnore]
//[System.Text.Json.Serialization.JsonIgnore]
[JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public AuctionDto AuctionDto { get; set; }
[JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public ProductToAuctionDto FirstProductToAuction { get; set; }
public int ProductId => FirstProductToAuction?.ProductId ?? 0;
public int ProductToAuctionMappingId => FirstProductToAuction?.ProductId ?? 0;
public DateTime StartDate => AuctionDto?.StartDateUtc ?? DateTime.MinValue;
public bool IsActive => FirstProductToAuction?.IsActiveItem ?? false;
public int ProductId { get; set; }
public int ProductToAuctionMappingId { get; set; }
public DateTime StartDate { get; set; }
public bool IsActive { get; set; }
public AuctionPublicInfoModel()
{
}
public AuctionPublicInfoModel() {}
public AuctionPublicInfoModel(AuctionDto auctionDto) : this()
{
AuctionDto = auctionDto;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First();
//StartDate = AuctionDto.StartDateUtc;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.FirstOrDefault();
if (FirstProductToAuction == null) return;
//ProductId = FirstProductToAuction.ProductId;
//ProductToAuctionMappingId = FirstProductToAuction.Id;
//IsActive = FirstProductToAuction.IsActiveItem;
ProductId = FirstProductToAuction.ProductId;
ProductToAuctionMappingId = FirstProductToAuction.Id;
StartDate = AuctionDto.StartDateUtc;
IsActive = FirstProductToAuction.IsActiveItem;
}
}
}

View File

@ -27,7 +27,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
public int AuctionId { get; set; }
public bool AuctionClosed { get; set; }
public bool IsItemActive => FirstProductToAuction?.IsActiveItem ?? false;
public bool IsItemActive => FirstProductToAuction.IsActiveItem;
public AuctionStatus AuctionStatus { get; set; }
public int ProductId { get; set; }
@ -62,11 +62,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
public ProductBidBoxViewModel(AuctionDto auctionDto) : this()
{
AuctionDto = auctionDto;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First();
AuctionId = auctionDto.Id;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.FirstOrDefault();
if (FirstProductToAuction == null) return;
ProductId = FirstProductToAuction.ProductId;
ProductToAuctionId = FirstProductToAuction.Id;
}

View File

@ -1,14 +1,19 @@
using Nop.Core;
using AyCode.Core.Extensions;
using Nop.Core;
using Nop.Core.Caching;
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;
@ -22,7 +27,6 @@ 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 IShoppingCartService _shoppingCartService;
private readonly IStoreContext _storeContext;
@ -37,7 +41,6 @@ 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,
@ -46,7 +49,6 @@ public class AuctionService : IAuctionService
IOrderProcessingService orderProcessingService,
IShoppingCartService shoppingCartService,
IStoreContext storeContext,
IPaymentService paymentService,
ILogger logger)
{
_ctx = ctx;
@ -55,7 +57,6 @@ public class AuctionService : IAuctionService
_orderProcessingService = orderProcessingService;
_shoppingCartService = shoppingCartService;
_storeContext = storeContext;
_paymentService = paymentService;
_logger = logger;
}
@ -105,12 +106,6 @@ public class AuctionService : IAuctionService
//200 000 000 Ft fölött 20 000 000 Ft-tal
}
public static decimal GetNextBidPrice(decimal currentBidPrice) => GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
public static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount)
{
return currentBidPrice + stepAmount;
}
public async Task ResetProductToAuctionByProductId(int productId)
=> await ResetProductToAuctionAsync(await _ctx.ProductToAuctions.GetByProductId(productId).FirstOrDefaultAsync());
@ -212,15 +207,12 @@ public class AuctionService : IAuctionService
PaymentMethodSystemName = "Payments.CheckMoneyOrder",
CustomerId = auctionItem.WinnerCustomerId,
OrderTotal = auctionItem.CurrentPrice,
OrderGuid = auctionItem.OrderGuid.IsNullOrEmpty() ? Guid.NewGuid() : auctionItem.OrderGuid.Value
};
var currentCustomer = await _workContext.GetCurrentCustomerAsync();
var product = await _productService.GetProductByIdAsync(auctionItem.ProductId);
var currentStore = await _storeContext.GetCurrentStoreAsync();
//TODO: valszeg a GenerateOrderGuidAsync-ot kell használni, de nemtom egy példában láttam... - J.
await _paymentService.GenerateOrderGuidAsync(processPaymentRequest);
processPaymentRequest.CustomValues.Add("ProductToAuctionMappingId", auctionItem.Id);
product.DisableBuyButton = false;
@ -231,6 +223,8 @@ public class AuctionService : IAuctionService
if (!placeOrderResult.Success) return null;
//placeOrderResult.PlacedOrder //TODO:... - J.
auctionItem.OrderId = placeOrderResult.PlacedOrder.Id;
auctionItem.OrderGuid = placeOrderResult.PlacedOrder.OrderGuid;

View File

@ -14,6 +14,7 @@
@{
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);">
@ -64,11 +65,11 @@
</div>
<div>
<span>Base price</span>
<span>@($"{Model.BasePrice:c}")</span>
<span>@(String.Format("{0:c}", Model.BasePrice))</span>
</div>
<div>
<span>Actual licit step</span>
<span>@($"{Model.LicitStep:c}")</span>
<span>@(String.Format("{0:c}", Model.LicitStep))</span>
</div>
</li>
@ -83,7 +84,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;">
@($"{Model.CurrentPrice:c}")
@(String.Format("{0:c}", Model.CurrentPrice))
</h3>
</div>
@ -114,7 +115,7 @@
$(document).ready(function () {
var liveScreenPageViewModel = @Html.Raw(Json.Serialize(Model));
liveScreenPageViewModel = @Html.Raw(Json.Serialize(Model));
console.log("ViewModel:", liveScreenPageViewModel);
// Extract and preprocess table data
@ -125,7 +126,6 @@
BidPrice: item.BidPrice,
CustomerId: item.CustomerId
}));
console.log("Table Data:", tableData);
tableData.forEach((element) => console.log(element));
@ -147,22 +147,22 @@
});
function addRowToTable(tableRow) {
var table = document.getElementById("bidHistoryTable");
var row = table.insertRow();
const table = document.getElementById("bidHistoryTable");
const row = table.insertRow();
var cell1 = row.insertCell();
const cell1 = row.insertCell();
cell1.textContent = tableRow.Id;
var cell2 = row.insertCell();
const cell2 = row.insertCell();
cell2.textContent = tableRow.BidPrice;
var cell3 = row.insertCell();
const cell3 = row.insertCell();
cell3.textContent = tableRow.CustomerId;
}
function reloadOnUpdate() {
location.reload();
location.reload()
}
</script>

View File

@ -1,85 +1,72 @@
@using AyCode.Core.Extensions
@model AuctionPublicInfoModel
@model AuctionPublicInfoModel
<script asp-location="Footer">
var pageViewModel;
var isActive;
$(document).ready(function () {
console.log("PublicInfo ready enter; ProductId: " + @Model.ProductId);
let auctionDto = @Html.Raw(Model.AuctionDto.ToJson());
initialize@(Model.ProductId)(auctionDto);
// Deserialize the server-side model
pageViewModel = @Html.Raw(Json.Serialize(Model));
console.log("Page View Model:", pageViewModel);
console.log(pageViewModel.ProductId);
console.log(pageViewModel.ProductToAuctionMappingId);
// Get the element with data-productid
isActive = pageViewModel.IsActive;
initialize@(Model.ProductId)(@Model.ProductId);
});
function initialize@(Model.ProductId)(auctionDto) {
console.log("PublicInfo initialize" + @Model.ProductId + " enter; auctionDto: " + auctionDto);
function initialize@(Model.ProductId)(thisProductId) {
console.log("isActive = " + isActive);
console.log("productId:" + thisProductId);
var productItem = $('.product-item[data-productid="' + thisProductId + '"]');
if (!auctionDto) {
console.error("auctionDto == null");
return;
}
let productToAuctionDto = auctionDto.productToAuctionDtos[0];
let productId = productToAuctionDto.productId;
let isActive = productToAuctionDto.isActiveItem;
console.log("isActiveItem: " + isActive + "; productId:" + productId + "; productToAuctionId: " + productToAuctionDto.id);
let productItem = $('.product-item[data-productid="' + productId + '"]');
let publicInfoOverlayId = "publicInfoOverlay" + productId;
console.log("publicInfoOverlayId: " + publicInfoOverlayId + "; productItem:" + productItem);
var existingOverlay = document.getElementById(publicInfoOverlayId);
var existingOverlay = document.getElementById(`publicInfoOverlay${thisProductId}`);
if (existingOverlay) {
console.log("remove because it exists");
existingOverlay.remove();
}
// Check if element exists
if (productItem.length > 0 && productToAuctionDto.id > 0) {
if (productItem.length > 0 && pageViewModel.ProductToAuctionMappingId > 0) {
console.log("Product item length:", productItem.length);
var widgetPriceElements = productItem.find('.actual-price');
//console.log("widgetPriceElements:", widgetPriceElements);
if (widgetPriceElements && widgetPriceElements.length > 0) {
widgetPriceElements[0].textContent = HUFFormatter.format(productToAuctionDto.currentPrice); // Update the price
}
// Add a new div as the first child
if (isActive) {
console.log("isActive: " + isActive);
productItem.prepend('<div id="' +
publicInfoOverlayId +
'" class="bg-success p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> ' +
'LIVE RIGTH NOW' +
productItem.prepend(`<div id="publicInfoOverlay${thisProductId}" class="bg-success p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
+ 'LIVE RIGTH NOW' +
'</i></div>');
} else {
}
else {
console.log("isActive: " + isActive);
productItem.prepend('<div id="' +
publicInfoOverlayId +
'" class="bg-primary p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> ' +
auctionDto.startDateUtc +
productItem.prepend(`<div id="publicInfoOverlay${thisProductId}" class="bg-primary p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
+ pageViewModel.StartDate +
'</i></div>');
}
} else {
console.error("Product item not found with productId:", productId);
console.error("Product item not found with productId:", pageViewModel.ProductId);
}
}
window[`refreshPublicInfo${@Model.ProductId}`] = function(auctionDto) {
let productToAuctionDto = auctionDto.productToAuctionDtos[0];
window[`refreshPublicInfo${@Model.ProductId}`] = function (data) {
console.log(auctionDto);
console.log("setting active to " + productToAuctionDto.isActiveItem);
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
if (status == AuctionStatus.Active) {
console.log(data.auctionDto);
isActive = true;
console.log("setting active to " + isActive);
}
else {
isActive = false;
console.log("setting active to " + isActive);
}
initialize@(Model.ProductId)(auctionDto);
console.log('Function called: refreshPublicInfo' + productToAuctionDto.productId);
initialize@(Model.ProductId)(data.auctionDto.productToAuctionDtos[0].productId);
console.log('Function called: refreshPublicInfo' + @Model.ProductId);
};
console.log(`Function refreshPublicInfo${@Model.ProductId} added to DOM:`, window[`refreshPublicInfo${@Model.ProductId}`]);
</script>

View File

@ -9,12 +9,9 @@
@{
if (!Model.IsGuest)
{
if (Model.FirstProductToAuction != null)
{
var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin);
var title = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "Your bid is leading" : "Place a bid!";
var bgClass = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
bool bidButtonActive = Model.IsItemActive && (Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId && !Model.IsAdmin) ? true : false;
string title = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "Your bid is leading" : "Place a bid!";
<div class="d-flex justify-content-between" id="otherAuctionItems">
<a href="@(string.IsNullOrEmpty(Model.LastProductUrl) ? "#" : Model.LastProductUrl)" @(string.IsNullOrEmpty(Model.LastProductUrl) ? "disabled" : string.Empty)>
<div class="card mb-3" style="max-width: 540px;">
@ -26,12 +23,12 @@
<div class="card-body">
<h5 class="card-title">@(string.IsNullOrEmpty(Model.LastProductUrl) ? "Start of list" : "Back to last")</h5>
<p class="card-text">@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)</p>
</div>
</div>
</div>
</div>
</a>
<a href="@(string.IsNullOrEmpty(Model.NextProductUrl) ? "#" : Model.NextProductUrl)" @(string.IsNullOrEmpty(Model.NextProductUrl) ? "disabled" : string.Empty)>
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
@ -42,6 +39,7 @@
<div class="card-body">
<h5 class="card-title">@(string.IsNullOrEmpty(Model.NextProductUrl) ? "End of list" : "Coming up next...")</h5>
<p class="card-text">@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)</p>
</div>
</div>
</div>
@ -64,7 +62,7 @@
<span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
</div>
<div>
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(!bidButtonActive ? "disabled" : string.Empty)>
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(bidButtonActive)">
Bid @($"{Model.NextBidPrice:c}")
</button>
@* <button id="bidButton" class="btn btn-success">
@ -124,7 +122,8 @@
{
<p>No access to admin level buttons</p>
}
}
}
else
{
@ -136,9 +135,9 @@
</div>
</div>
}
}
}
<script>
<script>
var bidBoxPageViewModel;
$(window).load(function () {
@ -328,7 +327,7 @@
budButtonElement.disabled = false;
if (isMyBid) {
console.log("This is my bid");
var list = bidBox.classList;
const list = bidBox.classList;
list.add("bg-success");
list.remove("bg-primary");
budButtonElement.textContent = "Good job";
@ -343,7 +342,7 @@
}
}
else {
var list = bidBox.classList;
const list = bidBox.classList;
list.add("bg-primary");
list.remove("bg-success");
bidBoxTitle.textContent = "Place a bid!"
@ -418,7 +417,7 @@
// Button IDs and their default states for each AuctionStatus
//true = disabled
var buttonStates = {
const buttonStates = {
[AuctionStatus.None]: {
signalRBidButton: true,
signalRFirstWarningButton: true,
@ -503,7 +502,7 @@
};
// Get the states for the given auctionStatus
var states = buttonStates[auctionStatus];
const states = buttonStates[auctionStatus];
if (!states) {
console.error("Unknown AuctionStatus: ", auctionStatus);
return;
@ -511,7 +510,7 @@
// Apply the states to each button
Object.keys(states).forEach((buttonId) => {
var button = document.getElementById(buttonId);
const button = document.getElementById(buttonId);
if (button) {
button.disabled = states[buttonId];
button.hidden = states[buttonId];
@ -522,4 +521,4 @@
}
</script>
</script>