merge
This commit is contained in:
commit
d7dffd1485
|
|
@ -118,8 +118,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
|
||||||
Data = new BidNotificationMessage
|
Data = new BidNotificationMessage
|
||||||
{
|
{
|
||||||
ProductName = viewModel.ProductName,
|
ProductName = viewModel.ProductName,
|
||||||
BidPrice = viewModel.BidPrice,
|
BidPrice = viewModel.BidPrice.ToString(),
|
||||||
NextStepAmount = viewModel.NextStepAmount
|
NextStepAmount = viewModel.NextStepAmount.ToString()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,
|
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models
|
||||||
[NopResourceDisplayName("Name")]
|
[NopResourceDisplayName("Name")]
|
||||||
public string ProductName { get; set; }
|
public string ProductName { get; set; }
|
||||||
|
|
||||||
public int BidPrice { get; set; }
|
public decimal BidPrice { get; set; }
|
||||||
|
|
||||||
public int NextStepAmount { get; set; }
|
public decimal NextStepAmount { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Nop.Core;
|
using Nop.Core;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||||
using Nop.Services.Cms;
|
using Nop.Services.Cms;
|
||||||
using Nop.Services.Common;
|
using Nop.Services.Common;
|
||||||
using Nop.Services.Logging;
|
using Nop.Services.Logging;
|
||||||
|
|
@ -18,6 +21,7 @@ public class AuctionPublicViewComponent : NopViewComponent
|
||||||
protected readonly IGenericAttributeService _genericAttributeService;
|
protected readonly IGenericAttributeService _genericAttributeService;
|
||||||
protected readonly IWidgetPluginManager _widgetPluginManager;
|
protected readonly IWidgetPluginManager _widgetPluginManager;
|
||||||
protected readonly IWorkContext _workContext;
|
protected readonly IWorkContext _workContext;
|
||||||
|
protected readonly AuctionService _auctionService;
|
||||||
protected readonly AuctionSettings _auctionSettings;
|
protected readonly AuctionSettings _auctionSettings;
|
||||||
protected readonly ILogger _logger;
|
protected readonly ILogger _logger;
|
||||||
|
|
||||||
|
|
@ -29,6 +33,7 @@ public class AuctionPublicViewComponent : NopViewComponent
|
||||||
IGenericAttributeService genericAttributeService,
|
IGenericAttributeService genericAttributeService,
|
||||||
IWidgetPluginManager widgetPluginManager,
|
IWidgetPluginManager widgetPluginManager,
|
||||||
IWorkContext workContext,
|
IWorkContext workContext,
|
||||||
|
AuctionService auctionService,
|
||||||
AuctionSettings auctionSettings,
|
AuctionSettings auctionSettings,
|
||||||
ILogger logger)
|
ILogger logger)
|
||||||
{
|
{
|
||||||
|
|
@ -36,6 +41,7 @@ public class AuctionPublicViewComponent : NopViewComponent
|
||||||
_genericAttributeService = genericAttributeService;
|
_genericAttributeService = genericAttributeService;
|
||||||
_widgetPluginManager = widgetPluginManager;
|
_widgetPluginManager = widgetPluginManager;
|
||||||
_workContext = workContext;
|
_workContext = workContext;
|
||||||
|
_auctionService = auctionService;
|
||||||
_auctionSettings = auctionSettings;
|
_auctionSettings = auctionSettings;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
@ -89,9 +95,42 @@ public class AuctionPublicViewComponent : NopViewComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
await _logger.InformationAsync("WidgetViewComponent called II");
|
await _logger.InformationAsync("WidgetViewComponent called II");
|
||||||
|
|
||||||
|
//is it under Auction?
|
||||||
|
|
||||||
|
List<ProductToAuctionMapping> auctionIds = await _auctionService.GetProductToAuctionsByProductIdAsync(productDetailsModel.Id);
|
||||||
|
int auctionId = 0;
|
||||||
|
if(auctionIds == null || auctionIds.Count == 0)
|
||||||
|
{
|
||||||
|
return Content(string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auctionIds.Count > 1)
|
||||||
|
{
|
||||||
|
List<AuctionDto> openAuctionList = [];
|
||||||
|
|
||||||
|
//we have more auctions so we return the closest open
|
||||||
|
foreach (var auctionMapping in auctionIds)
|
||||||
|
{
|
||||||
|
var auction = await _auctionService.GetAuctionDtoByIdAsync(auctionMapping.AuctionId);
|
||||||
|
if (!auction.Closed)
|
||||||
|
{
|
||||||
|
openAuctionList.Add(auction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//first auction that started or strats not earlier than yesterday
|
||||||
|
auctionId = openAuctionList.Where(x => x.StartDateUtc > DateTime.UtcNow.AddDays(-1)).OrderBy(x => x.StartDateUtc).FirstOrDefault().Id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var valami = await _auctionService.GetAuctionDtoByIdAsync(auctionIds.FirstOrDefault().AuctionId);
|
||||||
|
auctionId = valami.Id;
|
||||||
|
}
|
||||||
|
|
||||||
productBidBoxViewModel.WidgetZone = widgetZone;
|
productBidBoxViewModel.WidgetZone = widgetZone;
|
||||||
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
|
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
|
||||||
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
|
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
|
||||||
|
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 = 50000; //add calculation
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,30 @@ $(function () {
|
||||||
}, 100000);
|
}, 100000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.onclose(function () {
|
connection.onclose(function () {
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.sendMessageToServer = function (messageType, data) {
|
||||||
|
var messageWrapper = {
|
||||||
|
MessageType: messageType,
|
||||||
|
Data: data
|
||||||
|
};
|
||||||
|
|
||||||
|
connection.invoke("ReceiveMessageFromClient", messageWrapper)
|
||||||
|
.then(() => {
|
||||||
|
console.log("Message successfully sent to the server.");
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error("Error sending message to the server:", err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Function to send a message to the server
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,5 @@ public class AuctionDbTable: MgDbTableBase<Auction>
|
||||||
{
|
{
|
||||||
return GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default);
|
return GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -17,4 +17,9 @@ public class ProductToAuctionDbTable: MgDbTableBase<ProductToAuctionMapping>
|
||||||
{
|
{
|
||||||
return Table.Where(x => x.AuctionId == auctionId && x.ProductId == productId);
|
return Table.Where(x => x.AuctionId == auctionId && x.ProductId == productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IQueryable<ProductToAuctionMapping> GetByProductId(int productId)
|
||||||
|
{
|
||||||
|
return Table.Where(x => x.ProductId == productId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,7 +10,7 @@ public class AuctionBidDto : IAuctionBidDto
|
||||||
public int CustomerId { get; set; }
|
public int CustomerId { get; set; }
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
public bool IsWinner { get; set; }
|
public bool IsWinner { get; set; }
|
||||||
public int BidPrice { get; set; }
|
public decimal BidPrice { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public AuctionBidDto()
|
public AuctionBidDto()
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ public interface IAuctionBidDtoBase : IMgModelDtoBase
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
public bool IsWinner { get; set; }
|
public bool IsWinner { get; set; }
|
||||||
public int BidPrice { get; set; }
|
public decimal BidPrice { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
public bool IsWinner { get; set; }
|
public bool IsWinner { get; set; }
|
||||||
public int BidPrice { get; set; }
|
public decimal BidPrice { get; set; }
|
||||||
|
|
||||||
[SkipValuesOnUpdate]
|
[SkipValuesOnUpdate]
|
||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -2,29 +2,36 @@
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces;
|
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
|
||||||
using Nop.Services.Logging;
|
using Nop.Services.Logging;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Nop.Web.Models.Media;
|
||||||
|
using Nop.Services.Catalog;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
{
|
{
|
||||||
|
|
||||||
public class AuctionHub : Hub<IAuctionHubClient>
|
public class AuctionHub : Hub<IAuctionHubClient>
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
protected readonly SignalRMessageHandler _signalRMessageHandler;
|
||||||
private IAuctionService _auctionService;
|
|
||||||
|
ILogger _logger;
|
||||||
//HubCallerContext _hubCallerContext;
|
//HubCallerContext _hubCallerContext;
|
||||||
|
|
||||||
public AuctionHub(IAuctionService auctionService, ILogger logger)
|
public AuctionHub(ILogger logger, SignalRMessageHandler signalRMessageHandler)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_auctionService = auctionService;
|
_signalRMessageHandler = signalRMessageHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnConnectedAsync()
|
public override async Task OnConnectedAsync()
|
||||||
{
|
{
|
||||||
|
|
||||||
//await _logger.InformationAsync($"Caller connected: id{_hubCallerContext.ConnectionId}");
|
//await _logger.InformationAsync($"Caller connected: id{_hubCallerContext.ConnectionId}");
|
||||||
var userId = Context.ConnectionId;
|
var userId = Context.ConnectionId;
|
||||||
await _logger.InformationAsync($"Caller connected with id: {userId}");
|
await _logger.InformationAsync($"Caller connected with id: {userId}");
|
||||||
|
|
@ -33,12 +40,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
{
|
{
|
||||||
await _logger.InformationAsync($"Caller connected with name: {userName}");
|
await _logger.InformationAsync($"Caller connected with name: {userName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
await base.OnConnectedAsync();
|
await base.OnConnectedAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ReceiveMessageFromClient(string message)
|
public async Task ReceiveRegularMessageFromClient(string message)
|
||||||
{
|
{
|
||||||
await _logger.InformationAsync(message);
|
await _logger.InformationAsync(message);
|
||||||
// Broadcast the message received from the client to all clients
|
// Broadcast the message received from the client to all clients
|
||||||
|
|
@ -47,15 +53,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
//await _signalRservice.TestHub();
|
//await _signalRservice.TestHub();
|
||||||
}
|
}
|
||||||
|
|
||||||
//public async Task Send(string announcement)
|
public async Task ReceiveMessageFromClient(MessageWrapper message)
|
||||||
//{
|
|
||||||
// await _logger.InformationAsync($" Hub Send method called with messgae: {announcement}");
|
|
||||||
// await Clients.All.SendAsync("send", announcement);
|
|
||||||
//}
|
|
||||||
|
|
||||||
public async Task SendPriceToUsers(string message)
|
|
||||||
{
|
{
|
||||||
await Clients.All.SendPrice(message); //SendAsync(nameof(IAuctionHubClient.SendPrice), message);
|
// Log the message type and data
|
||||||
|
await _logger.InformationAsync($"Received message of type: {message.MessageType}");
|
||||||
|
await _signalRMessageHandler.HandleMessage(message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
|
||||||
public class BidNotificationMessage
|
public class BidNotificationMessage
|
||||||
{
|
{
|
||||||
public string ProductName { get; set; }
|
public string ProductName { get; set; }
|
||||||
public int BidPrice { get; set; }
|
public string BidPrice { get; set; }
|
||||||
public int NextStepAmount { get; set; }
|
public string NextStepAmount { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||||
|
using Nop.Services.Catalog;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Nop.Services.Logging;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
|
{
|
||||||
|
public class SignalRMessageHandler
|
||||||
|
{
|
||||||
|
protected readonly ILogger _logger;
|
||||||
|
protected readonly IProductService _productService;
|
||||||
|
protected readonly AuctionService _auctionService;
|
||||||
|
private IHubContext<AuctionHub> _hubContext;
|
||||||
|
|
||||||
|
public SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_productService = productService;
|
||||||
|
_auctionService = auctionService;
|
||||||
|
_hubContext = hubContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task HandleMessage(MessageWrapper message)
|
||||||
|
{
|
||||||
|
switch (message.MessageType)
|
||||||
|
{
|
||||||
|
case "BidRequestMessage":
|
||||||
|
await HandleBidRequest(message.Data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Add other message types here
|
||||||
|
default:
|
||||||
|
await _logger.ErrorAsync("Unknown message type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleBidRequest(object data)
|
||||||
|
{
|
||||||
|
AuctionBidRequest bidRequestMessage = new AuctionBidRequest();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var a = JsonConvert.DeserializeObject<AuctionBidRequest>(data.ToString());
|
||||||
|
//var b = (message.Data as JObject)?.ToObject<AuctionBidRequest>();
|
||||||
|
if (a == null)
|
||||||
|
{
|
||||||
|
await _logger.InformationAsync("Deserialization returned null. Message data might not match the expected structure.");
|
||||||
|
}
|
||||||
|
bidRequestMessage = a;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await _logger.ErrorAsync("Error during deserialization of AuctionBidRequest", ex);
|
||||||
|
}
|
||||||
|
//AuctionBidRequest bidRequestMessage = new AuctionBidRequest();
|
||||||
|
|
||||||
|
if (bidRequestMessage != null)
|
||||||
|
{
|
||||||
|
await _logger.InformationAsync($"Bid received: - Auction:{bidRequestMessage.AuctionId} Product: {bidRequestMessage.ProductId} - Bid: {bidRequestMessage.BidPrice} - Customer: {bidRequestMessage.CustomerId}");
|
||||||
|
//get product
|
||||||
|
|
||||||
|
var product = await _productService.GetProductByIdAsync(Convert.ToInt32(bidRequestMessage.ProductId));
|
||||||
|
|
||||||
|
if (product != null)
|
||||||
|
{
|
||||||
|
//validate the bidprice amount
|
||||||
|
|
||||||
|
|
||||||
|
//set new price
|
||||||
|
product.Price = Convert.ToDecimal(bidRequestMessage.BidPrice);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ProductToAuctionMapping> mapping = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(Convert.ToInt32(bidRequestMessage.AuctionId), Convert.ToInt32(bidRequestMessage.ProductId));
|
||||||
|
|
||||||
|
|
||||||
|
AuctionBid auctionBid = new AuctionBid();
|
||||||
|
|
||||||
|
auctionBid.ProductId = Convert.ToInt32(bidRequestMessage.ProductId);
|
||||||
|
auctionBid.CustomerId = Convert.ToInt32(bidRequestMessage.CustomerId);
|
||||||
|
auctionBid.BidPrice = Convert.ToDecimal(bidRequestMessage.BidPrice);
|
||||||
|
auctionBid.ProductAuctionMappingId = mapping.FirstOrDefault().Id;
|
||||||
|
|
||||||
|
//save bid
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = _auctionService.InsertBidAsync(auctionBid);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error($"MessageHandling error: {ex.ToString()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
//update product
|
||||||
|
|
||||||
|
await _productService.UpdateProductAsync(product);
|
||||||
|
|
||||||
|
// Optionally broadcast to all clients
|
||||||
|
var bid = new MessageWrapper
|
||||||
|
{
|
||||||
|
MessageType = "bidNotification",
|
||||||
|
Data = new BidNotificationMessage
|
||||||
|
{
|
||||||
|
ProductName = bidRequestMessage.ProductId,
|
||||||
|
BidPrice = bidRequestMessage.BidPrice,
|
||||||
|
NextStepAmount = "50000"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,
|
||||||
|
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }
|
||||||
|
);
|
||||||
|
|
||||||
|
await _hubContext.Clients.All.SendAsync("send", jsonMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -65,6 +65,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure
|
||||||
services.AddScoped<AuctionDbContext>();
|
services.AddScoped<AuctionDbContext>();
|
||||||
|
|
||||||
services.AddScoped<MyProductModelFactory>();
|
services.AddScoped<MyProductModelFactory>();
|
||||||
|
services.AddScoped<SignalRMessageHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
||||||
{
|
{
|
||||||
internal class AuctionBidRequest
|
public class AuctionBidRequest
|
||||||
{
|
{
|
||||||
public decimal BidPrice { get; set; }
|
public string AuctionId { get; set; }
|
||||||
public int ProductId { get; set; }
|
public string BidPrice { get; set; }
|
||||||
public int CustomerId { get; set; }
|
public string ProductId { get; set; }
|
||||||
|
public string CustomerId { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
||||||
{
|
{
|
||||||
public record ProductBidBoxViewModel: BaseNopModel
|
public record ProductBidBoxViewModel: BaseNopModel
|
||||||
{
|
{
|
||||||
|
public int AuctionId { get; set; }
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
public int CustomerId { get; set; }
|
public int CustomerId { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,11 @@ public class AuctionService : IAuctionService
|
||||||
/// <param name="shortTermCacheManager">Short term cache manager</param>
|
/// <param name="shortTermCacheManager">Short term cache manager</param>
|
||||||
/// <param name="staticCacheManager">Cache manager</param>
|
/// <param name="staticCacheManager">Cache manager</param>
|
||||||
public AuctionService(
|
public AuctionService(
|
||||||
AuctionDbContext ctx,
|
AuctionDbContext ctx,
|
||||||
//IRepository<Auction> auctionRepository,
|
//IRepository<Auction> auctionRepository,
|
||||||
//IRepository<ProductToAuctionMapping> productToAuctionRepository,
|
//IRepository<ProductToAuctionMapping> productToAuctionRepository,
|
||||||
IShortTermCacheManager shortTermCacheManager,
|
IShortTermCacheManager shortTermCacheManager,
|
||||||
IStaticCacheManager staticCacheManager,
|
IStaticCacheManager staticCacheManager,
|
||||||
IWorkContext workContext,
|
IWorkContext workContext,
|
||||||
ILogger logger)
|
ILogger logger)
|
||||||
{
|
{
|
||||||
|
|
@ -201,7 +201,17 @@ public class AuctionService : IAuctionService
|
||||||
return auctionBid == null ? null : new AuctionBidDto(auctionBid);
|
return auctionBid == null ? null : new AuctionBidDto(auctionBid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
|
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
|
||||||
|
{
|
||||||
|
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId)
|
||||||
|
{
|
||||||
|
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId).ToListAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
|
||||||
{
|
{
|
||||||
var auction = await GetAuctionDtoByIdAsync(auctionId);
|
var auction = await GetAuctionDtoByIdAsync(auctionId);
|
||||||
if (auction == null)
|
if (auction == null)
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,11 @@ public interface IAuctionService
|
||||||
|
|
||||||
Task<IList<Auction>> GetAllAuctionsAsync();
|
Task<IList<Auction>> GetAllAuctionsAsync();
|
||||||
|
|
||||||
|
Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems = false);
|
||||||
|
|
||||||
Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId);
|
Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId);
|
||||||
|
|
||||||
|
|
||||||
Task<AuctionDto> GetAuctionDtoWithProductByIdAsync(int auctionId, int productId);
|
Task<AuctionDto> GetAuctionDtoWithProductByIdAsync(int auctionId, int productId);
|
||||||
|
|
||||||
Task<ProductToAuctionDto> GetProductToAuctionDtoByIdAsync(int productToAuctionId);
|
Task<ProductToAuctionDto> GetProductToAuctionDtoByIdAsync(int productToAuctionId);
|
||||||
|
|
@ -44,4 +47,9 @@ public interface IAuctionService
|
||||||
Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId);
|
Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId);
|
||||||
|
|
||||||
Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
|
Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
|
||||||
|
Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId);
|
||||||
|
|
||||||
|
Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId);
|
||||||
|
|
||||||
|
Task<bool> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,9 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</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
|
TestButton
|
||||||
|
|
@ -40,11 +42,16 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var pageViewModel = @Html.Raw(Json.Serialize(Model));
|
var pageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||||
console.log(pageViewModel);
|
console.log(pageViewModel);
|
||||||
console.log(pageViewModel.WidgetZone);
|
console.log(pageViewModel.WidgetZone);
|
||||||
|
console.log(typeof sendMessageToServer);
|
||||||
|
|
||||||
|
|
||||||
$('#bidButton').click(function () {
|
$('#bidButton').click(function () {
|
||||||
const bidPrice = $('#bidPrice').val();
|
const bidPrice = $('#bidPrice').val();
|
||||||
|
|
@ -62,6 +69,7 @@
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
|
auctionId: pageViewModel.AuctionId,
|
||||||
bidPrice: bidPrice,
|
bidPrice: bidPrice,
|
||||||
customerId: dataObject.CustomerId,
|
customerId: dataObject.CustomerId,
|
||||||
productId: dataObject.ProductId
|
productId: dataObject.ProductId
|
||||||
|
|
@ -75,6 +83,19 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#signalRBidButton").on("click", function () {
|
||||||
|
var bidMessage = {
|
||||||
|
AuctionId: pageViewModel.AuctionId.toFixed(),
|
||||||
|
BidPrice: pageViewModel.BidPrice.toFixed(2),
|
||||||
|
ProductId: pageViewModel.ProductId.toFixed(),
|
||||||
|
CustomerId: pageViewModel.CustomerId.toFixed()
|
||||||
|
};
|
||||||
|
|
||||||
|
sendMessageToServer("BidRequestMessage", bidMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#testButton').click(function () {
|
$('#testButton').click(function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/Auction/RefreshAuctionWidget', // Controller endpoint
|
url: '/Auction/RefreshAuctionWidget', // Controller endpoint
|
||||||
|
|
@ -94,5 +115,10 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in New Issue