improvements, fixes, etc...

This commit is contained in:
Loretta 2024-11-21 14:57:07 +01:00
parent 840dae2969
commit d9f95dd8e1
10 changed files with 55 additions and 17 deletions

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Plugin.Misc.AuctionPlugin.Models;
using Nop.Plugin.Misc.AuctionPlugin.Services;
@ -76,29 +77,35 @@ public class AuctionViewComponent : NopViewComponent
//{
// return Content(string.Empty);
//}
var model = new AuctionPublicInfoModel();
if (!widgetZone.Equals(PublicWidgetZones.ProductBoxAddinfoBefore))
{
return Content(string.Empty);
}
var productId = ((ProductOverviewModel)additionalData).Id;
model.ProductId = productId;
var productToAuctionMapping = (await _auctionService.GetProductToAuctionsByProductIdAsync(productId)).FirstOrDefault();
if (productToAuctionMapping == null)
//model.ProductId = productId;
var productToAuctionDtoMappings = await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId);
if (productToAuctionDtoMappings.Count == 0)
{
return Content(string.Empty);
}
model.ProductToAuctionMappingId = productToAuctionMapping.Id;
var auction = await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuctionMapping.Id);
model.StartDate = auction.StartDateUtc;
AuctionStatus status = productToAuctionMapping.AuctionStatus;
model.IsActive = status.HasFlag(AuctionStatus.Active);
var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuctionDtoMappings.FirstOrDefault()!.AuctionId));
auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings);
bool isFirstWarning = status.HasFlag(AuctionStatus.FirstWarning);
var model = new AuctionPublicInfoModel(auctionDto);
//model.ProductToAuctionMappingId = productToAuctionMapping.Id;
//var auction = await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(productToAuctionMapping.Id);
//model.StartDate = auction.StartDateUtc;
//AuctionStatus status = productToAuctionMapping.AuctionStatus;
//model.IsActive = status.HasFlag(AuctionStatus.Active);
//bool isFirstWarning = status.HasFlag(AuctionStatus.FirstWarning);
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicInfo.cshtml", model);

View File

@ -8,6 +8,7 @@ public interface IProductToAuctionDtoBase : IMgModelDtoBase
public int ProductId { get; set; }
public int AuctionId { get; set; }
public int WinnerCustomerId { get; set; }
public AuctionStatus AuctionStatus { get; set; }
public decimal StartingPrice { get; set; }

View File

@ -9,6 +9,7 @@ public class ProductToAuctionDto : IProductToAuctionDto
public int Id { get; set; }
public int ProductId { get; set; }
public int AuctionId { get; set; }
public int WinnerCustomerId { get; set; }
public AuctionStatus AuctionStatus { get; set; }
public decimal StartingPrice { get; set; }
public decimal BidPrice { get; set; }

View File

@ -12,6 +12,7 @@ public partial class ProductToAuctionMapping : MgEntityBase, IProductToAuctionMa
{
public int ProductId { get; set; }
public int AuctionId { get; set; }
public int WinnerCustomerId { get; set; }
[NotMapped]
[NotColumn]

View File

@ -10,7 +10,7 @@
// NotSold = 25
//}
[Flags]
//[Flags]
public enum AuctionStatus : byte
{
None = 0,

View File

@ -50,7 +50,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
return;
}
//TODO: A MessageWrapper-ben kéne küldözgetni a UserId (CustomerId-t) - J.
if (message.SenderId <= 0 || message.SenderId != (await _workContext.GetCurrentCustomerAsync()).Id)
{
_logger.Error($"SignalRMessageHandler.HandleMessage(); message.SenderId <= 0 || message.SenderId != (await _workContext.GetCurrentCustomerAsync()).Id");
@ -214,6 +213,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
ProductName = auctionBid.ProductId.ToString(),
BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture),
NextStepAmount = "50000", //TODO: - J.
ToasterMessage = string.Empty, //TODO: - J.
}.ToJson()
};

View File

@ -1,18 +1,40 @@
using Nop.Web.Framework.Models;
using Newtonsoft.Json;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Web.Framework.Models;
using Nop.Web.Framework.Mvc.ModelBinding;
namespace Nop.Plugin.Misc.AuctionPlugin.Models
{
public record AuctionPublicInfoModel : BaseNopModel
{
[JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public AuctionDto AuctionDto { get; set; }
public int ProductId { get; set; }
[JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public ProductToAuctionDto FirstProductToAuction { get; set; }
public int ProductToAuctionMappingId { get; set; }
public int ProductId { get; set; }
public int ProductToAuctionMappingId { get; set; }
public DateTime StartDate { get; set; }
public bool IsActive { get; set; }
public AuctionPublicInfoModel() {}
public AuctionPublicInfoModel(AuctionDto auctionDto) : this()
{
AuctionDto = auctionDto;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First();
ProductId = FirstProductToAuction.ProductId;
ProductToAuctionMappingId = FirstProductToAuction.Id;
StartDate = AuctionDto.StartDateUtc;
IsActive = FirstProductToAuction.IsActiveItem;
}
}
}

View File

@ -197,6 +197,11 @@ public class AuctionService : IAuctionService
return auctionDto;
}
public async Task<List<ProductToAuctionDto>> GetProductToAuctionDtosByProductIdAsync(int productId)
{
return [..await _ctx.ProductToAuctions.GetByProductId(productId).Select(x=>new ProductToAuctionDto(x)).ToListAsync()];
}
public async Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId)
{
var auctionBid = await _ctx.AuctionBids.GetByIdAsync(auctionBidId);

View File

@ -129,6 +129,7 @@ public class EventConsumer :
public async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
{
//eventMessage.
//send notification on SignalR
}

View File

@ -37,7 +37,7 @@
function refreshPublicInfo@(Model.ProductId)(data) {
console.log('function called: refreshPublicInfo'+@(Model.ProductId))
console.log('function called: refreshPublicInfo' + @(Model.ProductId));
}
</script>