diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index 3570db0..4eb6a26 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -66,7 +66,7 @@ public class AuctionPublicViewComponent : NopViewComponent /// public async Task InvokeAsync(string widgetZone, object additionalData) { - ProductBidBoxViewModel productBidBoxViewModel = new ProductBidBoxViewModel(); + await _logger.InformationAsync("WidgetViewComponent called"); @@ -103,54 +103,35 @@ public class AuctionPublicViewComponent : NopViewComponent //is it under Auction? - List auctionIds = await _auctionService.GetProductToAuctionsByProductIdAsync(productDetailsModel.Id); - int auctionId = 0; - AuctionDto auction; - if(auctionIds == null || auctionIds.Count == 0) + var productId = productDetailsModel.Id; + + var productToAuctionDtoMappings = await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId); + if (productToAuctionDtoMappings.Count == 0) { return Content(string.Empty); } - if (auctionIds.Count > 1) - { - List openAuctionList = []; + var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuctionDtoMappings.FirstOrDefault()!.AuctionId)); + auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings); - //we have more auctions so we return the closest open - foreach (var auctionMapping in auctionIds) - { - var auctionItem = await _auctionService.GetAuctionDtoByIdAsync(auctionMapping.AuctionId); - if (!auctionItem.Closed) - { - openAuctionList.Add(auctionItem); - } - } - //first auction that started or strats not earlier than yesterday - auction = openAuctionList.Where(x => x.StartDateUtc > DateTime.UtcNow.AddDays(-1)).OrderBy(x => x.StartDateUtc).FirstOrDefault(); - auctionId = auction.Id; - } - else - { - auction = await _auctionService.GetAuctionDtoByIdAsync(auctionIds.FirstOrDefault().AuctionId); - auctionId = auction.Id; + var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto); + //List productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id); - } - - List productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id); - - AuctionStatus status = productToAuctionId.FirstOrDefault().AuctionStatus; + AuctionStatus status = productToAuctionDtoMappings.FirstOrDefault()!.AuctionStatus; bool isActive = status.HasFlag(AuctionStatus.Active); bool isFirstWarning = status.HasFlag(AuctionStatus.FirstWarning); productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer); productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer); - productBidBoxViewModel.AuctionClosed = auction.Closed; - productBidBoxViewModel.IsItemActive = isActive; + //productBidBoxViewModel.AuctionClosed = auction.Closed; + + //productBidBoxViewModel.IsItemActive = isActive; productBidBoxViewModel.WidgetZone = widgetZone; productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue; - productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id; - productBidBoxViewModel.AuctionId = auctionId; + //productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id; + //productBidBoxViewModel.AuctionId = auctionId; productBidBoxViewModel.CustomerId = customer.Id; productBidBoxViewModel.ProductId = productDetailsModel.Id; productBidBoxViewModel.LicitStep = 50000; //add calculation diff --git a/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs index 8bdfc8d..6007a5d 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs @@ -71,9 +71,24 @@ public class AuctionController : BasePluginController return ViewComponent("AuctionPublic", new { widgetZone = request.WidgetZone, additionalData = detailsModel }); } - public async Task LiveScreen() + public async Task LiveScreen(int auctionId) { - var model = new LiveScreenViewModel(); + + var auctionDto = await _auctionService.GetAuctionDtoByIdAsync(auctionId); + + var productToAuctionDtoMappings = await _auctionService.GetProductToAuctionsByAuctionIdAsync(auctionId, false); + + //auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings); + + var model = new LiveScreenViewModel(auctionDto); + + var product = await _productService.GetProductByIdAsync(auctionDto.ProductToAuctionDtos.FirstOrDefault().Id); + + var productDetailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product); + + + model.ProductDetails = productDetailsModel; + return View("~/Plugins/Misc.AuctionPlugin/Views/LiveScreen.cshtml", model); } } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs index 138a654..3fa05eb 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs @@ -55,7 +55,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure defaults: new { controller = "AuctionPluginAdmin", action = "AssignProductToAuction" }); endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.LiveScreenRouteName, - pattern: "Auction/LiveScreen", + pattern: "Auction/LiveScreen/{auctionId}", defaults: new { controller = "Auction", action = "LiveScreen" }); } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs index c07b3e9..b3b1f9d 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs @@ -1,4 +1,5 @@ -using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; +using Newtonsoft.Json; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Web.Framework.Models; using Nop.Web.Framework.Mvc.ModelBinding; using Nop.Web.Models.Catalog; @@ -8,16 +9,55 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models public record LiveScreenViewModel : BaseNopModel { - public int ProductId { get; set; } + [JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public AuctionDto AuctionDto { get; set; } - public DateTime StartDate { get; set; } - - public bool IsActive { get; set; } - - public AuctionDto CurrentAuction { get; set; } + [JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public ProductToAuctionDto FirstProductToAuction { get; set; } public ProductDetailsModel ProductDetails { get; set; } + public int ProductId { get; set; } + + public int ProductToAuctionId { get; set; } + public bool IsAdmin { get; set; } + public bool IsGuest { get; set; } + + public int AuctionId { get; set; } + public bool IsItemActive { get; set; } + public int CustomerId { get; set; } + + public string WidgetZone { get; set; } + + + #region debug fields to be removed + + public decimal? BasePrice { get; set; } + + #endregion + + #region visible + public decimal LicitStep { get; set; } + public decimal? CurrentPrice { get; set; } + public decimal BidPrice { get; set; } + + #endregion visible + + public LiveScreenViewModel() { } + + public LiveScreenViewModel(AuctionDto auctionDto) : this() + { + AuctionDto = auctionDto; + FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First(); + + AuctionId = auctionDto.Id; + ProductId = FirstProductToAuction.ProductId; + ProductToAuctionId = FirstProductToAuction.Id; + IsItemActive = FirstProductToAuction.IsActiveItem; + } + } } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs index 21ced3e..1d2739a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs @@ -1,4 +1,6 @@ -using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; +using Newtonsoft.Json; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Web.Framework.Models; using System; using System.Collections.Generic; @@ -10,16 +12,25 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models { public record ProductBidBoxViewModel: BaseNopModel { - public int ProductToAuctionId { get; set; } - public bool IsAdmin { get; set; } - public bool IsGuest { get; set; } - public int AuctionId { get; set; } - public bool AuctionClosed { get; set; } - public bool IsItemActive { get; set; } + [JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public AuctionDto AuctionDto { get; set; } + + [JsonIgnore] + [System.Text.Json.Serialization.JsonIgnore] + public ProductToAuctionDto FirstProductToAuction { get; set; } + public int ProductId { get; set; } + + public int ProductToAuctionId { get; set; } + public bool IsAdmin { get; set; } + public bool IsGuest { get; set; } + + public int AuctionId { get; set; } + public bool IsItemActive { get; set; } public int CustomerId { get; set; } - public string WidgetZone { get; set; } + public string WidgetZone { get; set; } #region debug fields to be removed @@ -35,5 +46,19 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models #endregion visible + public ProductBidBoxViewModel() { } + + public ProductBidBoxViewModel(AuctionDto auctionDto) : this() + { + AuctionDto = auctionDto; + FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First(); + + AuctionId = auctionDto.Id; + ProductId = FirstProductToAuction.ProductId; + ProductToAuctionId = FirstProductToAuction.Id; + IsItemActive = FirstProductToAuction.IsActiveItem; + } + + } } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml index 957f43a..e26402a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml @@ -9,11 +9,91 @@ //page title } -
-

Live screen

+
+ +
+
+ Auction Item Image +
+
+ +
+
+
+

Auction Item Title

+

Created by: Creator Name

+ + +
    +
  • + Size + 10 x 12 inches +
  • +
  • + Material + Oil on Canvas +
  • +
  • + Description: +

    + A beautiful depiction of a serene landscape, perfect for any art lover or collector. +

    +
  • +
+
+
+
+
+ +
+ +
+
+
+
Bid History
+
+ + + + + + + + + + + + +
#BidderBid AmountDate
+
+
+
+
+
+ + + + + + -