improvements
This commit is contained in:
parent
9086ec28c9
commit
476f668ff6
|
|
@ -138,14 +138,15 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
List<ProductToAuctionMapping> 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;
|
||||
|
|
|
|||
|
|
@ -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(`<div class="item bidToast"><p>${productToAuctionDto.auctionStatus}</p><p>${productToAuctionDto.id}</p></div>`, "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);
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// EGYELŐRE NE HASZNÁLD!!! - J.
|
||||
/// </summary>
|
||||
public decimal StepAmount { get; set; }
|
||||
public List<AuctionBidDto> 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)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="productToAuction"></param>
|
||||
/// <param name="stepAmount">EGYELŐRE NE HASZNÁLD!!! - J.</param>
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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<AuctionBidRequest>());
|
||||
break;
|
||||
|
||||
case "OpenItemRequestMessage":
|
||||
case "AuctionProductStatusRequest":
|
||||
await HandleProductToAuctionStatusChangedRequest(message.SenderId, message.Data.JsonTo<AuctionProductStatusRequest>());
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
|
|
|
|||
|
|
@ -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<bool> 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<AuctionDto> GetAuctionDtoByIdAsync(int auctionId)
|
||||
|
||||
public async Task<AuctionDto> 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<List<ProductToAuctionDto>> GetProductToAuctionDtosByAuctionId(int auctionId)
|
||||
{
|
||||
return (await GetProductToAuctionsByAuctionIdAsync(auctionId)).Select(x => new ProductToAuctionDto(x)).ToList();
|
||||
}
|
||||
|
||||
public async Task<AuctionDto> GetAuctionDtoWithProductByIdAsync(int auctionId, int productId, bool activeProductOnly = false)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Services;
|
|||
/// </summary>
|
||||
public interface IAuctionService
|
||||
{
|
||||
//decimal GetStepAmount(decimal currentPrice);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets all bids
|
||||
/// </summary>
|
||||
|
|
@ -38,7 +41,8 @@ public interface IAuctionService
|
|||
|
||||
Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems = false);
|
||||
|
||||
Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId);
|
||||
Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId, bool widthProducts = false);
|
||||
Task<List<ProductToAuctionDto>> GetProductToAuctionDtosByAuctionId(int auctionId);
|
||||
|
||||
|
||||
Task<AuctionDto> GetAuctionDtoWithProductByIdAsync(int auctionId, int productId, bool activeProductOnly);
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
<span id="licitStepText" class="value">@String.Format("{0:c}", Model.LicitStep)</span>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button">
|
||||
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)">
|
||||
Bid @String.Format("{0:c}", Model.BidPrice)
|
||||
</button>
|
||||
@* <button id="bidButton" class="btn btn-success">
|
||||
|
|
@ -49,13 +51,13 @@
|
|||
@{
|
||||
if(Model.IsItemActive)
|
||||
{
|
||||
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button">
|
||||
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" disabled="@((byte)Model.AuctionStatus >= (byte)AuctionStatus.FirstWarning))">
|
||||
First warning
|
||||
</button>
|
||||
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button">
|
||||
First warning
|
||||
<button id="signalRSecondWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" disabled="@((byte)Model.AuctionStatus >= (byte)AuctionStatus.SecondWarning))">
|
||||
Second warning
|
||||
</button>
|
||||
<button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
|
||||
<button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
|
||||
Deactivate item
|
||||
</button>
|
||||
}
|
||||
|
|
@ -65,7 +67,7 @@
|
|||
// }
|
||||
else
|
||||
{
|
||||
<button id="signalROpenItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
|
||||
<button id="signalROpenItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
|
||||
Activate item
|
||||
</button>
|
||||
}
|
||||
|
|
@ -175,7 +177,7 @@
|
|||
|
||||
// Create the message object
|
||||
var auctionMessage = {
|
||||
ProductAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionStatus: auctionStatus
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue