From 69a6cd5053908470370fbcdd88b746485d4f4a79 Mon Sep 17 00:00:00 2001 From: Loretta Date: Fri, 22 Nov 2024 11:31:45 +0100 Subject: [PATCH] fixes --- .../Controllers/AnnouncementController.cs | 5 +++-- .../Components/AuctionPublicViewComponent.cs | 19 +++++++++---------- .../Content/Js/LiveAnnouncement.js | 2 +- .../Content/Js/MgMessageHandler.js | 4 ++-- .../Interfaces/IProductToAuctionDtoBase.cs | 2 +- .../Domains/Dtos/ProductToAuctionDto.cs | 6 +++--- .../Entities/ProductToAuctionMapping.cs | 2 +- .../Domains/Enums/AuctionStatus.cs | 2 +- .../Hubs/Messages/BidNotificationMessage.cs | 2 +- .../Hubs/SignalRMessageHandler.cs | 16 ++++++++-------- .../Builders/ProductToAuctionBuilder.cs | 2 +- .../Models/ProductBidBoxViewModel.cs | 9 ++------- .../Services/AuctionService.cs | 2 +- .../Views/PublicProductBidBox.cshtml | 14 +++++++------- 14 files changed, 41 insertions(+), 46 deletions(-) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AnnouncementController.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AnnouncementController.cs index 420e87f..228bab1 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AnnouncementController.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AnnouncementController.cs @@ -120,8 +120,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers { //AuctionDto = TODO: ??? - J. ProductName = viewModel.ProductName, - BidPrice = viewModel.BidPrice, - NextStepAmount = viewModel.NextStepAmount + CurrentPrice = viewModel.BidPrice, + NextStepAmount = viewModel.NextStepAmount, + NextBidPrice = viewModel.BidPrice + viewModel.NextStepAmount }.ToJson() }; var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented, diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index f25c9fe..a773500 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -105,27 +105,26 @@ public class AuctionPublicViewComponent : NopViewComponent var productId = productDetailsModel.Id; - var productToAuctionDtoMappings = await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId); - if (productToAuctionDtoMappings.Count == 0) + var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault(); + if (productToAuction == null) { return Content(string.Empty); } - var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuctionDtoMappings.FirstOrDefault()!.AuctionId)); - auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings); + var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId)); + auctionDto.ProductToAuctionDtos.Add(productToAuction); var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto); //List 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 isFirstWarning = status == AuctionStatus.FirstWarning; + //bool isFirstWarning = status == AuctionStatus.FirstWarning; productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer); productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer); - productBidBoxViewModel.AuctionClosed = auction.Closed; - //productBidBoxViewModel.IsItemActive = isActive; + productBidBoxViewModel.AuctionClosed = auctionDto.Closed; productBidBoxViewModel.AuctionStatus = status; productBidBoxViewModel.WidgetZone = widgetZone; productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; @@ -134,8 +133,8 @@ public class AuctionPublicViewComponent : NopViewComponent //productBidBoxViewModel.AuctionId = auctionId; productBidBoxViewModel.CustomerId = customer.Id; productBidBoxViewModel.ProductId = productDetailsModel.Id; - productBidBoxViewModel.LicitStep = 50000; //add calculation - productBidBoxViewModel.BidPrice = productDetailsModel.ProductPrice.PriceValue + productBidBoxViewModel.LicitStep; + productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation + productBidBoxViewModel.NextBidPrice = productToAuction.CurrentPrice + productBidBoxViewModel.LicitStep; return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js index 14ea32f..16806b7 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js @@ -7,7 +7,7 @@ Active: 1, FirstWarning: 2, SecondWarning: 4, - SoldOut: 8, + Sold: 8, NotSold: 16 }); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index 3207232..4b7fdd1 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -25,7 +25,7 @@ bidNotification: function (data) { console.log(data); var myObject = JSON.parse(data); - toastr.success(`

${myObject.bidPrice}

${myObject.productName}

`, "New bid arrived", { + toastr.success(`

${myObject.currentPrice}

${myObject.productName}

`, "New bid arrived", { "closeButton": true, "positionClass": "toast-bottom-right", "newestOnTop": true, @@ -81,7 +81,7 @@ }, openItemMessage: function (data) { var myObject = JSON.parse(data); - toastr.success(`

${myObject.bidPrice}

${myObject.productName}

`, "Item auction is OPENED!", { + toastr.success(`

${myObject.nextBidPrice}

${myObject.productName}

`, "Item auction is OPENED!", { "closeButton": true, "positionClass": "toast-bottom-right", "newestOnTop": true, diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs index c70f720..204d436 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs @@ -12,7 +12,7 @@ public interface IProductToAuctionDtoBase : IMgModelDtoBase public AuctionStatus AuctionStatus { get; set; } public decimal StartingPrice { get; set; } - public decimal BidPrice { get; set; } + public decimal CurrentPrice { get; set; } public int ProductAmount { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs index 630b80d..38f2a4e 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs @@ -14,7 +14,7 @@ public class ProductToAuctionDto : IProductToAuctionDto public int WinnerCustomerId { get; set; } public AuctionStatus AuctionStatus { get; set; } public decimal StartingPrice { get; set; } - public decimal BidPrice { get; set; } + public decimal CurrentPrice { get; set; } public int ProductAmount { get; set; } public int SortIndex { get; set; } @@ -47,7 +47,7 @@ public class ProductToAuctionDto : IProductToAuctionDto AuctionId = productToAuction.AuctionId; AuctionStatus = productToAuction.AuctionStatus; StartingPrice = productToAuction.StartingPrice; - BidPrice = productToAuction.BidPrice; + CurrentPrice = productToAuction.CurrentPrice; ProductAmount = productToAuction.ProductAmount; } @@ -60,7 +60,7 @@ public class ProductToAuctionDto : IProductToAuctionDto mainEntity.AuctionId = AuctionId; mainEntity.AuctionStatus = AuctionStatus; mainEntity.StartingPrice = StartingPrice; - mainEntity.BidPrice = BidPrice; + mainEntity.CurrentPrice = CurrentPrice; mainEntity.ProductAmount = ProductAmount; return mainEntity; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs index d337790..81cf5d4 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs @@ -19,7 +19,7 @@ public partial class ProductToAuctionMapping : MgEntityBase, IProductToAuctionMa public AuctionStatus AuctionStatus { 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 SortIndex { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Enums/AuctionStatus.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Enums/AuctionStatus.cs index 3e3cf4b..b53dd22 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Enums/AuctionStatus.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Enums/AuctionStatus.cs @@ -17,6 +17,6 @@ public enum AuctionStatus : byte Active = 1, FirstWarning = 2, SecondWarning = 4, - SoldOut = 8, + Sold = 8, NotSold = 16 } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs b/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs index 99927ae..910b641 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Hubs/Messages/BidNotificationMessage.cs @@ -15,7 +15,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages public class BidNotificationMessage : AuctionNotificationBase { public string ProductName { get; set; } - public decimal BidPrice { get; set; } + public decimal CurrentPrice { get; set; } public decimal NextBidPrice { get; set; } public decimal NextStepAmount { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs index 4728c79..436118a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs @@ -110,16 +110,16 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs 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: - productToAuction.AuctionStatus = AuctionStatus.FirstWarning; //AuctionStatus.Active | AuctionStatus.FirstWarning; - break; case AuctionStatus.SecondWarning: - productToAuction.AuctionStatus = AuctionStatus.SecondWarning; //AuctionStatus.Active | AuctionStatus.SecondWarning; - break; case AuctionStatus.None: case AuctionStatus.Active: - case AuctionStatus.SoldOut: - case AuctionStatus.NotSold: default: productToAuction.AuctionStatus = auctionProductStatusRequest.AuctionStatus; break; @@ -205,7 +205,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs await _productService.UpdateProductAsync(product); activeProductAuction.StartingPrice = product.OldPrice; - activeProductAuction.BidPrice = product.Price; + activeProductAuction.CurrentPrice = product.Price; await _auctionService.UpdateProductToAuctionMappingAsync(activeProductAuction); 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)) { ProductName = auctionBid.ProductId.ToString(), - BidPrice = auctionBid.BidPrice, + CurrentPrice = auctionBid.BidPrice, NextStepAmount = stepAmount, NextBidPrice = nextBidPrice, ToasterMessage = string.Empty, //TODO: - J. diff --git a/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs b/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs index 98d75e1..e03a951 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs @@ -28,7 +28,7 @@ public class ProductToAuctionMappingBuilder : NopEntityBuilder AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning; + public bool IsItemActive => FirstProductToAuction.IsActiveItem; public AuctionStatus AuctionStatus { get; set; } public int ProductId { get; set; } public int CustomerId { get; set; } @@ -45,7 +43,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models #region visible public decimal LicitStep { get; set; } public decimal? CurrentPrice { get; set; } - public decimal BidPrice { get; set; } + public decimal NextBidPrice { get; set; } #endregion visible @@ -59,9 +57,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models AuctionId = auctionDto.Id; ProductId = FirstProductToAuction.ProductId; ProductToAuctionId = FirstProductToAuction.Id; - IsItemActive = FirstProductToAuction.IsActiveItem; } - - } } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index 32fee14..309ecee 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -290,7 +290,7 @@ public class AuctionService : IAuctionService { ProductId = productId, StartingPrice = startingPrice, - BidPrice = bidPrice, + CurrentPrice = bidPrice, ProductAmount = 1, AuctionStatus = AuctionStatus.None, AuctionId = auctionId diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index 760a512..c7ef3cc 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -25,11 +25,11 @@
@* *@
@@ -123,7 +123,7 @@ var bidMessage = { ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId, AuctionId: bidBoxPageViewModel.AuctionId, - BidPrice: bidBoxPageViewModel.BidPrice, + BidPrice: bidBoxPageViewModel.NextBidPrice, ProductId: bidBoxPageViewModel.ProductId, CustomerId: bidBoxPageViewModel.CustomerId }; @@ -205,18 +205,18 @@ var licitStepElement = document.getElementById("licitStepText"); 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); - 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) { // } - 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; } else { console.warn("Element with ID 'WidgetPrice' not found in the DOM.");