BidsCount; improvements, fixes, etc..

This commit is contained in:
Loretta 2024-11-26 16:45:52 +01:00
parent 849c04c10b
commit 12d207e208
9 changed files with 42 additions and 16 deletions

View File

@ -18,6 +18,9 @@ public class AuctionBidDbTable : MgDbTableBase<AuctionBid>
public IQueryable<AuctionBid> GetLastAuctionBidByProductToAuctionId(int productToAuctionId) public IQueryable<AuctionBid> GetLastAuctionBidByProductToAuctionId(int productToAuctionId)
=> GetByProductToAuctionId(productToAuctionId).OrderByDescending(x => x.Id); => GetByProductToAuctionId(productToAuctionId).OrderByDescending(x => x.Id);
public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
=> Table.CountAsync(x => x.ProductAuctionMappingId == productToAuctionId);
public IQueryable<AuctionBid> GetByProductToAuctionId(int productToAuctionId) public IQueryable<AuctionBid> GetByProductToAuctionId(int productToAuctionId)
=> Table.Where(x => x.ProductAuctionMappingId == productToAuctionId); => Table.Where(x => x.ProductAuctionMappingId == productToAuctionId);

View File

@ -60,6 +60,10 @@ public class AuctionDbContext : MgDbContextBase, IAuctionDbSet<AuctionDbTable>,
public Task<AuctionBid> GetLastAuctionBidByProductToAuctionId(int productToAuctionId) public Task<AuctionBid> GetLastAuctionBidByProductToAuctionId(int productToAuctionId)
=> AuctionBids.GetLastAuctionBidByProductToAuctionId(productToAuctionId).FirstOrDefaultAsync(); => AuctionBids.GetLastAuctionBidByProductToAuctionId(productToAuctionId).FirstOrDefaultAsync();
public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
=> AuctionBids.GetBidsCountByProductToAuctionIdAsync(productToAuctionId);
public Task<AuctionBid> RevertAuctionBidByProductToAuctionId(int productToAuctionId) public Task<AuctionBid> RevertAuctionBidByProductToAuctionId(int productToAuctionId)
=> AuctionBids.RevertByProductToAuctionIdAsync(productToAuctionId); => AuctionBids.RevertByProductToAuctionIdAsync(productToAuctionId);

View File

@ -5,12 +5,17 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
public abstract class AuctionNotificationBase public abstract class AuctionNotificationBase
{ {
public AuctionDto AuctionDto { get; set; } public AuctionDto AuctionDto { get; set; }
public string ToasterMessage { get; set; } public string ToasterMessage { get; set; }
public int BidsCount { get; set; }
protected AuctionNotificationBase(){} protected AuctionNotificationBase(){}
protected AuctionNotificationBase(AuctionDto auctionDto) protected AuctionNotificationBase(AuctionDto auctionDto, int bidsCount, string toasterMessage)
{ {
AuctionDto = auctionDto; AuctionDto = auctionDto;
BidsCount = bidsCount;
ToasterMessage = toasterMessage;
} }
} }

View File

@ -4,7 +4,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
public class AuctionStatusNotification : AuctionNotificationBase public class AuctionStatusNotification : AuctionNotificationBase
{ {
public AuctionStatusNotification() { } public AuctionStatusNotification()
public AuctionStatusNotification(AuctionDto auctionDto):base(auctionDto) { } {
}
public AuctionStatusNotification(AuctionDto auctionDto, int bidsCount, string toasterMessage) : base(auctionDto, bidsCount, toasterMessage)
{
}
} }

View File

@ -18,9 +18,13 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
public decimal CurrentPrice { get; set; } public decimal CurrentPrice { get; set; }
public decimal NextBidPrice { get; set; } public decimal NextBidPrice { get; set; }
public decimal NextStepAmount { get; set; } public decimal NextStepAmount { get; set; }
public BidNotificationMessage() { }
public BidNotificationMessage(AuctionDto auctionDto):base(auctionDto) { }
}
public BidNotificationMessage()
{
}
public BidNotificationMessage(AuctionDto auctionDto, int bidsCount, string toasterMessage) : base(auctionDto, bidsCount, toasterMessage)
{
}
}
} }

View File

