diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs index 14a0b1c..d51d248 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Controllers/AuctionPluginAdminController.cs @@ -8,6 +8,8 @@ using Nop.Plugin.Misc.AuctionPlugin; using Nop.Services.Messages; using Nop.Services.Localization; using Nop.Services.Logging; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; +using Nop.Plugin.Misc.AuctionPlugin.Services; namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers; @@ -21,16 +23,18 @@ public class AuctionPluginAdminController : BasePluginController private readonly INotificationService _notificationService; private readonly ISettingService _settingService; private readonly AuctionSettings _auctionSettings; + private readonly IAuctionService _auctionService; private readonly ILogger _logger; //public AuctionPluginAdminController(SignalRservice signalRservice) - public AuctionPluginAdminController(ILocalizationService localizationService, INotificationService notificationService, ISettingService settingService, AuctionSettings auctionSettings, ILogger logger) + public AuctionPluginAdminController(ILocalizationService localizationService, INotificationService notificationService, ISettingService settingService, AuctionSettings auctionSettings, ILogger logger, IAuctionService auctionService) { _localizationService = localizationService; _notificationService = notificationService; _settingService = settingService; _auctionSettings = auctionSettings; //_signalRservice = signalRservice; + _auctionService = auctionService; _logger = logger; } @@ -79,4 +83,37 @@ public class AuctionPluginAdminController : BasePluginController // return Json(new { success = false, message = $"Error: {ex.Message}" }); // } //} + + public IActionResult GetAuctionViewModel() + { + var model = new AuctionViewModel(); + return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml", model); + } + + [HttpPost] + public async Task GetAuctionViewModel(AuctionViewModel viewModel) + { + Auction objOfAuctionDomain = new Auction(); + objOfAuctionDomain.AuctionName = viewModel.AuctionName; + objOfAuctionDomain.AuctionType = viewModel.AuctionType; + objOfAuctionDomain.StartDateUtc = viewModel.StartDateUtc; + objOfAuctionDomain.EndDateUtc = viewModel.EndDateUtc; + objOfAuctionDomain.Closed = viewModel.Closed; + objOfAuctionDomain.Created = DateTime.UtcNow; + await _auctionService.InsertAuctionAsync(objOfAuctionDomain); + + //if (viewModel.IsActive == true) + //{ + // await _announcementHubContext.Clients.All.SendAsync("send", viewModel.Body.ToString()); + //} + return RedirectToAction("AuctionList"); + + } + + public IActionResult TestPage() + { + var model = new TestPageViewModel(); + return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml", model); + } + } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/AuctionViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/AuctionViewModel.cs new file mode 100644 index 0000000..739bd91 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/AuctionViewModel.cs @@ -0,0 +1,22 @@ +using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; +using Nop.Web.Framework.Models; +using Nop.Web.Framework.Mvc.ModelBinding; + +namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models +{ + public record AuctionViewModel : BaseNopModel + { + public string PageTitle { get; set; } + + [NopResourceDisplayName("Name")] + public string AuctionName { get; set; } + public AuctionType AuctionType { get; set; } + + public DateTime StartDateUtc { get; set; } + public DateTime? EndDateUtc { get; set; } + + public bool Closed { get; set; } + + } + +} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/KendoGridRequestModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/KendoGridRequestModel.cs deleted file mode 100644 index d130d8c..0000000 --- a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/KendoGridRequestModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models -{ - public class KendoGridRequestModel - { - // Page number - public int Page { get; set; } = 1; - - // Page size (number of items per page) - public int PageSize { get; set; } = 10; - - // Field to sort by - public string SortField { get; set; } - - // Sort direction (e.g., "asc" or "desc") - public string SortDirection { get; set; } - - // Optional: Filtering parameters, can be customized to fit your needs - public string FilterField { get; set; } - public string FilterValue { get; set; } - } -} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/TestPageViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/TestPageViewModel.cs new file mode 100644 index 0000000..3f9586d --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Models/TestPageViewModel.cs @@ -0,0 +1,17 @@ +using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; +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 TestPageViewModel : BaseNopModel + { + public string Title { get; set; } + public string Message { get; set; } + public Auction TestAuction { get; set; } + } +} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/Announcement.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/Announcement.cshtml index d6fbf17..a9f42ee 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/Announcement.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/Announcement.cshtml @@ -23,7 +23,7 @@ Create Announcement - LiveAnnouncement + Announcements diff --git a/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml new file mode 100644 index 0000000..96ffc39 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml @@ -0,0 +1,90 @@ +@model AuctionViewModel +@using Nop.Core.Infrastructure +@using Nop.Web.Framework + +@{ + var defaultGridPageSize = EngineContext.Current.Resolve().DefaultGridPageSize; + var gridPageSizes = EngineContext.Current.Resolve().GridPageSizes; + Layout = "_AdminLayout"; + //page title + Model.PageTitle = "Auctions page"; + ViewBag.Title = Model.PageTitle; +} + +@using (Html.BeginForm()) +{ +
+

