From 476f668ff6e4e3d709d8fbf014e24badc65a8697 Mon Sep 17 00:00:00 2001 From: Loretta Date: Fri, 22 Nov 2024 10:35:16 +0100 Subject: [PATCH] improvements --- .../Components/AuctionPublicViewComponent.cs | 7 ++- .../Content/Js/MgMessageHandler.js | 29 +++++++++ .../Domains/Dtos/ProductToAuctionDto.cs | 22 +++++-- .../Hubs/SignalRMessageHandler.cs | 56 +++-------------- .../Models/ProductBidBoxViewModel.cs | 3 +- .../Services/AuctionService.cs | 62 ++++++++++++++++++- .../Services/IAuctionService.cs | 6 +- .../Views/PublicProductBidBox.cshtml | 18 +++--- 8 files changed, 136 insertions(+), 67 deletions(-) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index 3570db0..1e7b08e 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -138,14 +138,15 @@ public class AuctionPublicViewComponent : NopViewComponent List productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id); AuctionStatus status = productToAuctionId.FirstOrDefault().AuctionStatus; - bool isActive = status.HasFlag(AuctionStatus.Active); - bool isFirstWarning = status.HasFlag(AuctionStatus.FirstWarning); + //bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning; + 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.IsItemActive = isActive; + productBidBoxViewModel.AuctionStatus = status; productBidBoxViewModel.WidgetZone = widgetZone; productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index 5fec22e..3207232 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -48,7 +48,36 @@ { refreshPublicBidBox(myObject); } + }, + ProductToAuctionStatusNotification: function (data) { + console.log(data); + var myObject = JSON.parse(data); + var auctionDto = myObject.auctionDto; + var productToAuctionDto = myObject.auctionDto.productToAuctionDtos[0]; + toastr.success(`

${productToAuctionDto.auctionStatus}

${productToAuctionDto.id}

