This commit is contained in:
Loretta 2024-11-22 11:31:45 +01:00
parent 5b15c2d52d
commit 69a6cd5053
14 changed files with 41 additions and 46 deletions

View File

@ -120,8 +120,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
{ {
//AuctionDto = TODO: ??? - J. //AuctionDto = TODO: ??? - J.
ProductName = viewModel.ProductName, ProductName = viewModel.ProductName,
BidPrice = viewModel.BidPrice, CurrentPrice = viewModel.BidPrice,
NextStepAmount = viewModel.NextStepAmount NextStepAmount = viewModel.NextStepAmount,
NextBidPrice = viewModel.BidPrice + viewModel.NextStepAmount
}.ToJson() }.ToJson()
}; };
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented, var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,

View File

@ -105,27 +105,26 @@ public class AuctionPublicViewComponent : NopViewComponent
var productId = productDetailsModel.Id; var productId = productDetailsModel.Id;
var productToAuctionDtoMappings = await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId); var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault();
if (productToAuctionDtoMappings.Count == 0) if (productToAuction == null)
{ {
return Content(string.Empty); return Content(string.Empty);
} }
var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuctionDtoMappings.FirstOrDefault()!.AuctionId)); var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId));
auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings); auctionDto.ProductToAuctionDtos.Add(productToAuction);
var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto); var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto);
//List<ProductToAuctionMapping> productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id); //List<ProductToAuctionMapping> productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id);
AuctionStatus status = productToAuctionId.FirstOrDefault().AuctionStatus; AuctionStatus status = productToAuction.AuctionStatus;
//bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning; //bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning;
bool isFirstWarning = status == AuctionStatus.FirstWarning; //bool isFirstWarning = status == AuctionStatus.FirstWarning;
productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer); productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer); productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
productBidBoxViewModel.AuctionClosed = auction.Closed; productBidBoxViewModel.AuctionClosed = auctionDto.Closed;
//productBidBoxViewModel.IsItemActive = isActive;
productBidBoxViewModel.AuctionStatus = status; productBidBoxViewModel.AuctionStatus = status;
productBidBoxViewModel.WidgetZone = widgetZone; productBidBoxViewModel.WidgetZone = widgetZone;
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
@ -134,8 +133,8 @@ public class AuctionPublicViewComponent : NopViewComponent
//productBidBoxViewModel.AuctionId = auctionId; //productBidBoxViewModel.AuctionId = auctionId;
productBidBoxViewModel.CustomerId = customer.Id; productBidBoxViewModel.CustomerId = customer.Id;
productBidBoxViewModel.ProductId = productDetailsModel.Id; productBidBoxViewModel.ProductId = productDetailsModel.Id;
productBidBoxViewModel.LicitStep = 50000; //add calculation productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation
productBidBoxViewModel.BidPrice = productDetailsModel.ProductPrice.PriceValue + productBidBoxViewModel.LicitStep; productBidBoxViewModel.NextBidPrice = productToAuction.CurrentPrice + productBidBoxViewModel.LicitStep;
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel); return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel);

View File

@ -7,7 +7,7 @@
Active: 1, Active: 1,
FirstWarning: 2, FirstWarning: 2,
SecondWarning: 4, SecondWarning: 4,
SoldOut: 8, Sold: 8,
NotSold: 16 NotSold: 16
}); });

View File

