From ef98268f0373d36cae4bf10dfe4550d9b7c28426 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 Nov 2024 19:34:45 +0100 Subject: [PATCH] ghdkjg fdskhgk --- .../Controllers/AuctionController.cs | 59 ++++++- .../Domains/Dtos/ProductToAuctionDto.cs | 4 + .../Models/LiveScreenViewModel.cs | 37 ++--- .../Views/Auction/LiveScreenRoot.cshtml | 2 +- .../Views/LiveScreen.cshtml | 145 +++++++++++------- 5 files changed, 156 insertions(+), 91 deletions(-) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs index 6007a5d..462a082 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs @@ -1,8 +1,11 @@ using AyCode.Core.Extensions; using Microsoft.AspNetCore.Mvc; +using Nop.Core.Domain.Catalog; using Nop.Data; using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; 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; using Nop.Services.Catalog; @@ -74,20 +77,64 @@ public class AuctionController : BasePluginController public async Task LiveScreen(int auctionId) { - var auctionDto = await _auctionService.GetAuctionDtoByIdAsync(auctionId); + var auctionDto = await _auctionService.GetAuctionDtoByIdAsync(auctionId, true); + + //var auctionDto = _auctionService.GetAuctionDtoWithAuctionBids(int auctionId, bool activeProductOnly) - var productToAuctionDtoMappings = await _auctionService.GetProductToAuctionsByAuctionIdAsync(auctionId, false); - //auctionDto.ProductToAuctionDtos.AddRange(productToAuctionDtoMappings); + bool isAnyItemLive = auctionDto.ProductToAuctionDtos.Any(x => x.AuctionStatus == AuctionStatus.Active); + var model = new LiveScreenViewModel(auctionDto); + Product product; + ProductDetailsModel productDetailsModel; + ProductToAuctionDto activeMapping; + int activeProductId = 0; + int activeProductToAuctionId = 0; + decimal basePrice = 0; + decimal currentPrice = 0; + decimal nextStep = 0; - var product = await _productService.GetProductByIdAsync(auctionDto.ProductToAuctionDtos.FirstOrDefault().Id); + if (isAnyItemLive) + { + + activeMapping = auctionDto.ProductToAuctionDtos.Where(x => x.AuctionStatus == AuctionStatus.Active).FirstOrDefault(); + product = await _productService.GetProductByIdAsync(activeMapping.ProductId); + activeProductId = activeMapping.ProductId; + activeProductToAuctionId = activeMapping.Id; + productDetailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product); + basePrice = activeMapping.StartingPrice; + currentPrice = activeMapping.CurrentPrice; + nextStep = AuctionService.GetStepAmount(currentPrice); + + } - var productDetailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product); + else + { + activeMapping = null; + product = null; + activeProductId = 0; + activeProductToAuctionId = 0; + productDetailsModel = null; + } + //I need product data + //create a more detailed model + + + model.IsAnyItemActive = isAnyItemLive; + model.AuctionId = auctionId; + model.CurrentProductToAuction = activeMapping; + model.ActiveProductId = activeProductId; + model.ActiveProductToAuctionId = activeProductToAuctionId; + model.ActiveProductDetails = productDetailsModel; + model.BasePrice = basePrice; + model.CurrentPrice = currentPrice; + model.LicitStep = nextStep; + model.BasePrice = basePrice; + model.CurrentPrice = currentPrice; + - model.ProductDetails = productDetailsModel; return View("~/Plugins/Misc.AuctionPlugin/Views/LiveScreen.cshtml", model); } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs index 38f2a4e..2349273 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs @@ -26,6 +26,8 @@ public class ProductToAuctionDto : IProductToAuctionDto public bool IsActiveItem => AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning; + public decimal BidPrice { get; set; } + public ProductToAuctionDto() { } public ProductToAuctionDto(ProductToAuctionMapping productToAuction) : this(productToAuction, 0/*AuctionService.GetStepAmount(productToAuction.BidPrice)*/) { } @@ -49,6 +51,7 @@ public class ProductToAuctionDto : IProductToAuctionDto StartingPrice = productToAuction.StartingPrice; CurrentPrice = productToAuction.CurrentPrice; ProductAmount = productToAuction.ProductAmount; + SortIndex = productToAuction.SortIndex; } public ProductToAuctionMapping CreateMainEntity() @@ -62,6 +65,7 @@ public class ProductToAuctionDto : IProductToAuctionDto mainEntity.StartingPrice = StartingPrice; mainEntity.CurrentPrice = CurrentPrice; mainEntity.ProductAmount = ProductAmount; + mainEntity.SortIndex = SortIndex; return mainEntity; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs index b3b1f9d..2641800 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/LiveScreenViewModel.cs @@ -15,47 +15,30 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models [JsonIgnore] [System.Text.Json.Serialization.JsonIgnore] - public ProductToAuctionDto FirstProductToAuction { get; set; } + public ProductToAuctionDto CurrentProductToAuction { get; set; } - public ProductDetailsModel ProductDetails { get; set; } + public ProductDetailsModel ActiveProductDetails { get; set; } - public int ProductId { get; set; } - - public int ProductToAuctionId { get; set; } - public bool IsAdmin { get; set; } - public bool IsGuest { get; set; } + public bool IsAnyItemActive { get; set; } + public int ActiveProductId { 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 int ActiveProductToAuctionId { get; set; } + public bool IsAdmin { get; set; } + public bool IsGuest { get; set; } 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; + AuctionDto = auctionDto; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/Auction/LiveScreenRoot.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/Auction/LiveScreenRoot.cshtml index 3c29b53..bcdcf04 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/Auction/LiveScreenRoot.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/Auction/LiveScreenRoot.cshtml @@ -13,7 +13,7 @@
-
+
@RenderBody()
diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml index e26402a..670dae3 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml @@ -7,53 +7,24 @@ var gridPageSizes = EngineContext.Current.Resolve().GridPageSizes; Layout = "Auction/LiveScreenRoot.cshtml"; //page title - + } -
+@{ + if (Model.IsAnyItemActive) + { + +
-
-
- Auction Item Image +
+
+ 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
- +
@@ -70,27 +41,87 @@ + +
+
+
+

@Model.ActiveProductDetails.Name

+

Created by: @Model.ActiveProductDetails.ProductManufacturers.FirstOrDefault().Name

+

Item no.: @Model.CurrentProductToAuction.SortIndex

+ +
    +
  • + Base price + @(String.Format("{0:c}", Model.BasePrice)) +
  • +
  • + Actual licit step + @(String.Format("{0:c}", Model.LicitStep)) +
  • +
  • + @await Html.PartialAsync("../../../Views/Product/_ProductSpecifications.cshtml", Model.ActiveProductDetails.ProductSpecificationModel) + @* @{ + + var dataDictAttributes = new ViewDataDictionary(ViewData); + dataDictAttributes.TemplateInfo.HtmlFieldPrefix = $"attributes_{Model.ProductDetails.Id}"; + @await Html.PartialAsync("../../../Views/Product/_ProductAttributes.cshtml", Model.ProductDetails, dataDictAttributes) + } + *@ +
  • + @*
  • + Material + Oil on Canvas +
  • *@ +
  • + Description: +

    + @Html.Raw(Model.ActiveProductDetails.FullDescription) +

    +
  • +
+
+ +
+
+ + } + else + { +
+ +
+

@Model.AuctionDto.AuctionName

+
+ } +} - - + }); +
#