UpdateProductCategoryIsFeaturedAsync
This commit is contained in:
parent
d0c6e71b0c
commit
dbb70fd201
|
|
@ -20,6 +20,7 @@ public partial class Auction: MgEntityBase, IAuction
|
|||
public DateTime? EndDateUtc { get; set; }
|
||||
|
||||
public bool Closed { get; set; }
|
||||
public int? CategoryId { get; set; }
|
||||
|
||||
[SkipValuesOnUpdate]
|
||||
public DateTime Created { get; set; }
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces;
|
|||
|
||||
public interface IAuction : IAuctionDtoBase, ITimeStampInfo //, ISoftRemoveEntityInt
|
||||
{
|
||||
|
||||
public int? CategoryId { get; set; }
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
//- ha bid-elt 1x is, kerüljön a watch-ba
|
||||
//- DbTransaction-t vhogy megcsinánli!
|
||||
|
||||
public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext, ICustomerService customerService)
|
||||
public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext, ICustomerService customerService, ICategoryService categoryService)
|
||||
{
|
||||
private readonly Mutex _handleMessageMutex = new();
|
||||
|
||||
|
|
@ -132,13 +132,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
{
|
||||
await logger.InformationAsync($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); ProductToAuctionMappingId: {auctionProductStatusRequest.ProductToAuctionId}; Status: {auctionProductStatusRequest.AuctionStatus}({(int)auctionProductStatusRequest.AuctionStatus})", null, customer);
|
||||
|
||||
var auction = await auctionService.GetAuctionDtoByProductToAuctionIdAsync(auctionProductStatusRequest.ProductToAuctionId, false);
|
||||
if (auction == null || auction.Closed)
|
||||
{
|
||||
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (auction == null || auction.Closed); Closed: {auction?.Closed}", null, customer);
|
||||
return;
|
||||
}
|
||||
|
||||
var productToAuction = await auctionService.GetProductToAuctionMappingByIdAsync(auctionProductStatusRequest.ProductToAuctionId);
|
||||
if (productToAuction == null)
|
||||
{
|
||||
|
|
@ -146,13 +139,20 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
return;
|
||||
}
|
||||
|
||||
var auction = await auctionService.GetAuctionByIdAsync(productToAuction.AuctionId);
|
||||
if (auction == null || auction.Closed)
|
||||
{
|
||||
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); (auction == null || auction.Closed); Closed: {auction?.Closed}", null, customer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsValidRequestAuctionStatus(auctionProductStatusRequest.AuctionStatus, productToAuction.AuctionStatus))
|
||||
{
|
||||
logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); RequestAuctionStatusIsValid() == false; newStatus: {auctionProductStatusRequest.AuctionStatus}; oldStatus: {productToAuction.AuctionStatus}", null, customer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (auctionProductStatusRequest.AuctionStatus == AuctionStatus.None) await ResetProductToAuction(productToAuction);
|
||||
if (auctionProductStatusRequest.AuctionStatus == AuctionStatus.None) await ResetProductToAuction(productToAuction, auction.CategoryId);
|
||||
else
|
||||
{
|
||||
switch (auctionProductStatusRequest.AuctionStatus)
|
||||
|
|
@ -207,8 +207,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
SenderId = customer.Id,
|
||||
Data = new ProductToAuctionStatusNotification(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuction.Id, true), bidsCount, "EMPTY").ToJson()
|
||||
};
|
||||
|
||||
|
||||
await hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson());
|
||||
|
||||
var isFeaturedProduct = productToAuction.IsActiveItem || productToAuction.AuctionStatus == AuctionStatus.Pause;
|
||||
await UpdateProductCategoryIsFeaturedAsync(isFeaturedProduct, auction.CategoryId, productToAuction.ProductId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -307,10 +310,34 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
await hubContext.Clients.All.SendAsync("send", bidMessage.ToJson());
|
||||
}
|
||||
|
||||
private Task ResetProductToAuction(ProductToAuctionMapping productToAuction)
|
||||
private async Task ResetProductToAuction(ProductToAuctionMapping productToAuction, int? categoryId = null)
|
||||
{
|
||||
productToAuction.AuctionStatus = AuctionStatus.None;
|
||||
return auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice);
|
||||
await auctionService.ResetProductToAuctionAsync(productToAuction, productToAuction.StartingPrice);
|
||||
|
||||
categoryId ??= (await auctionService.GetAuctionByIdAsync(productToAuction.AuctionId))?.CategoryId;
|
||||
await UpdateProductCategoryIsFeaturedAsync(false, categoryId, productToAuction.ProductId);
|
||||
}
|
||||
|
||||
private async Task UpdateProductCategoryIsFeaturedAsync(bool isFeatured, int? categoryId, int productId)
|
||||
{
|
||||
//Leszarjuk ha elszáll, az aukció menjen tovább... - J.
|
||||
try
|
||||
{
|
||||
if (categoryId.GetValueOrDefault(0) == 0) return;
|
||||
|
||||
var productCategory = (await categoryService.GetProductCategoriesByProductIdAsync(productId)).FirstOrDefault(x => x.CategoryId == categoryId);
|
||||
if (productCategory == null) return;
|
||||
|
||||
if (productCategory.IsFeaturedProduct == isFeatured) return;
|
||||
|
||||
productCategory.IsFeaturedProduct = isFeatured;
|
||||
await categoryService.UpdateProductCategoryAsync(productCategory);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error($"SignalRMessageHandler.UpdateProductCategoryIsFeaturedAsync(); categoryId: {categoryId}; productId: {productId}; isFeatured: {isFeatured}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsValidBidPrice(decimal productPrice, decimal productToAuctionCurrentPrice, decimal bidRequestPrice, Customer customer = null)
|
||||
|
|
|
|||
|
|
@ -417,9 +417,11 @@ public class AuctionService(
|
|||
return auctionDto;
|
||||
}
|
||||
|
||||
public async Task<Auction> GetAuctionByIdAsync(int auctionId) => await ctx.Auctions.GetByIdAsync(auctionId);
|
||||
|
||||
public async Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId, bool widthProducts, bool activeProductOnly)
|
||||
{
|
||||
var auction = await ctx.Auctions.GetByIdAsync(auctionId);
|
||||
var auction = await GetAuctionByIdAsync(auctionId);
|
||||
if (auction == null) return null;
|
||||
|
||||
var auctionDto = new AuctionDto(auction);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public interface IAuctionService
|
|||
Task<AuctionDto> GetAuctionDtoWithAuctionBids(int auctionId, bool activeProductOnly, int maxBidsCount);
|
||||
Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems);
|
||||
|
||||
Task<Auction> GetAuctionByIdAsync(int auctionId);
|
||||
Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId, bool widthProducts, bool activeProductOnly);
|
||||
Task<List<ProductToAuctionDto>> GetProductToAuctionDtosByAuctionId(int auctionId, bool activeProductOnly);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue