productbidbox signalR update
This commit is contained in:
parent
169a4540c7
commit
c07e654730
|
|
@ -127,9 +127,12 @@ public class AuctionPublicViewComponent : NopViewComponent
|
|||
auctionId = valami.Id;
|
||||
}
|
||||
|
||||
var productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id);
|
||||
|
||||
productBidBoxViewModel.WidgetZone = widgetZone;
|
||||
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
|
||||
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
|
||||
productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id;
|
||||
productBidBoxViewModel.AuctionId = auctionId;
|
||||
productBidBoxViewModel.CustomerId = customer.Id;
|
||||
productBidBoxViewModel.ProductId = productDetailsModel.Id;
|
||||
|
|
|
|||
|
|
@ -39,9 +39,16 @@
|
|||
"hideMethod": "fadeOut"
|
||||
});
|
||||
$('.toast-success').css("background-color", "#4caf50");
|
||||
|
||||
const publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||
if (publicProductBidBox) {
|
||||
refreshPublicBidBox(data);
|
||||
}
|
||||
|
||||
},
|
||||
auctionUpdateAlternate: function (data) {
|
||||
const widgetPriceElement = document.getElementById("WidgetPrice");
|
||||
|
||||
if (widgetPriceElement) {
|
||||
widgetPriceElement.textContent = data.bidPrice; // Update the price
|
||||
console.log(`WidgetPrice updated to: ${data.bidPrice}`);
|
||||
|
|
@ -49,20 +56,25 @@
|
|||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
},
|
||||
auctionUpdate: function (data) {
|
||||
// Refresh the ViewComponent using AJAX
|
||||
$.ajax({
|
||||
url: '/Auction/RefreshAuctionWidget', // Controller endpoint
|
||||
method: 'GET',
|
||||
success: function (response) {
|
||||
//$('#auction-widget').html(response); // Update the DOM element
|
||||
console.log("Auction widget refreshed!");
|
||||
},
|
||||
error: function (error) {
|
||||
console.error("Error refreshing auction widget:", error);
|
||||
}
|
||||
});
|
||||
},
|
||||
//auctionUpdate: function (data) {
|
||||
// // Refresh the ViewComponent using AJAX
|
||||
// $.ajax({
|
||||
// url: '/Auction/RefreshAuctionWidget', // Controller endpoint
|
||||
// type: 'POST',
|
||||
// contentType: 'application/json',
|
||||
// data: JSON.stringify({
|
||||
// WidgetZone: data.WidgetZone,
|
||||
// ProductId: data.ProductId
|
||||
// }),
|
||||
// success: function (response) {
|
||||
// //$('#auction-widget').html(response); // Update the DOM element
|
||||
// console.log("Auction widget refreshed!");
|
||||
// },
|
||||
// error: function (error) {
|
||||
// console.error("Error refreshing auction widget:", error);
|
||||
// }
|
||||
// });
|
||||
//},
|
||||
|
||||
// Add more handlers as needed
|
||||
default: function (data) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// this message sends update to the clients. so it sends current (the already winner) price,
|
||||
/// sends the ACTUAL bidstep, so the new price, and next bid can be calculated on the client side
|
||||
/// </summary>
|
||||
public class BidNotificationMessage
|
||||
{
|
||||
public string ProductName { get; set; }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
|||
{
|
||||
public record ProductBidBoxViewModel: BaseNopModel
|
||||
{
|
||||
public int ProductToAuctionId { get; set; }
|
||||
public int AuctionId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int CustomerId { get; set; }
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@
|
|||
@inject IJsonHelper JsonHelper;
|
||||
|
||||
@* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
|
||||
<div class="bg-dark p-3">
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
<div id="publicProductBidBox" class="bg-dark p-3">
|
||||
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<div>
|
||||
|
|
@ -11,78 +15,70 @@
|
|||
@String.Format("{0:c}", Model.BasePrice)
|
||||
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Current Price:</strong>
|
||||
<span class="value">
|
||||
@String.Format("{0:c}", Model.CurrentPrice)
|
||||
@* @(decimal?.Round(Model.CurrentPrice, 2, MidpointRounding.AwayFromZero)) *@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Bid Step:</strong>
|
||||
<span class="value">@String.Format("{0:c}", Model.LicitStep)</span>
|
||||
</div>
|
||||
<div>
|
||||
<button id="bidButton" class="btn btn-success">
|
||||
@* Bid @(decimal?.Round(@Model.BidPrice, 2, MidpointRounding.AwayFromZero)) *@
|
||||
<button id="signalRBidButton" class="btn btn-success">
|
||||
Bid @String.Format("{0:c}", Model.BidPrice)
|
||||
</button>
|
||||
@* <button id="bidButton" class="btn btn-success">
|
||||
|
||||
Bid @String.Format("{0:c}", Model.BidPrice)
|
||||
</button> *@
|
||||
</div>
|
||||
</div>
|
||||
<button id="signalRBidButton" class="btn btn-success">
|
||||
SignalRBidButton
|
||||
</button>
|
||||
|
||||
|
||||
<button id="testButton" class="btn btn-success">
|
||||
@* <button id="testButton" class="btn btn-success">
|
||||
TestButton
|
||||
</button>
|
||||
</button> *@
|
||||
|
||||
<div id="bidFeedback" class="mt-3"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
var pageViewModel = undefined;
|
||||
$(document).ready(function () {
|
||||
|
||||
|
||||
|
||||
var pageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
pageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
console.log(pageViewModel);
|
||||
console.log(pageViewModel.WidgetZone);
|
||||
console.log(typeof sendMessageToServer);
|
||||
|
||||
|
||||
$('#bidButton').click(function () {
|
||||
const bidPrice = $('#bidPrice').val();
|
||||
// $('#bidButton').click(function () {
|
||||
// const bidPrice = $('#bidPrice').val();
|
||||
|
||||
// Validate bid price
|
||||
if (!bidPrice || parseInt(bidPrice) < @Model.CurrentPrice + @Model.LicitStep) {
|
||||
$('#bidFeedback').text('Bid price must be at least the current price plus the licit step.')
|
||||
.addClass('text-danger');
|
||||
return;
|
||||
}
|
||||
// // Validate bid price
|
||||
// if (!bidPrice || parseInt(bidPrice) < @Model.CurrentPrice + @Model.LicitStep) {
|
||||
// $('#bidFeedback').text('Bid price must be at least the current price plus the licit step.')
|
||||
// .addClass('text-danger');
|
||||
// return;
|
||||
// }
|
||||
|
||||
// AJAX POST to send the bid
|
||||
$.ajax({
|
||||
url: '/Auction/PlaceBid', // Ensure this endpoint exists in your controller
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
auctionId: pageViewModel.AuctionId,
|
||||
bidPrice: bidPrice,
|
||||
customerId: dataObject.CustomerId,
|
||||
productId: dataObject.ProductId
|
||||
}),
|
||||
success: function (response) {
|
||||
$('#bidFeedback').text(response.message).removeClass('text-danger').addClass('text-success');
|
||||
},
|
||||
error: function (xhr) {
|
||||
$('#bidFeedback').text('Failed to place bid: ' + xhr.responseText)
|
||||
.addClass('text-danger');
|
||||
}
|
||||
});
|
||||
});
|
||||
// // AJAX POST to send the bid
|
||||
// $.ajax({
|
||||
// url: '/Auction/PlaceBid', // Ensure this endpoint exists in your controller
|
||||
// type: 'POST',
|
||||
// contentType: 'application/json',
|
||||
// data: JSON.stringify({
|
||||
// auctionId: pageViewModel.AuctionId,
|
||||
// bidPrice: bidPrice,
|
||||
// customerId: dataObject.CustomerId,
|
||||
// productId: dataObject.ProductId
|
||||
// }),
|
||||
// success: function (response) {
|
||||
// $('#bidFeedback').text(response.message).removeClass('text-danger').addClass('text-success');
|
||||
// },
|
||||
// error: function (xhr) {
|
||||
// $('#bidFeedback').text('Failed to place bid: ' + xhr.responseText)
|
||||
// .addClass('text-danger');
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
|
||||
$("#signalRBidButton").on("click", function () {
|
||||
var bidMessage = {
|
||||
|
|
@ -93,32 +89,42 @@
|
|||
};
|
||||
|
||||
sendMessageToServer("BidRequestMessage", bidMessage);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
$('#testButton').click(function () {
|
||||
$.ajax({
|
||||
url: '/Auction/RefreshAuctionWidget', // Controller endpoint
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
WidgetZone: pageViewModel.WidgetZone,
|
||||
ProductId: pageViewModel.ProductId
|
||||
}),
|
||||
success: function (response) {
|
||||
//$('#auction-widget').html(response); // Update the DOM element
|
||||
console.log("Auction widget refreshed!");
|
||||
},
|
||||
error: function (error) {
|
||||
console.error("Error refreshing auction widget:", error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
function refreshPublicBidBox(data) {
|
||||
// $.ajax({
|
||||
// url: '/Auction/RefreshAuctionWidget', // Controller endpoint
|
||||
// type: 'POST',
|
||||
// contentType: 'application/json',
|
||||
// data: JSON.stringify({
|
||||
// WidgetZone: pageViewModel.WidgetZone,
|
||||
// ProductId: pageViewModel.ProductId
|
||||
// }),
|
||||
// success: function (response) {
|
||||
// //$('#auction-widget').html(response); // Update the DOM element
|
||||
// console.log("Auction widget refreshed!");
|
||||
// },
|
||||
// error: function (error) {
|
||||
// console.error("Error refreshing auction widget:", error);
|
||||
// }
|
||||
// });
|
||||
|
||||
const widgetPriceElement = document.getElementById("price-value-"+pageViewModel.ProductId);
|
||||
const budButtonelement = document.getElementById("signalRBidButton");
|
||||
|
||||
if (widgetPriceElement) {
|
||||
widgetPriceElement.textContent = data.bidPrice; // Update the price
|
||||
budButtonElement.textContent = data.bidPrice + data.nextStep;
|
||||
console.log(`WidgetPrice updated to: ${data.bidPrice}`);
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue