improvements, fixes, etc...

This commit is contained in:
Loretta 2024-11-21 12:28:53 +01:00
parent acc9496490
commit 637d5c1dc8
3 changed files with 36 additions and 29 deletions

View File

@ -17,6 +17,7 @@ public class ProductToAuctionDto : IProductToAuctionDto
public List<AuctionBidDto> AuctionBidDtos { get; } = [];
public bool IsActiveItem => AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning;
public ProductToAuctionDto()
{

View File

@ -1,27 +1,36 @@
using System.Globalization;
using AyCode.Core.Extensions;
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;
using Nop.Core;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Services.Customers;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
//- SortIndex
//- Rátettem egy unique-ot az AuctionId és a ProductId-ra!!!
//- Új field-ek a db-be! pl.: WinnerCustomerId, stb...
//- IsActiveItem
//- Product onupdate
//- lock
//- ha saját licit a legjobb vagy lezárt, ne lehessen bid-elni
//- az előző esetben a kliensen a gombot is tiltani, már a.cshtml-ben ellenőrizni!
//- ha nincs login elszállhat a kliens
//- csak a watch-olt item-eknél legyen announcment
//- ha bid-elt 1x is, kerüljön a watch-ba
//- DbTransaction-t vhogy megcsinánli!
//- NextStepAmount
public class SignalRMessageHandler
{
protected readonly ILogger _logger;
protected readonly IProductService _productService;
protected readonly AuctionService _auctionService;
private IHubContext<AuctionHub> _hubContext;
private readonly ILogger _logger;
private readonly IProductService _productService;
private readonly AuctionService _auctionService;
private readonly IHubContext<AuctionHub> _hubContext;
private readonly IWorkContext _workContext;
public SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext)
@ -114,7 +123,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
await _auctionService.UpdateProductToAuctionMappingAsync(productToAuction);
var bid = new MessageWrapper
var productToauctionChangedNotification = new MessageWrapper
{
MessageType = nameof(ProductToAuctionStatusNotification),
SenderId = senderId,
@ -124,7 +133,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
}.ToJson()
};
await _hubContext.Clients.All.SendAsync("send", bid.ToJson());
await _hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson());
}
catch (Exception ex)
{
@ -204,7 +213,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
ProductName = auctionBid.ProductId.ToString(),
BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture),
NextStepAmount = "50000",
NextStepAmount = "50000", //TODO: - J.
ToasterMessage = string.Empty, //TODO: - J.
}.ToJson()
};

View File

@ -1,9 +1,5 @@
using AyCode.Core.Extensions;
using Nop.Core;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Customers;
using Nop.Data;
using Nop.Plugin.Misc.AuctionPlugin.Domains;
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
@ -25,21 +21,18 @@ public class AuctionService : IAuctionService
/// <remarks>
/// {0} : current store ID
/// </remarks>
protected readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY);
protected const string AUCTION_PATTERN_KEY = "Nop.auction.";
private readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY); //nem ezt használjuk a kódban, nem gond?! - J.
private const string AUCTION_PATTERN_KEY = "Nop.auction.";
#endregion
#region Fields
protected readonly AuctionDbContext _ctx;
//protected readonly IRepository<AuctionBid> _customerBidRepository;
//protected readonly IRepository<Auction> _auctionRepository;
//protected readonly IRepository<ProductToAuctionMapping> _productToAuctionRepository;
protected readonly IShortTermCacheManager _shortTermCacheManager;
protected readonly IStaticCacheManager _staticCacheManager;
protected readonly IWorkContext _workContext;
protected readonly ILogger _logger;
private readonly AuctionDbContext _ctx;
private readonly IShortTermCacheManager _shortTermCacheManager;
private readonly IStaticCacheManager _staticCacheManager;
private readonly IWorkContext _workContext;
private readonly ILogger _logger;
#endregion
#region Ctor
@ -50,6 +43,8 @@ public class AuctionService : IAuctionService
/// <param name="ctx"></param>
/// <param name="shortTermCacheManager">Short term cache manager</param>
/// <param name="staticCacheManager">Cache manager</param>
/// <param name="workContext"></param>
/// <param name="logger"></param>
public AuctionService(
AuctionDbContext ctx,
//IRepository<Auction> auctionRepository,
@ -93,6 +88,8 @@ public class AuctionService : IAuctionService
/// </returns>
public async Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue)
{
//TODO: megcsinálni! - J.
var rez = new List<AuctionBid>();
//var rez = await _shortTermCacheManager.GetAsync(async () => await _customerBidRepository.GetAllAsync(query =>
//{
@ -209,12 +206,12 @@ public class AuctionService : IAuctionService
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
{
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync());
return [..await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync()];
}
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly = false)
{
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync());
return [..await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()];
}
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)