From 83be60e4d2ed01c9be964992515934b63c54a4b8 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 17 Nov 2024 16:50:40 +0100 Subject: [PATCH] Assign product to auction, auction list, creat auction --- .../Components/AuctionAdminViewComponent.cs | 101 ++++++++++++++++++ .../AuctionPluginAdminController.cs | 47 ++++++++ .../Models/ProductAssignToAuctionViewModel.cs | 18 ++++ .../AdminProductAuctionSettingsBox.cshtml | 46 ++++++++ .../Areas/Admin/Views/AuctionList.cshtml | 61 +++++++++++ .../AuctionDefaults.cs | 1 + .../AuctionPlugin.cs | 24 ++++- .../Components/AuctionAdminViewComponent.cs | 73 ------------- .../Components/AuctionPublicViewComponent.cs | 2 +- .../Entities/ProductToAuctionMapping.cs | 3 +- .../Infrastructure/PluginNopStartup.cs | 3 +- .../Infrastructure/RouteProvider.cs | 4 + .../Nop.Plugin.Misc.AuctionPlugin.csproj | 7 +- .../Services/AuctionService.cs | 21 +++- .../Services/IAuctionService.cs | 5 +- .../Services/MyProductModelFactory.cs | 82 +------------- .../AdminProductAuctionSettingsBox.cshtml | 10 -- .../Views/PublicProductBidBox.cshtml | 50 ++++----- 18 files changed, 359 insertions(+), 199 deletions(-) create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Components/AuctionAdminViewComponent.cs create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/ProductAssignToAuctionViewModel.cs create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AdminProductAuctionSettingsBox.cshtml create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml delete mode 100644 Nop.Plugin.Misc.AuctionPlugin/Components/AuctionAdminViewComponent.cs delete mode 100644 Nop.Plugin.Misc.AuctionPlugin/Views/AdminProductAuctionSettingsBox.cshtml diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Components/AuctionAdminViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Components/AuctionAdminViewComponent.cs new file mode 100644 index 0000000..4205501 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Components/AuctionAdminViewComponent.cs @@ -0,0 +1,101 @@ +using Microsoft.AspNetCore.Mvc; +using Nop.Plugin.Misc.AuctionPlugin; +using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; +using Nop.Plugin.Misc.AuctionPlugin.Services; +using Nop.Services.Catalog; +using Nop.Services.Cms; +using Nop.Services.Common; +using Nop.Services.Logging; +using Nop.Web.Areas.Admin.Components; +using Nop.Web.Areas.Admin.Models.Catalog; +using Nop.Web.Areas.Admin.Models.Orders; +using Nop.Web.Framework.Components; +using Nop.Web.Framework.Factories; +using Nop.Web.Framework.Infrastructure; + + +namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Components +{ + [ViewComponent(Name = "AuctionAdmin")] + public class AuctionAdminViewComponent : AdminWidgetViewComponent + { + #region Fields + protected readonly ILogger _logger; + protected readonly IProductAttributeService _productAttributeService; + protected readonly IWidgetPluginManager _widgetPluginManager; + protected readonly AuctionSettings _auctionSettings; + protected readonly IAuctionService _auctionService; + + + + #endregion + + #region Ctor + + public AuctionAdminViewComponent( + IWidgetModelFactory widgetModelFactory, + ILogger logger, + IProductAttributeService productAttributeService, + IWidgetPluginManager widgetPluginManager, + AuctionSettings auctionSettings, + IAuctionService auctionService) : base(widgetModelFactory) + { + _logger = logger; + _productAttributeService = productAttributeService; + _widgetPluginManager = widgetPluginManager; + _auctionSettings = auctionSettings; + _auctionService = auctionService; + } + + #endregion + + #region Methods + + /// + /// Invoke the widget view component + /// + /// Widget zone + /// Additional parameters + /// + /// A task that represents the asynchronous operation + /// The task result contains the view component result + /// + public override async Task InvokeAsync(string widgetZone, object additionalData) + { + + //await base.InvokeAsync(widgetZone, additionalData); + await _logger.InformationAsync($"Admin auction widget called from {widgetZone}!"); + if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName)) + return Content(string.Empty); + + //if (!_auctionSettings.Enabled) + // return Content(string.Empty); + + //if (additionalData is not ProductDetailsModel model) + // return Content(string.Empty); + + var productId = 0; + if (!widgetZone.Equals(AdminWidgetZones.ProductDetailsButtons)) + { + await _logger.InformationAsync($"Admin auction widget not in the right widgetzone {widgetZone}!"); + return Content(string.Empty); + } + + var product = (additionalData as ProductModel); + productId = product.Id; + + var auctions = await _auctionService.GetAllAuctionsAsync() ?? new List(); + + // Assign the auctions to the ViewBag + ViewBag.Auctions = auctions; + ProductAssignToAuctionViewModel viewModel = new ProductAssignToAuctionViewModel(); + viewModel.StartingPrice = product.BasepriceAmount; + await _logger.InformationAsync($"Admin auction widget called from {widgetZone}! II. "); + return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AdminProductAuctionSettingsBox.cshtml", productId.ToString()); + } + + #endregion + } + +} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs index 808184e..c0d6dd6 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs @@ -10,6 +10,7 @@ using Nop.Services.Localization; using Nop.Services.Logging; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Services; +using Nop.Web.Framework.Models.DataTables; namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers; @@ -84,12 +85,21 @@ public class AuctionPluginAdminController : BasePluginController // } //} + public IActionResult GetAuctionViewModel() { var model = new AuctionViewModel(); return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml", model); } + + public async Task AuctionList() + { + await _logger.InformationAsync("AnnouncementList called!"); + var model = new AuctionViewModel(); + return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml", model); + } + [HttpPost] public async Task GetAuctionViewModel(AuctionViewModel viewModel) { @@ -110,6 +120,29 @@ public class AuctionPluginAdminController : BasePluginController } + [HttpPost] + public async Task GetAuctionList() + { + //await _logger.InformationAsync("GetAnnouncementList called!"); + //var total = (await _announcementService.GetAnnouncementsAsync()).Count(); + //var result = await _announcementService.GetAnnouncementsAsync(request.Page, request.PageSize); + + //return Json(new + //{ + // Data = result, + // Total = total + //}); + + try + { + return Ok(new DataTablesModel { Data = await _auctionService.GetAllAuctionsAsync() }); + } + catch (Exception ex) + { + return BadRequest(ex); + } + } + public async Task TestPage() { var model = new TestPageViewModel(); @@ -120,4 +153,18 @@ public class AuctionPluginAdminController : BasePluginController return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/TestPage.cshtml", model); } + + [HttpPost] + public async Task AssignProductToAuction(int productId, int auctionId) + { + if (productId <= 0 || auctionId <= 0) + return BadRequest(); + + var result = await _auctionService.AssignProductToAuctionAsync(productId, auctionId); + if (result) + return Ok(); + + return StatusCode(500, "Error assigning product to auction."); + } + } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/ProductAssignToAuctionViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/ProductAssignToAuctionViewModel.cs new file mode 100644 index 0000000..a38ab99 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/ProductAssignToAuctionViewModel.cs @@ -0,0 +1,18 @@ +using Nop.Web.Framework.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models +{ + public record ProductAssignToAuctionViewModel : BaseNopModel + { + public int ProductId { get; set; } + public int AuctionId { get; set; } + public decimal StartingPrice { get; set; } + public decimal BidPrice { get; set; } + public decimal BidAmount { get; set; } + } +} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AdminProductAuctionSettingsBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AdminProductAuctionSettingsBox.cshtml new file mode 100644 index 0000000..827ab92 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AdminProductAuctionSettingsBox.cshtml @@ -0,0 +1,46 @@ +@model ProductAssignToAuctionViewModel +
+

@T("Plugins.Misc.AuctionPlugin.AssignToAuction")

+ +
+ + + @* *@ + +
+ + +
+ + +
+
+ + diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml new file mode 100644 index 0000000..cce8830 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml @@ -0,0 +1,61 @@ +@using Nop.Core.Infrastructure +@using Nop.Web.Framework + + +@{ + var defaultGridPageSize = EngineContext.Current.Resolve().DefaultGridPageSize; + var gridPageSizes = EngineContext.Current.Resolve().GridPageSizes; + + Layout = "_AdminLayout"; + //page title + ViewBag.Title = T("Admin.Plugins.HomePageProduct").Text; +} + + + +
+
+
+
+
+ + @await Html.PartialAsync("Table", new DataTablesModel + { + Name = "announcement-grid", + UrlRead = new DataUrl("GetAuctionList", "AuctionPluginAdmin"), + Paging = false, + ColumnCollection = new List + { + new ColumnProperty(nameof(Auction.AuctionName)) + { + Title = "Name", + Width = "300" + }, + new ColumnProperty(nameof(Auction.StartDateUtc)) + { + Title = "Starts", + Width = "300" + }, + new ColumnProperty(nameof(Auction.Closed)) + { + Title = "Closed", + Width = "300" + } + } + }) + + + +
+
+
+
+
+ diff --git a/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs b/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs index ca87974..3a1b79b 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs @@ -28,6 +28,7 @@ public static class AuctionDefaults public static string AnnouncementRouteName => "Plugin.Misc.AuctionPlugin.Announcement"; public static string AnnouncementListRouteName => "Plugin.Misc.AuctionPlugin.AnnouncementList"; public static string AuctionRouteName => "Plugin.Misc.AuctionPlugin.Auction"; + public static string AuctionListRouteName => "Plugin.Misc.AuctionPlugin.AuctionList"; public static string TestPageRouteName => "Plugin.Misc.AuctionPlugin.TestPage"; public static string BidNotificationRouteName => "Plugin.Misc.AuctionPlugin.BidNotification"; public static string RefreshAuctionWidgetRouteName => "Plugin.Misc.AuctionPlugin.RefreshAuctionWidget"; diff --git a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs index 989391b..a2f6ede 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs @@ -5,6 +5,8 @@ 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.Widgets.AuctionPlugin.Components; using Nop.Services.Catalog; @@ -100,12 +102,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin { ArgumentNullException.ThrowIfNull(widgetZone); - if (widgetZone.Equals(PublicWidgetZones.ProductDetailsInsideOverviewButtonsBefore)) + if (widgetZone.Equals(PublicWidgetZones.ProductDetailsAfterPictures)) { return typeof(AuctionPublicViewComponent); } - if (widgetZone.Equals(AdminWidgetZones.ProductDetailsBlock)) + if (widgetZone.Equals(AdminWidgetZones.ProductDetailsButtons)) { return typeof(AuctionAdminViewComponent); } @@ -115,6 +117,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin return typeof(LiveAnnouncementViewComponent); } + if (widgetZone.Equals(PublicWidgetZones.ProductBoxAddinfoBefore)) + { + return typeof(AuctionViewComponent); + } + return typeof(AuctionViewComponent); } @@ -122,9 +129,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin { return Task.FromResult>(new List { - PublicWidgetZones.ProductDetailsInsideOverviewButtonsBefore, + PublicWidgetZones.ProductDetailsAfterPictures, PublicWidgetZones.ProductDetailsBottom, - PublicWidgetZones.HeaderAfter + PublicWidgetZones.HeaderAfter, + AdminWidgetZones.ProductDetailsButtons //AdminWidgetZones.OrderBillingAddressDetailsBottom, //AdminWidgetZones.OrderShippingAddressDetailsBottom @@ -166,6 +174,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin Url = "~/Admin/AuctionPluginAdmin/GetAuctionViewModel" }); + liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode() + { + Title = await _localizationService.GetResourceAsync("Misc.AuctionList"), + Visible = true, + IconClass = "fa-dot-circle-o", + Url = "~/Admin/AuctionPluginAdmin/AuctionList" + }); + liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode() { Title = await _localizationService.GetResourceAsync("Misc.Announcement"), diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionAdminViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionAdminViewComponent.cs deleted file mode 100644 index 205a3c9..0000000 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionAdminViewComponent.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Nop.Plugin.Misc.AuctionPlugin; -using Nop.Services.Catalog; -using Nop.Services.Cms; -using Nop.Services.Common; -using Nop.Web.Areas.Admin.Models.Orders; -using Nop.Web.Framework.Components; -using Nop.Web.Framework.Infrastructure; -using Nop.Web.Models.Catalog; - -namespace Nop.Plugin.AuctionPlugin.Components -{ - [ViewComponent(Name = "AuctionAdmin")] - public class AuctionAdminViewComponent : NopViewComponent - { - #region Fields - - protected readonly IAddressService _addressService; - protected readonly IProductAttributeService _productAttributeService; - protected readonly IWidgetPluginManager _widgetPluginManager; - protected readonly AuctionSettings _auctionSettings; - - #endregion - - #region Ctor - - public AuctionAdminViewComponent(IAddressService addressService, - IProductAttributeService productAttributeService, - IWidgetPluginManager widgetPluginManager, - AuctionSettings auctionSettings) - { - _addressService = addressService; - _productAttributeService = productAttributeService; - _widgetPluginManager = widgetPluginManager; - _auctionSettings = auctionSettings; - } - - #endregion - - #region Methods - - /// - /// Invoke the widget view component - /// - /// Widget zone - /// Additional parameters - /// - /// A task that represents the asynchronous operation - /// The task result contains the view component result - /// - public async Task InvokeAsync(string widgetZone, object additionalData) - { - - if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName)) - return Content(string.Empty); - - if (!_auctionSettings.Enabled) - return Content(string.Empty); - - //if (additionalData is not ProductDetailsModel model) - // return Content(string.Empty); - - var productId = 0; - if (widgetZone.Equals(AdminWidgetZones.ProductDetailsBlock)) - productId = (additionalData as ProductDetailsModel).Id; - - return View("~/Plugins/Misc.AuctionPlugin/Views/AdminProductAuctionSettingsBox.cshtml", productId.ToString()); - } - - #endregion - } - -} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index 36c9769..ed94aba 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -85,7 +85,7 @@ public class AuctionPublicViewComponent : NopViewComponent // return Content(string.Empty); //} - if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsInsideOverviewButtonsBefore)) + if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsAfterPictures)) { await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}"); return Content(string.Empty); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs index 1d4303c..36baec4 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Entities/ProductToAuctionMapping.cs @@ -1,5 +1,6 @@ using AyCode.Interfaces.Entities; using AyCode.Interfaces.TimeStampInfo; +using LinqToDB.Mapping; using Mango.Nop.Core.Entities; using Nop.Core; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; @@ -10,7 +11,7 @@ public partial class ProductToAuctionMapping : MgEntityBase, ITimeStampInfo//, I { public int ProductId { get; set; } public int AuctionId { get; set; } - + [NotColumn] public AuctionStatus AuctionStatus { get; set; } = AuctionStatus.None; public int StartingPrice { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs index 8b50a2a..38fae8a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs @@ -16,6 +16,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Services.Catalog; using Nop.Services.Configuration; using Nop.Services.Localization; +using Nop.Web.Areas.Admin.Factories; using Nop.Web.Framework; using Nop.Web.Framework.Mvc.Routing; @@ -59,7 +60,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure services.AddScoped(); services.AddScoped(); services.AddScoped(); - + //services.AddSingleton(); services.AddScoped(); } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs index ab6bcd6..192b071 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs @@ -34,6 +34,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure pattern: "Admin/AuctionPlugin/GetAuctionViewModel", defaults: new { controller = "AuctionPluginAdmin", action = "GetAuctionViewModel" }); + endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AuctionListRouteName, + pattern: "Admin/AuctionPlugin/AuctionList", + defaults: new { controller = "AuctionPluginAdmin", action = "AuctionList" }); + endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.TestPageRouteName, pattern: "Admin/Auction/TestPage", defaults: new { controller = "AuctionPluginAdmin", action = "TestPage" }); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj b/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj index 448060e..28fdb01 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj +++ b/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj @@ -14,6 +14,7 @@ + @@ -30,6 +31,9 @@ + + Always + Always @@ -45,7 +49,7 @@ PreserveNewest - + Always @@ -90,7 +94,6 @@ - diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index 90f892d..6389809 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -31,6 +31,7 @@ public class AuctionService : IAuctionService protected readonly AuctionDbContext _ctx; //protected readonly IRepository _customerBidRepository; //protected readonly IRepository _auctionRepository; + protected readonly IRepository _productToAuctionRepository; protected readonly IShortTermCacheManager _shortTermCacheManager; protected readonly IStaticCacheManager _staticCacheManager; protected readonly IWorkContext _workContext; @@ -44,12 +45,12 @@ public class AuctionService : IAuctionService /// Store pickup point repository /// Short term cache manager /// Cache manager - public AuctionService(AuctionDbContext ctx, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, IWorkContext workContext) + public AuctionService(AuctionDbContext ctx, IRepository auctionRepository, IRepository productToAuctionRepository, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, IWorkContext workContext) { _ctx = ctx; //_customerBidRepository = customerBidRepository; //_auctionRepository = auctionRepository; - + _productToAuctionRepository = productToAuctionRepository; _shortTermCacheManager = shortTermCacheManager; _staticCacheManager = staticCacheManager; _workContext = workContext; @@ -146,6 +147,22 @@ public class AuctionService : IAuctionService return []; } + public async Task AssignProductToAuctionAsync(int productId, int auctionId) + { + var auction = await _ctx.Auctions.GetByIdAsync(auctionId); + if (auction == null) + return false; + + var mapping = new ProductToAuctionMapping + { + ProductId = productId, + AuctionId = auctionId + }; + + await _productToAuctionRepository.InsertAsync(mapping); + return true; + } + #endregion #endregion diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs index 2f5508f..f8ed2a2 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs @@ -1,4 +1,5 @@ -using Nop.Core; +using Microsoft.AspNetCore.Mvc; +using Nop.Core; using Nop.Plugin.Misc.AuctionPlugin.Domains; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; @@ -32,4 +33,6 @@ public interface IAuctionService Task InsertAuctionAsync(Auction auction); Task> GetAllAuctionsAsync(); + + Task AssignProductToAuctionAsync(int productId, int auctionId); } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/MyProductModelFactory.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/MyProductModelFactory.cs index b54193c..33994da 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/MyProductModelFactory.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/MyProductModelFactory.cs @@ -34,46 +34,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Services { public class MyProductModelFactory : ProductModelFactory { - protected readonly CaptchaSettings _captchaSettings; - protected readonly CatalogSettings _catalogSettings; - protected readonly CustomerSettings _customerSettings; - protected readonly ICategoryService _categoryService; - protected readonly ICurrencyService _currencyService; - protected readonly ICustomerService _customerService; - protected readonly IDateRangeService _dateRangeService; - protected readonly IDateTimeHelper _dateTimeHelper; - protected readonly IDownloadService _downloadService; - protected readonly IGenericAttributeService _genericAttributeService; - protected readonly IJsonLdModelFactory _jsonLdModelFactory; - protected readonly ILocalizationService _localizationService; - protected readonly IManufacturerService _manufacturerService; - protected readonly IPermissionService _permissionService; - protected readonly IPictureService _pictureService; - protected readonly IPriceCalculationService _priceCalculationService; - protected readonly IPriceFormatter _priceFormatter; - protected readonly IProductAttributeParser _productAttributeParser; - protected readonly IProductAttributeService _productAttributeService; - protected readonly IProductService _productService; - protected readonly IProductTagService _productTagService; - protected readonly IProductTemplateService _productTemplateService; - protected readonly IReviewTypeService _reviewTypeService; - protected readonly IShoppingCartService _shoppingCartService; - protected readonly ISpecificationAttributeService _specificationAttributeService; - protected readonly IStaticCacheManager _staticCacheManager; - protected readonly IStoreContext _storeContext; - protected readonly IStoreService _storeService; - protected readonly IShoppingCartModelFactory _shoppingCartModelFactory; - protected readonly ITaxService _taxService; - protected readonly IUrlRecordService _urlRecordService; - protected readonly IVendorService _vendorService; - protected readonly IVideoService _videoService; - protected readonly IWebHelper _webHelper; - protected readonly IWorkContext _workContext; - protected readonly MediaSettings _mediaSettings; - protected readonly OrderSettings _orderSettings; - protected readonly SeoSettings _seoSettings; - protected readonly ShippingSettings _shippingSettings; - protected readonly VendorSettings _vendorSettings; + private static readonly char[] _separator = [',']; public MyProductModelFactory(CaptchaSettings captchaSettings, @@ -151,46 +112,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Services vendorSettings ) { - _captchaSettings = captchaSettings; - _catalogSettings = catalogSettings; - _customerSettings = customerSettings; - _categoryService = categoryService; - _currencyService = currencyService; - _customerService = customerService; - _dateRangeService = dateRangeService; - _dateTimeHelper = dateTimeHelper; - _downloadService = downloadService; - _genericAttributeService = genericAttributeService; - _jsonLdModelFactory = jsonLdModelFactory; - _localizationService = localizationService; - _manufacturerService = manufacturerService; - _permissionService = permissionService; - _pictureService = pictureService; - _priceCalculationService = priceCalculationService; - _priceFormatter = priceFormatter; - _productAttributeParser = productAttributeParser; - _productAttributeService = productAttributeService; - _productService = productService; - _productTagService = productTagService; - _productTemplateService = productTemplateService; - _reviewTypeService = reviewTypeService; - _shoppingCartService = shoppingCartService; - _specificationAttributeService = specificationAttributeService; - _staticCacheManager = staticCacheManager; - _storeContext = storeContext; - _storeService = storeService; - _shoppingCartModelFactory = shoppingCartModelFactory; - _taxService = taxService; - _urlRecordService = urlRecordService; - _vendorService = vendorService; - _webHelper = webHelper; - _workContext = workContext; - _mediaSettings = mediaSettings; - _orderSettings = orderSettings; - _seoSettings = seoSettings; - _shippingSettings = shippingSettings; - _vendorSettings = vendorSettings; - _videoService = videoService; + } public override async Task PrepareProductDetailsModelAsync(Product product, diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/AdminProductAuctionSettingsBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/AdminProductAuctionSettingsBox.cshtml deleted file mode 100644 index 8f810cc..0000000 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/AdminProductAuctionSettingsBox.cshtml +++ /dev/null @@ -1,10 +0,0 @@ -@model string - - - - @T("Plugins.Widgets.What3words.Address.Field.Label") - - - @Model - - diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index cb8331f..f95d422 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -3,33 +3,36 @@ @* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@
-

Auction Public View Component

-

@T("Plugins.Misc.AuctionPlugin.BidBox.Field.Label"):

-

DEBUG DATA:

-

@Model.ProductId

-

@Model.CustomerId

-

@Model.BasePrice

+
+
+ Base Price: + + @String.Format("{0:c}", Model.BasePrice) + @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@ + +
Current Price: - @Model.CurrentPrice + + @String.Format("{0:c}", Model.CurrentPrice) + @* @(decimal?.Round(Model.CurrentPrice, 2, MidpointRounding.AwayFromZero)) *@ +
Bid Step: - @Model.LicitStep + @String.Format("{0:c}", Model.LicitStep) +
+
+
+ -
- - -
- - - - @@ -38,9 +41,9 @@