From 1c1bb07fa608452d7683b91a06fefeee6860fece Mon Sep 17 00:00:00 2001 From: Loretta Date: Mon, 18 Nov 2024 15:32:37 +0100 Subject: [PATCH] improvements, fixes, etc... --- .../AuctionPlugin.cs | 7 ++-- .../Components/AuctionPublicViewComponent.cs | 7 +--- .../Components/AuctionViewComponent.cs | 3 +- .../LiveAnnouncementViewComponent.cs | 4 +- .../Domains/DataLayer/AuctionDbTable.cs | 1 - .../Interfaces/IProductToAuctionDtoBase.cs | 8 ++-- .../Domains/Dtos/ProductToAuctionDto.cs | 11 +++--- .../Entities/ProductToAuctionMapping.cs | 7 ++-- .../Mapping/Builders/AuctionBuilder.cs | 38 +++++++++++++++++++ .../Builders/ProductToAuctionBuilder.cs | 10 +++-- .../Services/AuctionService.cs | 26 +++++++------ .../Views/PublicProductBidBox.cshtml | 2 +- 12 files changed, 82 insertions(+), 42 deletions(-) create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/AuctionBuilder.cs diff --git a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs index a2f6ede..035a990 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs @@ -4,11 +4,10 @@ using Microsoft.AspNetCore.Mvc.Routing; using Nop.Core; using Nop.Core.Domain.Catalog; using Nop.Data; -using Nop.Plugin.AuctionPlugin.Components; using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Components; +using Nop.Plugin.Misc.AuctionPlugin.Components; //using Nop.Plugin.Misc.AuctionPlugin.Components; -using Nop.Plugin.Widgets.AuctionPlugin.Components; using Nop.Services.Catalog; using Nop.Services.Cms; using Nop.Services.Common; @@ -102,7 +101,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin { ArgumentNullException.ThrowIfNull(widgetZone); - if (widgetZone.Equals(PublicWidgetZones.ProductDetailsAfterPictures)) + if (widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop)) { return typeof(AuctionPublicViewComponent); } @@ -129,7 +128,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin { return Task.FromResult>(new List { - PublicWidgetZones.ProductDetailsAfterPictures, + PublicWidgetZones.ProductDetailsOverviewTop, PublicWidgetZones.ProductDetailsBottom, PublicWidgetZones.HeaderAfter, AdminWidgetZones.ProductDetailsButtons diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index ed94aba..4bdd9dd 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Mvc; using Nop.Core; -using Nop.Plugin.Misc.AuctionPlugin; using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Services.Cms; using Nop.Services.Common; @@ -8,10 +7,8 @@ using Nop.Services.Logging; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; using Nop.Web.Models.Catalog; -using Nop.Web.Models.Order; -using Nop.Web.Models.ShoppingCart; -namespace Nop.Plugin.AuctionPlugin.Components; +namespace Nop.Plugin.Misc.AuctionPlugin.Components; public class AuctionPublicViewComponent : NopViewComponent { @@ -85,7 +82,7 @@ public class AuctionPublicViewComponent : NopViewComponent // return Content(string.Empty); //} - if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsAfterPictures)) + if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop)) { await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}"); return Content(string.Empty); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs index e6b4e22..f47cc4a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionViewComponent.cs @@ -1,6 +1,5 @@ using Microsoft.AspNetCore.Mvc; using Nop.Core; -using Nop.Plugin.Misc.AuctionPlugin; using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Services.Cms; using Nop.Services.Logging; @@ -8,7 +7,7 @@ using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; using Nop.Web.Models.Catalog; -namespace Nop.Plugin.Widgets.AuctionPlugin.Components; +namespace Nop.Plugin.Misc.AuctionPlugin.Components; public class AuctionViewComponent : NopViewComponent { diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs index 0a33ff6..aad80c9 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs @@ -1,13 +1,11 @@ using Microsoft.AspNetCore.Mvc; using Nop.Core; -using Nop.Plugin.Misc.AuctionPlugin; using Nop.Services.Cms; using Nop.Services.Logging; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; - -namespace Nop.Plugin.AuctionPlugin.Components +namespace Nop.Plugin.Misc.AuctionPlugin.Components { [ViewComponent(Name = "LiveAnnouncement")] diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/DataLayer/AuctionDbTable.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/DataLayer/AuctionDbTable.cs index 7400e82..3b3093b 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/DataLayer/AuctionDbTable.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/DataLayer/AuctionDbTable.cs @@ -18,5 +18,4 @@ public class AuctionDbTable: MgDbTableBase { return GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default); } - } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs index b017d0c..cb474f8 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/Interfaces/IProductToAuctionDtoBase.cs @@ -10,8 +10,10 @@ public interface IProductToAuctionDtoBase : IMgModelDtoBase public AuctionStatus AuctionStatus { get; set; } - public int StartingPrice { get; set; } - public int BidPrice { get; set; } + public decimal StartingPrice { get; set; } + public decimal BidPrice { get; set; } - public int BidAmount { get; set; } + public int ProductAmount { get; set; } + + public int SortIndex { get; set; } } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs index b66c934..6eb16d7 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs @@ -10,9 +10,10 @@ public class ProductToAuctionDto : IProductToAuctionDto public int ProductId { get; set; } public int AuctionId { get; set; } public AuctionStatus AuctionStatus { get; set; } - public int StartingPrice { get; set; } - public int BidPrice { get; set; } - public int BidAmount { get; set; } + public decimal StartingPrice { get; set; } + public decimal BidPrice { get; set; } + public int ProductAmount { get; set; } + public int SortIndex { get; set; } public List AuctionBidDtos { get; } = []; @@ -29,7 +30,7 @@ public class ProductToAuctionDto : IProductToAuctionDto AuctionStatus = productToAuction.AuctionStatus; StartingPrice = productToAuction.StartingPrice; BidPrice = productToAuction.BidPrice; - BidAmount = productToAuction.BidAmount; + ProductAmount = productToAuction.ProductAmount; } public ProductToAuctionMapping CreateMainEntity() @@ -42,7 +43,7 @@ public class ProductToAuctionDto : IProductToAuctionDto mainEntity.AuctionStatus = AuctionStatus; mainEntity.StartingPrice = StartingPrice; mainEntity.BidPrice = BidPrice; - mainEntity.BidAmount = BidAmount; + mainEntity.ProductAmount = ProductAmount; return mainEntity; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs index 408a22b..698a227 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs @@ -17,10 +17,11 @@ public partial class ProductToAuctionMapping : MgEntityBase, IProductToAuctionMa [NotColumn] public AuctionStatus AuctionStatus { get; set; } - public int StartingPrice { get; set; } - public int BidPrice { get; set; } + public decimal StartingPrice { get; set; } + public decimal BidPrice { get; set; } - public int BidAmount { get; set; } = 1; + public int ProductAmount { get; set; } = 1; + public int SortIndex { get; set; } [SkipValuesOnUpdate] public DateTime Created { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/AuctionBuilder.cs b/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/AuctionBuilder.cs new file mode 100644 index 0000000..4d18e62 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/AuctionBuilder.cs @@ -0,0 +1,38 @@ +using FluentMigrator; +using FluentMigrator.Builders.Create.Table; +using Nop.Data.Mapping.Builders; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; +using Nop.Data.Extensions; +using System.Data; +using Nop.Core.Domain.Catalog; +using Nop.Core.Domain.Common; +using Nop.Data.Mapping; + +namespace Nop.Plugin.Misc.AuctionPlugin.Mapping.Builders; + +public class AuctionBuilder : NopEntityBuilder +{ + #region Methods + + /// + /// Apply entity configuration + /// + /// Create table expression builder + public override void MapEntity(CreateTableExpressionBuilder table) + { + table.WithColumn(nameof(Auction.Id)).AsInt32().PrimaryKey().Identity() + + //.WithColumn(nameof(Auction.AuctionId)).AsInt32().ForeignKey(onDelete: Rule.Cascade) //Rule.Cascade?? + //.WithColumn(nameof(Auction.ProductId)).AsInt32().ForeignKey(onDelete: Rule.Cascade) //Rule.Cascade?? + + .WithColumn(nameof(Auction.AuctionType)).AsByte().NotNullable() //enum??? - J. + + //.WithColumn(nameof(Auction.StartingPrice)).AsInt32().NotNullable() + //.WithColumn(nameof(Auction.BidPrice)).AsInt32().NotNullable() + //.WithColumn(nameof(Auction.BidAmount)).AsInt32().NotNullable().WithDefaultValue(1) + .WithColumn(nameof(Auction.Created)).AsDateTime().NotNullable() + .WithColumn(nameof(Auction.Modified)).AsDateTime().NotNullable().WithDefault(SystemMethods.CurrentUTCDateTime); + } + + #endregion +} \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs b/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs index 1034684..98d75e1 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Mapping/Builders/ProductToAuctionBuilder.cs @@ -22,14 +22,16 @@ public class ProductToAuctionMappingBuilder : NopEntityBuilder(onDelete: Rule.None) //Rule.Cascade?? - .WithColumn(nameof(ProductToAuctionMapping.ProductId)).AsInt32().ForeignKey(onDelete: Rule.None) //Rule.Cascade?? + .WithColumn(nameof(ProductToAuctionMapping.AuctionId)).AsInt32().ForeignKey(onDelete: Rule.Cascade) //Rule.Cascade?? + .WithColumn(nameof(ProductToAuctionMapping.ProductId)).AsInt32().ForeignKey(onDelete: Rule.Cascade) //Rule.Cascade?? - //.WithColumn(nameof(ProductToAuctionMapping.AuctionStatus)).AsByte().NotNullable() //enum??? - J. + .WithColumn(nameof(ProductToAuctionMapping.AuctionStatus)).AsByte().NotNullable() //enum??? - J. .WithColumn(nameof(ProductToAuctionMapping.StartingPrice)).AsInt32().NotNullable() .WithColumn(nameof(ProductToAuctionMapping.BidPrice)).AsInt32().NotNullable() - .WithColumn(nameof(ProductToAuctionMapping.BidAmount)).AsInt32().NotNullable().WithDefaultValue(1) + .WithColumn(nameof(ProductToAuctionMapping.ProductAmount)).AsInt32().NotNullable().WithDefaultValue(1) + .WithColumn(nameof(ProductToAuctionMapping.SortIndex)).AsInt32().NotNullable().WithDefaultValue(0) + .WithColumn(nameof(ProductToAuctionMapping.Created)).AsDateTime().NotNullable() .WithColumn(nameof(ProductToAuctionMapping.Modified)).AsDateTime().NotNullable().WithDefault(SystemMethods.CurrentUTCDateTime); } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index fa5d0dc..924dcc5 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -1,4 +1,5 @@ -using Nop.Core; +using AyCode.Core.Extensions; +using Nop.Core; using Nop.Core.Caching; using Nop.Core.Domain.Customers; using Nop.Data; @@ -33,7 +34,7 @@ public class AuctionService : IAuctionService protected readonly AuctionDbContext _ctx; //protected readonly IRepository _customerBidRepository; //protected readonly IRepository _auctionRepository; - protected readonly IRepository _productToAuctionRepository; + //protected readonly IRepository _productToAuctionRepository; protected readonly IShortTermCacheManager _shortTermCacheManager; protected readonly IStaticCacheManager _staticCacheManager; protected readonly IWorkContext _workContext; @@ -50,8 +51,8 @@ public class AuctionService : IAuctionService /// Cache manager public AuctionService( AuctionDbContext ctx, - IRepository auctionRepository, - IRepository productToAuctionRepository, + //IRepository auctionRepository, + //IRepository productToAuctionRepository, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, IWorkContext workContext, @@ -60,7 +61,7 @@ public class AuctionService : IAuctionService _ctx = ctx; //_customerBidRepository = customerBidRepository; //_auctionRepository = auctionRepository; - _productToAuctionRepository = productToAuctionRepository; + //_productToAuctionRepository = productToAuctionRepository; _shortTermCacheManager = shortTermCacheManager; _staticCacheManager = staticCacheManager; _workContext = workContext; @@ -158,7 +159,7 @@ public class AuctionService : IAuctionService #endregion #endregion - #region Dtos + #region Dtots public async Task GetAuctionDtoByIdAsync(int auctionId) { return new AuctionDto(await _ctx.Auctions.GetByIdAsync(auctionId)); @@ -181,6 +182,7 @@ public class AuctionService : IAuctionService { return new AuctionBidDto(await _ctx.AuctionBids.GetByIdAsync(auctionBidId)); } + public async Task AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId) { var auction = await _ctx.Auctions.GetByIdAsync(auctionId); @@ -190,9 +192,9 @@ public class AuctionService : IAuctionService var mapping = new ProductToAuctionMapping { ProductId = productId, - StartingPrice = Convert.ToInt32(startingPrice), - BidPrice = Convert.ToInt32(bidPrice), - BidAmount = 0, + StartingPrice = startingPrice, + BidPrice = bidPrice, + ProductAmount = 0, AuctionStatus = Domains.Enums.AuctionStatus.Active, AuctionId = auctionId }; @@ -200,9 +202,11 @@ public class AuctionService : IAuctionService { await _ctx.ProductToAuctions.InsertAsync(mapping); } - catch (Exception ex) { + catch (Exception ex) + { await _logger.InformationAsync(ex.ToString()); - } + } + return true; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index f95d422..ff642cf 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -32,7 +32,7 @@ -