@ -25,7 +25,7 @@
bidNotification: function (data) { bidNotification: function (data) {
console.log(data); console.log(data);
var myObject = JSON.parse(data); var myObject = JSON.parse(data);
toastr.success(`<div class="item bidToast"><p>${myObject.bidPrice}</p><p>${myObject.productName}</p></div>`, "New bid arrived", { toastr.success(`<div class="item bidToast"><p>${myObject.currentPrice}</p><p>${myObject.productName}</p></div>`, "New bid arrived", {
"closeButton": true, "closeButton": true,
"positionClass": "toast-bottom-right", "positionClass": "toast-bottom-right",
"newestOnTop": true, "newestOnTop": true,
@ -81,7 +81,7 @@
}, },
openItemMessage: function (data) { openItemMessage: function (data) {
var myObject = JSON.parse(data); var myObject = JSON.parse(data);
toastr.success(`<div class="item bidToast"><p>${myObject.bidPrice}</p><p>${myObject.productName}</p></div>`, "Item auction is OPENED!", { toastr.success(`<div class="item bidToast"><p>${myObject.nextBidPrice}</p><p>${myObject.productName}</p></div>`, "Item auction is OPENED!", {
"closeButton": true, "closeButton": true,
"positionClass": "toast-bottom-right", "positionClass": "toast-bottom-right",
"newestOnTop": true, "newestOnTop": true,

View File

@ -12,7 +12,7 @@ public interface IProductToAuctionDtoBase : IMgModelDtoBase
public AuctionStatus AuctionStatus { get; set; } public AuctionStatus AuctionStatus { get; set; }
public decimal StartingPrice { get; set; } public decimal StartingPrice { get; set; }
public decimal BidPrice { get; set; } public decimal CurrentPrice { get; set; }
public int ProductAmount { get; set; } public int ProductAmount { get; set; }

View File

@ -14,7 +14,7 @@ public class ProductToAuctionDto : IProductToAuctionDto
public int WinnerCustomerId { get; set; } public int WinnerCustomerId { get; set; }
public AuctionStatus AuctionStatus { get; set; } public AuctionStatus AuctionStatus { get; set; }
public decimal StartingPrice { get; set; } public decimal StartingPrice { get; set; }
public decimal BidPrice { get; set; } public decimal CurrentPrice { get; set; }
public int ProductAmount { get; set; } public int ProductAmount { get; set; }
public int SortIndex { get; set; } public int SortIndex { get; set; }
@ -47,7 +47,7 @@ public class ProductToAuctionDto : IProductToAuctionDto
AuctionId = productToAuction.AuctionId; AuctionId = productToAuction.AuctionId;
AuctionStatus = productToAuction.AuctionStatus; AuctionStatus = productToAuction.AuctionStatus;
StartingPrice = productToAuction.StartingPrice; StartingPrice = productToAuction.StartingPrice;
BidPrice = productToAuction.BidPrice; CurrentPrice = productToAuction.CurrentPrice;
ProductAmount = productToAuction.ProductAmount; ProductAmount = productToAuction.ProductAmount;
} }
@ -60,7 +60,7 @@ public class ProductToAuctionDto : IProductToAuctionDto
mainEntity.AuctionId = AuctionId; mainEntity.AuctionId = AuctionId;
mainEntity.AuctionStatus = AuctionStatus; mainEntity.AuctionStatus = AuctionStatus;
mainEntity.StartingPrice = StartingPrice; mainEntity.StartingPrice = StartingPrice;
mainEntity.BidPrice = BidPrice; mainEntity.CurrentPrice = CurrentPrice;
mainEntity.ProductAmount = ProductAmount; mainEntity.ProductAmount = ProductAmount;
return mainEntity; return mainEntity;

View File

@ -19,7 +19,7 @@ public partial class ProductToAuctionMapping : MgEntityBase, IProductToAuctionMa
public AuctionStatus AuctionStatus { get; set; } public AuctionStatus AuctionStatus { get; set; }
public decimal StartingPrice { get; set; } public decimal StartingPrice { get; set; }
public decimal BidPrice { get; set; } public decimal CurrentPrice { get; set; }
public int ProductAmount { get; set; } = 1; public int ProductAmount { get; set; } = 1;
public int SortIndex { get; set; } public int SortIndex { get; set; }

View File

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

View File

@ -15,7 +15,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
public class BidNotificationMessage : AuctionNotificationBase public class BidNotificationMessage : AuctionNotificationBase
{ {
public string ProductName { get; set; } public string ProductName { get; set; }
public decimal BidPrice { get; set; } public decimal CurrentPrice { get; set; }
public decimal NextBidPrice { get; set; } public decimal NextBidPrice { get; set; }
public decimal NextStepAmount { get; set; } public decimal NextStepAmount { get; set; }

View File

@ -110,16 +110,16 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
switch (auctionProductStatusRequest.AuctionStatus) switch (auctionProductStatusRequest.AuctionStatus)
{ {
case AuctionStatus.Sold:
productToAuction.AuctionStatus = productToAuction.CurrentPrice == productToAuction.StartingPrice ? AuctionStatus.NotSold : AuctionStatus.Sold;
break;
case AuctionStatus.NotSold:
_logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); auctionProductStatusRequest.AuctionStatus == AuctionStatus.NotSold");
break;
case AuctionStatus.FirstWarning: case AuctionStatus.FirstWarning:
productToAuction.AuctionStatus = AuctionStatus.FirstWarning; //AuctionStatus.Active | AuctionStatus.FirstWarning;
break;
case AuctionStatus.SecondWarning: case AuctionStatus.SecondWarning:
productToAuction.AuctionStatus = AuctionStatus.SecondWarning; //AuctionStatus.Active | AuctionStatus.SecondWarning;
break;
case AuctionStatus.None: case AuctionStatus.None:
case AuctionStatus.Active: case AuctionStatus.Active:
case AuctionStatus.SoldOut:
case AuctionStatus.NotSold:
default: default:
productToAuction.AuctionStatus = auctionProductStatusRequest.AuctionStatus; productToAuction.AuctionStatus = auctionProductStatusRequest.AuctionStatus;
break; break;
@ -205,7 +205,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
await _productService.UpdateProductAsync(product); await _productService.UpdateProductAsync(product);
activeProductAuction.StartingPrice = product.OldPrice; activeProductAuction.StartingPrice = product.OldPrice;
activeProductAuction.BidPrice = product.Price; activeProductAuction.CurrentPrice = product.Price;
await _auctionService.UpdateProductToAuctionMappingAsync(activeProductAuction); await _auctionService.UpdateProductToAuctionMappingAsync(activeProductAuction);
var stepAmount = AuctionService.GetStepAmount(auctionBid.BidPrice); var stepAmount = AuctionService.GetStepAmount(auctionBid.BidPrice);
@ -219,7 +219,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
Data = new BidNotificationMessage(await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true)) Data = new BidNotificationMessage(await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true))
{ {
ProductName = auctionBid.ProductId.ToString(), ProductName = auctionBid.ProductId.ToString(),
BidPrice = auctionBid.BidPrice, CurrentPrice = auctionBid.BidPrice,
NextStepAmount = stepAmount, NextStepAmount = stepAmount,
NextBidPrice = nextBidPrice, NextBidPrice = nextBidPrice,
ToasterMessage = string.Empty, //TODO: - J. ToasterMessage = string.Empty, //TODO: - J.

View File

@ -28,7 +28,7 @@ public class ProductToAuctionMappingBuilder : NopEntityBuilder<ProductToAuctionM
.WithColumn(nameof(ProductToAuctionMapping.AuctionStatus)).AsByte().NotNullable() //enum??? - J. .WithColumn(nameof(ProductToAuctionMapping.AuctionStatus)).AsByte().NotNullable() //enum??? - J.
.WithColumn(nameof(ProductToAuctionMapping.StartingPrice)).AsInt32().NotNullable() .WithColumn(nameof(ProductToAuctionMapping.StartingPrice)).AsInt32().NotNullable()
.WithColumn(nameof(ProductToAuctionMapping.BidPrice)).AsInt32().NotNullable() .WithColumn(nameof(ProductToAuctionMapping.CurrentPrice)).AsInt32().NotNullable()
.WithColumn(nameof(ProductToAuctionMapping.ProductAmount)).AsInt32().NotNullable().WithDefaultValue(1) .WithColumn(nameof(ProductToAuctionMapping.ProductAmount)).AsInt32().NotNullable().WithDefaultValue(1)
.WithColumn(nameof(ProductToAuctionMapping.SortIndex)).AsInt32().NotNullable().WithDefaultValue(0) .WithColumn(nameof(ProductToAuctionMapping.SortIndex)).AsInt32().NotNullable().WithDefaultValue(0)

View File

@ -20,15 +20,13 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
[System.Text.Json.Serialization.JsonIgnore] [System.Text.Json.Serialization.JsonIgnore]
public ProductToAuctionDto FirstProductToAuction { get; set; } public ProductToAuctionDto FirstProductToAuction { get; set; }
public int ProductId { get; set; }
public int ProductToAuctionId { get; set; } public int ProductToAuctionId { get; set; }
public bool IsAdmin { get; set; } public bool IsAdmin { get; set; }
public bool IsGuest { get; set; } public bool IsGuest { get; set; }
public int AuctionId { get; set; } public int AuctionId { get; set; }
public bool AuctionClosed { get; set; } public bool AuctionClosed { get; set; }
public bool IsItemActive => AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning; public bool IsItemActive => FirstProductToAuction.IsActiveItem;
public AuctionStatus AuctionStatus { get; set; } public AuctionStatus AuctionStatus { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
public int CustomerId { get; set; } public int CustomerId { get; set; }
@ -45,7 +43,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
#region visible #region visible
public decimal LicitStep { get; set; } public decimal LicitStep { get; set; }
public decimal? CurrentPrice { get; set; } public decimal? CurrentPrice { get; set; }
public decimal BidPrice { get; set; } public decimal NextBidPrice { get; set; }
#endregion visible #endregion visible
@ -59,9 +57,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
AuctionId = auctionDto.Id; AuctionId = auctionDto.Id;
ProductId = FirstProductToAuction.ProductId; ProductId = FirstProductToAuction.ProductId;
ProductToAuctionId = FirstProductToAuction.Id; ProductToAuctionId = FirstProductToAuction.Id;
IsItemActive = FirstProductToAuction.IsActiveItem;
} }
} }
} }

View File

@ -290,7 +290,7 @@ public class AuctionService : IAuctionService
{ {
ProductId = productId, ProductId = productId,
StartingPrice = startingPrice, StartingPrice = startingPrice,
BidPrice = bidPrice, CurrentPrice = bidPrice,
ProductAmount = 1, ProductAmount = 1,
AuctionStatus = AuctionStatus.None, AuctionStatus = AuctionStatus.None,
AuctionId = auctionId AuctionId = auctionId

View File

@ -25,11 +25,11 @@
</div> </div>
<div> <div>
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)"> <button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)">
Bid @String.Format("{0:c}", Model.BidPrice) Bid @String.Format("{0:c}", Model.NextBidPrice)
</button> </button>
@* <button id="bidButton" class="btn btn-success"> @* <button id="bidButton" class="btn btn-success">
Bid @String.Format("{0:c}", Model.BidPrice) Bid @String.Format("{0:c}", Model.NextBidPrice)
</button> *@ </button> *@
</div> </div>
</div> </div>
@ -123,7 +123,7 @@
var bidMessage = { var bidMessage = {
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId, ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
AuctionId: bidBoxPageViewModel.AuctionId, AuctionId: bidBoxPageViewModel.AuctionId,
BidPrice: bidBoxPageViewModel.BidPrice, BidPrice: bidBoxPageViewModel.NextBidPrice,
ProductId: bidBoxPageViewModel.ProductId, ProductId: bidBoxPageViewModel.ProductId,
CustomerId: bidBoxPageViewModel.CustomerId CustomerId: bidBoxPageViewModel.CustomerId
}; };
@ -205,18 +205,18 @@
var licitStepElement = document.getElementById("licitStepText"); var licitStepElement = document.getElementById("licitStepText");
if (widgetPriceElement) { if (widgetPriceElement) {
widgetPriceElement.textContent = HUFFormatter.format(data.bidPrice); // Update the price widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount); licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
bidBoxPageViewModel.BidPrice = Number(data.bidPrice) + Number(data.nextStepAmount); bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.BidPrice); budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
// if (bidBoxPageViewModel.CustomerId == data.CustomerId) { // if (bidBoxPageViewModel.CustomerId == data.CustomerId) {
// } // }
console.log(`WidgetPrice updated to: ${data.bidPrice}, next bid is ${bidBoxPageViewModel.BidPrice}`); console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
budButtonElement.disabled = false; budButtonElement.disabled = false;
} else { } else {
console.warn("Element with ID 'WidgetPrice' not found in the DOM."); console.warn("Element with ID 'WidgetPrice' not found in the DOM.");