+ Create Auction +

+ +
+ + + Auctions +
+
+ +
+
+
+ +
+
+
+ +} \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs b/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs index 4ecd9a7..00a35c2 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/AuctionDefaults.cs @@ -27,6 +27,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"; /// /// Gets the name of autosuggest component diff --git a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs index 6f151cf..77b75c4 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs @@ -140,6 +140,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin rootNode.ChildNodes.Add(liveAnnouncementPluginNode); } + + liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode() { Title = await _localizationService.GetResourceAsync("Plugins.Configure"), @@ -149,6 +151,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin }); + liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode() + { + Title = await _localizationService.GetResourceAsync("Misc.Auction"), + Visible = true, + IconClass = "fa-dot-circle-o", + Url = "~/Admin/AuctionPluginAdmin/GetAuctionViewModel" + }); + liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode() { Title = await _localizationService.GetResourceAsync("Misc.Announcement"), diff --git a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs index 1b72eb8..4f0e4a4 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/RouteProvider.cs @@ -29,6 +29,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AnnouncementListRouteName, pattern: "Admin/Announcement/AnnouncementList", defaults: new { controller = "Announcement", action = "AnnouncementList"}); + + endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AuctionRouteName, + pattern: "Admin/AuctionPlugin/GetAuctionViewModel", + defaults: new { controller = "AuctionPluginAdmin", action = "GetAuctionViewModel" }); } /// diff --git a/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj b/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj index bd40a99..611c054 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj +++ b/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj @@ -13,6 +13,7 @@ + @@ -27,6 +28,9 @@ + + Always + PreserveNewest diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index 3209522..7beeb68 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -27,6 +27,7 @@ public class AuctionService : IAuctionService #region Fields protected readonly IRepository _customerBidRepository; + protected readonly IRepository _auctionRepository; protected readonly IShortTermCacheManager _shortTermCacheManager; protected readonly IStaticCacheManager _staticCacheManager; @@ -40,11 +41,14 @@ public class AuctionService : IAuctionService /// Store pickup point repository /// Short term cache manager /// Cache manager - public AuctionService(IRepository customerBidRepository, + public AuctionService( + IRepository customerBidRepository, + IRepository auctionRepository, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager) { _customerBidRepository = customerBidRepository; + _auctionRepository = auctionRepository; _shortTermCacheManager = shortTermCacheManager; _staticCacheManager = staticCacheManager; } @@ -106,5 +110,13 @@ public class AuctionService : IAuctionService await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY); } + #region auctions + public virtual async Task InsertAuctionAsync(Auction auction) + { + await _auctionRepository.InsertAsync(auction, false); + await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY); + } + #endregion + #endregion } \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs index e0a2393..eecc414 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/IAuctionService.cs @@ -20,16 +20,14 @@ public interface IAuctionService /// The task result contains the bids /// Task> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue); - Task GetBidByIdAsync(int bidId); - Task InsertBidAsync(AuctionBid auctionBid); - Task UpdateBidAsync(AuctionBid auctionBid); - Task DeleteBidAsync(AuctionBid pickupPoint); + + Task InsertAuctionAsync(Auction auction); } \ No newline at end of file