@ -4,7 +4,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
public class ProductToAuctionStatusNotification : AuctionNotificationBase public class ProductToAuctionStatusNotification : AuctionNotificationBase
{ {
public ProductToAuctionStatusNotification() { } public ProductToAuctionStatusNotification()
public ProductToAuctionStatusNotification(AuctionDto auctionDto):base(auctionDto) { } {
}
public ProductToAuctionStatusNotification(AuctionDto auctionDto, int bidsCount, string toasterMessage) : base(auctionDto, bidsCount, toasterMessage)
{
}
} }

View File

@ -199,14 +199,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
await auctionService.UpdateProductToAuctionMappingAsync(productToAuction); await auctionService.UpdateProductToAuctionMappingAsync(productToAuction);
} }
var bidsCount = await auctionService.GetBidsCountByProductToAuctionIdAsync(productToAuction.Id);
var productToauctionChangedNotification = new MessageWrapper var productToauctionChangedNotification = new MessageWrapper
{ {
MessageType = nameof(ProductToAuctionStatusNotification), MessageType = nameof(ProductToAuctionStatusNotification),
SenderId = customer.Id, SenderId = customer.Id,
Data = new ProductToAuctionStatusNotification(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true)) Data = new ProductToAuctionStatusNotification(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true), bidsCount, "EMPTY").ToJson()
{
ToasterMessage = "EMPTY", //TODO: - J.
}.ToJson()
}; };
await hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson()); await hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson());
@ -286,17 +284,17 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
var stepAmount = GetStepAmount(productToAuction.CurrentPrice); var stepAmount = GetStepAmount(productToAuction.CurrentPrice);
var nextBidPrice = GetNextBidPrice(productToAuction.CurrentPrice, stepAmount); var nextBidPrice = GetNextBidPrice(productToAuction.CurrentPrice, stepAmount);
var bidsCount = await auctionService.GetBidsCountByProductToAuctionIdAsync(productToAuction.Id);
var bidMessage = new MessageWrapper var bidMessage = new MessageWrapper
{ {
MessageType = "bidNotification", MessageType = "bidNotification",
SenderId = customerId, SenderId = customerId,
Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true)) //TODO: NE KÉRJÜK LE DB-BŐL!!! - j. Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true), bidsCount, "EMPTY") //TODO: NE KÉRJÜK LE DB-BŐL!!! - j.
{ {
ProductName = product.Name, ProductName = product.Name,
CurrentPrice = productToAuction.CurrentPrice, CurrentPrice = productToAuction.CurrentPrice,
NextStepAmount = stepAmount, NextStepAmount = stepAmount,
NextBidPrice = nextBidPrice, NextBidPrice = nextBidPrice,
ToasterMessage = "EMPTY", //TODO: - J.
}.ToJson() }.ToJson()
}; };

View File

@ -114,6 +114,9 @@ public class AuctionService : IAuctionService
public Task<AuctionBid> GetLastAuctionBidByProductToAuctionIdAsync(int productToAuctionId) public Task<AuctionBid> GetLastAuctionBidByProductToAuctionIdAsync(int productToAuctionId)
=> _ctx.GetLastAuctionBidByProductToAuctionId(productToAuctionId); => _ctx.GetLastAuctionBidByProductToAuctionId(productToAuctionId);
public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
=> _ctx.GetBidsCountByProductToAuctionIdAsync(productToAuctionId);
public Task<AuctionBid> RevertAuctionBidByProductToAuctionIdAsync(int productToAuctionId) public Task<AuctionBid> RevertAuctionBidByProductToAuctionIdAsync(int productToAuctionId)
=> _ctx.RevertAuctionBidByProductToAuctionId(productToAuctionId); => _ctx.RevertAuctionBidByProductToAuctionId(productToAuctionId);

View File

@ -26,7 +26,8 @@ public interface IAuctionService
/// The task result contains the bids /// The task result contains the bids
/// </returns> /// </returns>
Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue); Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue);
Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId);
Task<AuctionBid> GetBidByIdAsync(int bidId); Task<AuctionBid> GetBidByIdAsync(int bidId);
Task InsertBidAsync(AuctionBid auctionBid); Task InsertBidAsync(AuctionBid auctionBid);