`, "Status changed", { + "closeButton": true, + "positionClass": "toast-bottom-right", + "newestOnTop": true, + "progressBar": true, + "preventDuplicates": false, + "onclick": null, + "showDuration": "30000", + "hideDuration": "1000", + "timeOut": "5000", + "extendedTimeOut": "1000", + "showEasing": "swing", + "hideEasing": "linear", + "showMethod": animation, + "hideMethod": "fadeOut" + }); + $('.toast-success').css("background-color", "#4caf50"); + + // var publicProductBidBox = document.getElementById("publicProductBidBox"); + // if (publicProductBidBox) + // { + // refreshPublicBidBox(myObject); + // } }, openItemMessage: function (data) { var myObject = JSON.parse(data); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs index ed1a210..630b80d 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs @@ -1,6 +1,8 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos.Interfaces; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; +using Nop.Plugin.Misc.AuctionPlugin.Services; namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; @@ -16,18 +18,30 @@ public class ProductToAuctionDto : IProductToAuctionDto public int ProductAmount { get; set; } public int SortIndex { get; set; } + /// + /// EGYELŐRE NE HASZNÁLD!!! - J. + /// + public decimal StepAmount { get; set; } public List AuctionBidDtos { get; } = []; public bool IsActiveItem => AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning; - public ProductToAuctionDto() - { - } + public ProductToAuctionDto() { } + public ProductToAuctionDto(ProductToAuctionMapping productToAuction) : this(productToAuction, 0/*AuctionService.GetStepAmount(productToAuction.BidPrice)*/) { } - public ProductToAuctionDto(ProductToAuctionMapping productToAuction) + /// + /// + /// + /// + /// EGYELŐRE NE HASZNÁLD!!! - J. + public ProductToAuctionDto(ProductToAuctionMapping productToAuction, decimal stepAmount) : this() { if (productToAuction == null) return; + if (stepAmount > 0) StepAmount = stepAmount; + //else StepAmount = AuctionService.GetStepAmount(productToAuction.BidPrice); + + Id = productToAuction.Id; ProductId = productToAuction.ProductId; AuctionId = productToAuction.AuctionId; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs index 5aa9757..4728c79 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs @@ -53,9 +53,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs return; } + await _logger.InformationAsync($"SignalRMessageHandler.HandleMessage(); jsonData: {message.Data}"); + if (message.SenderId <= 0 || message.SenderId != (await _workContext.GetCurrentCustomerAsync()).Id) { - _logger.Error($"SignalRMessageHandler.HandleMessage(); message.SenderId <= 0 || message.SenderId != (await _workContext.GetCurrentCustomerAsync()).Id"); + _logger.Error($"SignalRMessageHandler.HandleMessage(); message.SenderId <= 0 || message.SenderId != (await _workContext.GetCurrentCustomerAsync()).Id; SenderId: {message.SenderId}"); return; } @@ -66,13 +68,13 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs await HandleBidRequest(message.SenderId, message.Data.JsonTo()); break; - case "OpenItemRequestMessage": + case "AuctionProductStatusRequest": await HandleProductToAuctionStatusChangedRequest(message.SenderId, message.Data.JsonTo()); break; // Add other message types here default: - await _logger.ErrorAsync("SignalRMessageHandler.HandleMessage(); Unknown message type"); + await _logger.ErrorAsync($"SignalRMessageHandler.HandleMessage(); Unknown message type; MessageType: {message.MessageType}"); break; } } @@ -95,7 +97,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs var auction = await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(auctionProductStatusRequest.ProductToAuctionId); if (auction == null || auction.Closed) { - _logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); auction == null || auction.Closed"); + _logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); auction == null || auction.Closed;"); return; } @@ -119,7 +121,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs case AuctionStatus.SoldOut: case AuctionStatus.NotSold: default: - auctionProductStatusRequest.AuctionStatus = auctionProductStatusRequest.AuctionStatus; + productToAuction.AuctionStatus = auctionProductStatusRequest.AuctionStatus; break; } @@ -206,7 +208,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs activeProductAuction.BidPrice = product.Price; await _auctionService.UpdateProductToAuctionMappingAsync(activeProductAuction); - var stepAmount = GetStepAmount(auctionBid.BidPrice); + var stepAmount = AuctionService.GetStepAmount(auctionBid.BidPrice); var nextBidPrice = auctionBid.BidPrice + stepAmount; //stepAmount = GetStepAmount(nextBidPrice); //Direkt van 2x, különben a sávváltásoknál lehet gond! - J. @@ -231,47 +233,5 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs _logger.Error($"SignalRMessageHandler.HandleBidRequest(); MessageHandling error: {ex}"); } } - - private static decimal GetStepAmount(decimal currentPrice) - { - return currentPrice switch - { - >= 0 and < 100000 => 1000, //Ezt csak hasraütésszerűen adtam meg!!! - J. - - //100 000 - 1 000 000 - >= 100000 and < 200000 => 10000, - >= 200000 and < 500000 => 20000, - >= 500000 and < 1000000 => 50000, - - //1 000 000 - 10 000 000 - >= 1000000 and < 2000000 => 100000, - >= 2000000 and < 5000000 => 200000, - >= 5000000 and < 10000000 => 500000, - - //10 000 000 - 100 000 000 - >= 10000000 and < 20000000 => 1000000, - >= 20000000 and < 50000000 => 2000000, - >= 50000000 and < 100000000 => 5000000, - - //100 000 000 - ~ - >= 100000000 and < 200000000 => 10000000, - _ => 20000000 - }; - - //100 000 Ft – 200 000 Ft között 10 000 Ft-tal - //200 000 Ft – 500 000 Ft között 20 000 Ft-tal - //500 000 Ft – 1 000 000 Ft között 50 000 Ft-tal - - //1 000 000 Ft – 2 000 000 Ft között 100 000 Ft-tal - //2 000 000 Ft – 5 000 000 Ft között 200 000 Ft-tal - //5 000 000 Ft – 10 000 000 Ft között 500 000 Ft-tal - - //10 000 000 Ft – 20 000 000 Ft között 1 000 000 Ft-tal - //20 000 000 Ft – 50 000 000 Ft között 2 000 000 Ft-tal - //50 000 000 Ft – 100 000 000 Ft között 5 000 000 Ft-tal - - //100 000 000 Ft – 200 000 000 Ft között 10 000 000 Ft-tal - //200 000 000 Ft fölött 20 000 000 Ft-tal - } } } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs index 21ced3e..caf850e 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs @@ -15,7 +15,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models public bool IsGuest { get; set; } public int AuctionId { get; set; } public bool AuctionClosed { get; set; } - public bool IsItemActive { get; set; } + public bool IsItemActive => AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning; + public AuctionStatus AuctionStatus { get; set; } public int ProductId { get; set; } public int CustomerId { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index bc8eb88..32fee14 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -5,6 +5,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Services.Logging; +using Org.BouncyCastle.Crypto; namespace Nop.Plugin.Misc.AuctionPlugin.Services; @@ -68,6 +69,48 @@ public class AuctionService : IAuctionService #region Methods + public static decimal GetStepAmount(decimal currentPrice) + { + return currentPrice switch + { + >= 0 and < 100000 => 10000, //Ezt csak hasraütésszerűen adtam meg!!! - J. + + //100 000 - 1 000 000 + >= 100000 and < 200000 => 10000, + >= 200000 and < 500000 => 20000, + >= 500000 and < 1000000 => 50000, + + //1 000 000 - 10 000 000 + >= 1000000 and < 2000000 => 100000, + >= 2000000 and < 5000000 => 200000, + >= 5000000 and < 10000000 => 500000, + + //10 000 000 - 100 000 000 + >= 10000000 and < 20000000 => 1000000, + >= 20000000 and < 50000000 => 2000000, + >= 50000000 and < 100000000 => 5000000, + + //100 000 000 - ~ + >= 100000000 and < 200000000 => 10000000, + _ => 20000000 + }; + + //100 000 Ft – 200 000 Ft között 10 000 Ft-tal + //200 000 Ft – 500 000 Ft között 20 000 Ft-tal + //500 000 Ft – 1 000 000 Ft között 50 000 Ft-tal + + //1 000 000 Ft – 2 000 000 Ft között 100 000 Ft-tal + //2 000 000 Ft – 5 000 000 Ft között 200 000 Ft-tal + //5 000 000 Ft – 10 000 000 Ft között 500 000 Ft-tal + + //10 000 000 Ft – 20 000 000 Ft között 1 000 000 Ft-tal + //20 000 000 Ft – 50 000 000 Ft között 2 000 000 Ft-tal + //50 000 000 Ft – 100 000 000 Ft között 5 000 000 Ft-tal + + //100 000 000 Ft – 200 000 000 Ft között 10 000 000 Ft-tal + //200 000 000 Ft fölött 20 000 000 Ft-tal + } + private async Task ValidateAuctionBid(AuctionBid auctionBid) { //auctionBid.CustomerId = (await _workContext.GetCurrentCustomerAsync()).Id; //elvileg megnézi cache-ben, csak utána DB-zik! - J. @@ -163,10 +206,25 @@ public class AuctionService : IAuctionService #endregion #region Dtots - public async Task GetAuctionDtoByIdAsync(int auctionId) + + public async Task GetAuctionDtoByIdAsync(int auctionId, bool widthProducts = false) { var auction = await _ctx.Auctions.GetByIdAsync(auctionId); - return auction == null ? null : new AuctionDto(auction); + if (auction == null) return null; + + var auctionDto = new AuctionDto(auction); + + if (widthProducts) + { + auctionDto.ProductToAuctionDtos.AddRange((await GetProductToAuctionDtosByAuctionId(auctionId))); + } + + return auctionDto; + } + + public async Task> GetProductToAuctionDtosByAuctionId(int auctionId) + { + return (await GetProductToAuctionsByAuctionIdAsync(auctionId)).Select(x => new ProductToAuctionDto(x)).ToList(); } public async Task GetAuctionDtoWithProductByIdAsync(int auctionId, int productId, bool activeProductOnly = false) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs index 7aa2160..81e1ae1 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs @@ -11,6 +11,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Services; /// public interface IAuctionService { + //decimal GetStepAmount(decimal currentPrice); + + /// /// Gets all bids /// @@ -38,7 +41,8 @@ public interface IAuctionService Task> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems = false); - Task GetAuctionDtoByIdAsync(int auctionId); + Task GetAuctionDtoByIdAsync(int auctionId, bool widthProducts = false); + Task> GetProductToAuctionDtosByAuctionId(int auctionId); Task GetAuctionDtoWithProductByIdAsync(int auctionId, int productId, bool activeProductOnly); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index e6730b0..760a512 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -1,4 +1,6 @@ -@model ProductBidBoxViewModel +@using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums +@using Nop.Web.Framework.TagHelpers.Shared +@model ProductBidBoxViewModel @* @inject IJsonHelper JsonHelper; *@ @* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@ @@ -22,7 +24,7 @@ @String.Format("{0:c}", Model.LicitStep)
- @* - - } @@ -65,7 +67,7 @@ // } else { - } @@ -175,7 +177,7 @@ // Create the message object var auctionMessage = { - ProductAuctionId: bidBoxPageViewModel.ProductToAuctionId, + ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId, AuctionStatus: auctionStatus };