diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index c041551..2adaa56 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -2,10 +2,12 @@ using Nop.Core; 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.Cms; using Nop.Services.Common; +using Nop.Services.Customers; using Nop.Services.Logging; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; @@ -23,6 +25,7 @@ public class AuctionPublicViewComponent : NopViewComponent protected readonly IWorkContext _workContext; protected readonly AuctionService _auctionService; protected readonly AuctionSettings _auctionSettings; + protected readonly ICustomerService _customerService; protected readonly ILogger _logger; #endregion @@ -35,6 +38,7 @@ public class AuctionPublicViewComponent : NopViewComponent IWorkContext workContext, AuctionService auctionService, AuctionSettings auctionSettings, + ICustomerService customerService, ILogger logger) { _addressService = addressService; @@ -43,6 +47,7 @@ public class AuctionPublicViewComponent : NopViewComponent _workContext = workContext; _auctionService = auctionService; _auctionSettings = auctionSettings; + _customerService = customerService; _logger = logger; } @@ -100,6 +105,7 @@ public class AuctionPublicViewComponent : NopViewComponent List auctionIds = await _auctionService.GetProductToAuctionsByProductIdAsync(productDetailsModel.Id); int auctionId = 0; + AuctionDto auction; if(auctionIds == null || auctionIds.Count == 0) { return Content(string.Empty); @@ -112,27 +118,32 @@ public class AuctionPublicViewComponent : NopViewComponent //we have more auctions so we return the closest open foreach (var auctionMapping in auctionIds) { - var auction = await _auctionService.GetAuctionDtoByIdAsync(auctionMapping.AuctionId); - if (!auction.Closed) + var auctionItem = await _auctionService.GetAuctionDtoByIdAsync(auctionMapping.AuctionId); + if (!auctionItem.Closed) { - openAuctionList.Add(auction); + openAuctionList.Add(auctionItem); } } //first auction that started or strats not earlier than yesterday - auctionId = openAuctionList.Where(x => x.StartDateUtc > DateTime.UtcNow.AddDays(-1)).OrderBy(x => x.StartDateUtc).FirstOrDefault().Id; + auction = openAuctionList.Where(x => x.StartDateUtc > DateTime.UtcNow.AddDays(-1)).OrderBy(x => x.StartDateUtc).FirstOrDefault(); + auctionId = auction.Id; } else { - var valami = await _auctionService.GetAuctionDtoByIdAsync(auctionIds.FirstOrDefault().AuctionId); - auctionId = valami.Id; + auction = await _auctionService.GetAuctionDtoByIdAsync(auctionIds.FirstOrDefault().AuctionId); + auctionId = auction.Id; + } var productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id); + productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer); + productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer); + productBidBoxViewModel.AuctionClosed = auction.Closed; productBidBoxViewModel.WidgetZone = widgetZone; productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue; productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue; - productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id; + productBidBoxViewModel.ProductToAuctionsId = productToAuctionId.FirstOrDefault().Id; productBidBoxViewModel.AuctionId = auctionId; productBidBoxViewModel.CustomerId = customer.Id; productBidBoxViewModel.ProductId = productDetailsModel.Id; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs index 47e68e2..3707101 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs @@ -1,4 +1,5 @@ -using Nop.Web.Framework.Models; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; +using Nop.Web.Framework.Models; using System; using System.Collections.Generic; using System.Linq; @@ -9,8 +10,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models { public record ProductBidBoxViewModel: BaseNopModel { - public int ProductToAuctionId { get; set; } + public int ProductToAuctionsId { get; set; } + public bool IsAdmin { get; set; } + public bool IsGuest { get; set; } public int AuctionId { get; set; } + public bool AuctionClosed { get; set; } public int ProductId { get; set; } public int CustomerId { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index d674954..84c7b07 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -3,41 +3,76 @@ @* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@ - -
+@{ + if (!Model.IsGuest) + { +
+

This item is under auction!

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

Manage auction!

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

No access to admin level buttons

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

This item is under auction!

+
+ +

Please log in or register to participate!

+
+
+ } +}