fixes
This commit is contained in:
parent
354bdb6556
commit
d9b4a7ffdd
|
|
@ -1,10 +1,7 @@
|
|||
using ExCSS;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Nop.Core;
|
||||
using Nop.Core.Domain.Catalog;
|
||||
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;
|
||||
|
|
@ -15,196 +12,198 @@ using Nop.Web.Framework.Components;
|
|||
using Nop.Web.Framework.Infrastructure;
|
||||
using Nop.Web.Models.Catalog;
|
||||
using Nop.Web.Framework.Mvc.Routing;
|
||||
using DocumentFormat.OpenXml.EMMA;
|
||||
using Nop.Services.Catalog;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Components;
|
||||
|
||||
public class AuctionPublicViewComponent : NopViewComponent
|
||||
{
|
||||
#region Fields
|
||||
#region Fields
|
||||
|
||||
protected readonly IAddressService _addressService;
|
||||
protected readonly IGenericAttributeService _genericAttributeService;
|
||||
protected readonly IWidgetPluginManager _widgetPluginManager;
|
||||
protected readonly IWorkContext _workContext;
|
||||
protected readonly AuctionService _auctionService;
|
||||
protected readonly AuctionSettings _auctionSettings;
|
||||
protected readonly ICustomerService _customerService;
|
||||
protected readonly IWebHelper _webHelper;
|
||||
protected readonly IProductService _productService;
|
||||
protected readonly ILogger _logger;
|
||||
protected readonly MyProductModelFactory _myProductModelFactory;
|
||||
//private readonly IAddressService _addressService;
|
||||
//private readonly IGenericAttributeService _genericAttributeService;
|
||||
private readonly IWidgetPluginManager _widgetPluginManager;
|
||||
private readonly IWorkContext _workContext;
|
||||
private readonly AuctionService _auctionService;
|
||||
//private readonly AuctionSettings _auctionSettings;
|
||||
private readonly ICustomerService _customerService;
|
||||
private readonly IWebHelper _webHelper;
|
||||
private readonly IProductService _productService;
|
||||
private readonly ILogger _logger;
|
||||
private readonly MyProductModelFactory _myProductModelFactory;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Ctor
|
||||
#region Ctor
|
||||
|
||||
public AuctionPublicViewComponent(IAddressService addressService,
|
||||
IGenericAttributeService genericAttributeService,
|
||||
IWidgetPluginManager widgetPluginManager,
|
||||
IWorkContext workContext,
|
||||
AuctionService auctionService,
|
||||
AuctionSettings auctionSettings,
|
||||
ICustomerService customerService,
|
||||
IWebHelper webHelper,
|
||||
IProductService productService,
|
||||
MyProductModelFactory myProductModelFactory,
|
||||
ILogger logger)
|
||||
{
|
||||
_addressService = addressService;
|
||||
_genericAttributeService = genericAttributeService;
|
||||
_widgetPluginManager = widgetPluginManager;
|
||||
_workContext = workContext;
|
||||
_auctionService = auctionService;
|
||||
_auctionSettings = auctionSettings;
|
||||
_customerService = customerService;
|
||||
_webHelper = webHelper;
|
||||
_productService = productService;
|
||||
_myProductModelFactory = myProductModelFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
public AuctionPublicViewComponent(
|
||||
//IAddressService addressService,
|
||||
//IGenericAttributeService genericAttributeService,
|
||||
IWidgetPluginManager widgetPluginManager,
|
||||
IWorkContext workContext,
|
||||
AuctionService auctionService,
|
||||
//AuctionSettings auctionSettings,
|
||||
ICustomerService customerService,
|
||||
IWebHelper webHelper,
|
||||
IProductService productService,
|
||||
MyProductModelFactory myProductModelFactory,
|
||||
ILogger logger)
|
||||
{
|
||||
//_addressService = addressService;
|
||||
//_genericAttributeService = genericAttributeService;
|
||||
_widgetPluginManager = widgetPluginManager;
|
||||
_workContext = workContext;
|
||||
_auctionService = auctionService;
|
||||
//_auctionSettings = auctionSettings;
|
||||
_customerService = customerService;
|
||||
_webHelper = webHelper;
|
||||
_productService = productService;
|
||||
_myProductModelFactory = myProductModelFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Invoke the widget view component
|
||||
/// </summary>
|
||||
/// <param name="widgetZone">Widget zone</param>
|
||||
/// <param name="additionalData">Additional parameters</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation
|
||||
/// The task result contains the view component result
|
||||
/// </returns>
|
||||
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
|
||||
{
|
||||
|
||||
|
||||
await _logger.InformationAsync("WidgetViewComponent called");
|
||||
|
||||
//ensure that widget is active and enabled
|
||||
var customer = await _workContext.GetCurrentCustomerAsync();
|
||||
await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}");
|
||||
|
||||
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
|
||||
return Content(string.Empty);
|
||||
|
||||
await _logger.InformationAsync("WidgetViewComponent widget active");
|
||||
|
||||
//if (!_auctionSettings.Enabled)
|
||||
// return Content(string.Empty);
|
||||
|
||||
var productDetailsModel = additionalData as ProductDetailsModel;
|
||||
|
||||
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
|
||||
|
||||
//if (productDetailsModel is null)
|
||||
//{
|
||||
|
||||
// await _logger.InformationAsync("WidgetViewComponent productdetailsmodel is null");
|
||||
// return Content(string.Empty);
|
||||
//}
|
||||
|
||||
if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
|
||||
{
|
||||
await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}");
|
||||
return Content(string.Empty);
|
||||
}
|
||||
|
||||
await _logger.InformationAsync("WidgetViewComponent called II");
|
||||
|
||||
//is it under Auction?
|
||||
|
||||
var productId = productDetailsModel.Id;
|
||||
|
||||
var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault();
|
||||
|
||||
if (productToAuction == null)
|
||||
{
|
||||
return Content(string.Empty);
|
||||
}
|
||||
|
||||
var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, false, false));
|
||||
auctionDto.ProductToAuctionDtos.Add(productToAuction);
|
||||
|
||||
var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto);
|
||||
//List<ProductToAuctionMapping> productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id);
|
||||
|
||||
AuctionStatus status = productToAuction.AuctionStatus;
|
||||
//bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning;
|
||||
//bool isFirstWarning = status == AuctionStatus.FirstWarning;
|
||||
|
||||
var detailedAuctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, true, false));
|
||||
|
||||
ProductToAuctionDto nextProductToAuction;
|
||||
ProductToAuctionDto lastProductToAuction;
|
||||
string nextUrl = "";
|
||||
string lastUrl = "";
|
||||
string nextImageUrl = "";
|
||||
string lastImageUrl = "";
|
||||
string nextProductName = "";
|
||||
string lastProductName = "";
|
||||
|
||||
if (productToAuction.SortIndex < detailedAuctionDto.ProductToAuctionDtos.Count)
|
||||
{
|
||||
nextProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex + 1).FirstOrDefault();
|
||||
var nextProductId = nextProductToAuction.ProductId;
|
||||
var nextProduct = await _productService.GetProductByIdAsync(nextProductId);
|
||||
var nextDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(nextProduct);
|
||||
nextUrl = Url.RouteUrl<Product>(new { nextDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
|
||||
nextImageUrl = nextDetails.DefaultPictureModel.FullSizeImageUrl;
|
||||
nextProductName = nextDetails.SeName;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
nextProductToAuction = null;
|
||||
}
|
||||
|
||||
if (productToAuction.SortIndex > 1)
|
||||
{
|
||||
lastProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex - 1).FirstOrDefault();
|
||||
var lastProductId = lastProductToAuction.ProductId;
|
||||
var lastProduct = await _productService.GetProductByIdAsync(lastProductId);
|
||||
var lastDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(lastProduct);
|
||||
lastUrl = Url.RouteUrl<Product>(new { lastDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
|
||||
lastImageUrl = lastDetails.DefaultPictureModel.FullSizeImageUrl;
|
||||
lastProductName = lastDetails.SeName;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastProductToAuction = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invoke the widget view component
|
||||
/// </summary>
|
||||
/// <param name="widgetZone">Widget zone</param>
|
||||
/// <param name="additionalData">Additional parameters</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous operation
|
||||
/// The task result contains the view component result
|
||||
/// </returns>
|
||||
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
|
||||
{
|
||||
|
||||
|
||||
productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
|
||||
productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
|
||||
productBidBoxViewModel.AuctionClosed = auctionDto.Closed;
|
||||
productBidBoxViewModel.AuctionStatus = status;
|
||||
productBidBoxViewModel.WidgetZone = widgetZone;
|
||||
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
|
||||
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
|
||||
//productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id;
|
||||
//productBidBoxViewModel.AuctionId = auctionId;
|
||||
productBidBoxViewModel.CustomerId = customer.Id;
|
||||
productBidBoxViewModel.ProductId = productDetailsModel.Id;
|
||||
//productBidBoxViewModel.NextProductUrl = Url.RouteUrl("Product", productDetailsModel.SeName);
|
||||
productBidBoxViewModel.NextProductUrl = nextUrl;
|
||||
productBidBoxViewModel.LastProductUrl = lastUrl;
|
||||
productBidBoxViewModel.LastProductImageUrl = lastImageUrl;
|
||||
productBidBoxViewModel.NextProductImageUrl = nextImageUrl;
|
||||
productBidBoxViewModel.LastProductName = lastProductName;
|
||||
productBidBoxViewModel.NextProductName = nextProductName;
|
||||
productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation
|
||||
productBidBoxViewModel.NextBidPrice = productToAuction.CurrentPrice + productBidBoxViewModel.LicitStep;
|
||||
await _logger.InformationAsync("WidgetViewComponent called");
|
||||
|
||||
//ensure that widget is active and enabled
|
||||
var customer = await _workContext.GetCurrentCustomerAsync();
|
||||
await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}");
|
||||
|
||||
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
|
||||
return Content(string.Empty);
|
||||
|
||||
await _logger.InformationAsync("WidgetViewComponent widget active");
|
||||
|
||||
//if (!_auctionSettings.Enabled)
|
||||
// return Content(string.Empty);
|
||||
|
||||
var productDetailsModel = (additionalData as ProductDetailsModel)!;
|
||||
|
||||
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
|
||||
|
||||
//if (productDetailsModel is null)
|
||||
//{
|
||||
|
||||
// await _logger.InformationAsync("WidgetViewComponent productdetailsmodel is null");
|
||||
// return Content(string.Empty);
|
||||
//}
|
||||
|
||||
if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
|
||||
{
|
||||
await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}");
|
||||
return Content(string.Empty);
|
||||
}
|
||||
|
||||
await _logger.InformationAsync("WidgetViewComponent called II");
|
||||
|
||||
//is it under Auction?
|
||||
|
||||
var productId = productDetailsModel.Id;
|
||||
|
||||
var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault();
|
||||
|
||||
if (productToAuction == null)
|
||||
{
|
||||
return Content(string.Empty);
|
||||
}
|
||||
|
||||
var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, false, false));
|
||||
auctionDto.ProductToAuctionDtos.Add(productToAuction);
|
||||
|
||||
var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto);
|
||||
//List<ProductToAuctionMapping> productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id);
|
||||
|
||||
var status = productToAuction.AuctionStatus;
|
||||
//bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning;
|
||||
//bool isFirstWarning = status == AuctionStatus.FirstWarning;
|
||||
|
||||
var detailedAuctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, true, false));
|
||||
|
||||
ProductToAuctionDto nextProductToAuction;
|
||||
ProductToAuctionDto lastProductToAuction;
|
||||
var nextUrl = "";
|
||||
var lastUrl = "";
|
||||
var nextImageUrl = "";
|
||||
var lastImageUrl = "";
|
||||
var nextProductName = "";
|
||||
var lastProductName = "";
|
||||
|
||||
if (productToAuction.SortIndex < detailedAuctionDto.ProductToAuctionDtos.Count)
|
||||
{
|
||||
nextProductToAuction = detailedAuctionDto.ProductToAuctionDtos.FirstOrDefault(x => x.SortIndex == productToAuction.SortIndex + 1);
|
||||
if (nextProductToAuction != null)
|
||||
{
|
||||
var nextProductId = nextProductToAuction.ProductId;
|
||||
var nextProduct = await _productService.GetProductByIdAsync(nextProductId);
|
||||
var nextDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(nextProduct);
|
||||
nextUrl = Url.RouteUrl<Product>(new { nextDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
|
||||
nextImageUrl = nextDetails.DefaultPictureModel.FullSizeImageUrl;
|
||||
nextProductName = nextDetails.SeName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nextProductToAuction = null;
|
||||
}
|
||||
|
||||
if (productToAuction.SortIndex > 1)
|
||||
{
|
||||
lastProductToAuction = detailedAuctionDto.ProductToAuctionDtos.FirstOrDefault(x => x.SortIndex == productToAuction.SortIndex - 1);
|
||||
if (lastProductToAuction != null)
|
||||
{
|
||||
var lastProductId = lastProductToAuction.ProductId;
|
||||
var lastProduct = await _productService.GetProductByIdAsync(lastProductId);
|
||||
var lastDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(lastProduct);
|
||||
lastUrl = Url.RouteUrl<Product>(new { lastDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
|
||||
lastImageUrl = lastDetails.DefaultPictureModel.FullSizeImageUrl;
|
||||
lastProductName = lastDetails.SeName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastProductToAuction = null;
|
||||
}
|
||||
|
||||
productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
|
||||
productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
|
||||
productBidBoxViewModel.AuctionClosed = auctionDto.Closed;
|
||||
productBidBoxViewModel.AuctionStatus = status;
|
||||
productBidBoxViewModel.WidgetZone = widgetZone;
|
||||
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
|
||||
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
|
||||
//productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id;
|
||||
//productBidBoxViewModel.AuctionId = auctionId;
|
||||
productBidBoxViewModel.CustomerId = customer.Id;
|
||||
productBidBoxViewModel.ProductId = productDetailsModel.Id;
|
||||
//productBidBoxViewModel.NextProductUrl = Url.RouteUrl("Product", productDetailsModel.SeName);
|
||||
productBidBoxViewModel.NextProductUrl = nextUrl;
|
||||
productBidBoxViewModel.LastProductUrl = lastUrl;
|
||||
productBidBoxViewModel.LastProductImageUrl = lastImageUrl;
|
||||
productBidBoxViewModel.NextProductImageUrl = nextImageUrl;
|
||||
productBidBoxViewModel.LastProductName = lastProductName;
|
||||
productBidBoxViewModel.NextProductName = nextProductName;
|
||||
productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation
|
||||
productBidBoxViewModel.NextBidPrice = AuctionService.GetNextBidPrice(productToAuction.CurrentPrice, productBidBoxViewModel.LicitStep);
|
||||
|
||||
|
||||
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel);
|
||||
}
|
||||
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
|
|
@ -323,11 +323,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
|||
}
|
||||
|
||||
private static decimal GetStepAmount(decimal currentBidPrice) => AuctionService.GetStepAmount(currentBidPrice);
|
||||
private static decimal GetNextBidPrice(decimal currentBidPrice) => GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
|
||||
private static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount)
|
||||
{
|
||||
return currentBidPrice + stepAmount;
|
||||
}
|
||||
private static decimal GetNextBidPrice(decimal currentBidPrice) => AuctionService.GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
|
||||
private static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount) => AuctionService.GetNextBidPrice(currentBidPrice, stepAmount);
|
||||
|
||||
private static bool IsValidRequestAuctionStatus(AuctionStatus newStatus, AuctionStatus oldStatus)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using Newtonsoft.Json;
|
||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||
using Nop.Web.Framework.Models;
|
||||
using Nop.Web.Framework.Mvc.ModelBinding;
|
||||
|
||||
namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
||||
{
|
||||
|
|
@ -29,11 +28,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
|||
public AuctionPublicInfoModel(AuctionDto auctionDto) : this()
|
||||
{
|
||||
AuctionDto = auctionDto;
|
||||
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First();
|
||||
|
||||
StartDate = AuctionDto.StartDateUtc;
|
||||
|
||||
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.FirstOrDefault();
|
||||
if (FirstProductToAuction == null) return;
|
||||
|
||||
ProductId = FirstProductToAuction.ProductId;
|
||||
ProductToAuctionMappingId = FirstProductToAuction.Id;
|
||||
StartDate = AuctionDto.StartDateUtc;
|
||||
IsActive = FirstProductToAuction.IsActiveItem;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
|||
|
||||
public int AuctionId { get; set; }
|
||||
public bool AuctionClosed { get; set; }
|
||||
public bool IsItemActive => FirstProductToAuction.IsActiveItem;
|
||||
public bool IsItemActive => FirstProductToAuction?.IsActiveItem ?? false;
|
||||
public AuctionStatus AuctionStatus { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
|
||||
|
|
@ -62,9 +62,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
|||
public ProductBidBoxViewModel(AuctionDto auctionDto) : this()
|
||||
{
|
||||
AuctionDto = auctionDto;
|
||||
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First();
|
||||
|
||||
AuctionId = auctionDto.Id;
|
||||
|
||||
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.FirstOrDefault();
|
||||
if (FirstProductToAuction == null) return;
|
||||
|
||||
ProductId = FirstProductToAuction.ProductId;
|
||||
ProductToAuctionId = FirstProductToAuction.Id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,12 @@ public class AuctionService : IAuctionService
|
|||
//200 000 000 Ft fölött 20 000 000 Ft-tal
|
||||
}
|
||||
|
||||
public static decimal GetNextBidPrice(decimal currentBidPrice) => GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
|
||||
public static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount)
|
||||
{
|
||||
return currentBidPrice + stepAmount;
|
||||
}
|
||||
|
||||
public async Task ResetProductToAuctionByProductId(int productId)
|
||||
=> await ResetProductToAuctionAsync(await _ctx.ProductToAuctions.GetByProductId(productId).FirstOrDefaultAsync());
|
||||
|
||||
|
|
|
|||
|
|
@ -7,518 +7,519 @@
|
|||
|
||||
|
||||
@{
|
||||
if (!Model.IsGuest)
|
||||
{
|
||||
var bgClass = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
|
||||
bool bidButtonActive = Model.IsItemActive && (Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId && !Model.IsAdmin) ? true : false;
|
||||
string title = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "Your bid is leading" : "Place a bid!";
|
||||
<div class="d-flex justify-content-between" id="otherAuctionItems">
|
||||
<a href="@(string.IsNullOrEmpty(Model.LastProductUrl) ? "#" : Model.LastProductUrl)" @(string.IsNullOrEmpty(Model.LastProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.LastProductImageUrl) ? "https://placehold.co/400" : Model.LastProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.LastProductUrl) ? "Start of list" : "Back to last")</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<a href="@(string.IsNullOrEmpty(Model.NextProductUrl) ? "#" : Model.NextProductUrl)" @(string.IsNullOrEmpty(Model.NextProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.NextProductImageUrl) ? "https://placehold.co/400" : Model.NextProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.NextProductUrl) ? "End of list" : "Coming up next...")</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
<div id="publicProductBidBox" class="p-3 @bgClass text-white">
|
||||
<h4 id="bidBoxTitle">@title</h4>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<strong>Base Price:</strong>
|
||||
<span class="value">
|
||||
@($"{Model.BasePrice:c}")
|
||||
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Bid Step:</strong>
|
||||
<span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(bidButtonActive)">
|
||||
Bid @($"{Model.NextBidPrice:c}")
|
||||
</button>
|
||||
@* <button id="bidButton" class="btn btn-success">
|
||||
|
||||
Bid @String.Format("{0:c}", Model.NextBidPrice)
|
||||
</button> *@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@* <button id="testButton" class="btn btn-success">
|
||||
TestButton
|
||||
</button> *@
|
||||
|
||||
<div id="bidFeedback" class="mt-3"></div>
|
||||
</div>
|
||||
|
||||
|
||||
if (Model.IsAdmin)
|
||||
{
|
||||
<div id="publicProductBidBoxAdmin" class="p-3 bg-secondary text-white">
|
||||
<h4>Manage auction!</h4>
|
||||
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
|
||||
|
||||
|
||||
<div>
|
||||
<button id="signalROpenItemButton" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled hidden")>
|
||||
Open item
|
||||
</button>
|
||||
<button id="signalRPauseItemButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.Active || Model.AuctionStatus == AuctionStatus.FirstWarning || Model.AuctionStatus == AuctionStatus.SecondWarning ? string.Empty : "disabled hidden")>
|
||||
Pause auction
|
||||
</button>
|
||||
<button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Revert bid
|
||||
</button>
|
||||
<button id="signalRResetItemButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Reset auction
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled hidden" : string.Empty)>
|
||||
First warning
|
||||
</button>
|
||||
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled hidden" : string.Empty)>
|
||||
Second warning
|
||||
</button>
|
||||
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled hidden" : string.Empty)>
|
||||
Finished
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>No access to admin level buttons</p>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
<div id="publicProductBidBoxGuest" class="p-3 bg-primary text-white">
|
||||
<h4>This item is under auction!</h4>
|
||||
<div id="bidBoxGuestMessage" class="d-flex justify-content-between mb-3">
|
||||
|
||||
<p>Please log in or register to participate!</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<script>
|
||||
var bidBoxPageViewModel;
|
||||
|
||||
$(window).load(function () {
|
||||
try {
|
||||
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e); // Logs the error
|
||||
}
|
||||
console.log("bidBoxPageViewModel " + bidBoxPageViewModel);
|
||||
console.log(bidBoxPageViewModel.WidgetZone);
|
||||
console.log(typeof sendMessageToServer);
|
||||
|
||||
$("#signalRBidButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRBidButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
if (!bidBoxPageViewModel) {
|
||||
console.log("we need viewmodel data");
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
|
||||
var bidMessage = {
|
||||
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionId: bidBoxPageViewModel.AuctionId,
|
||||
BidPrice: bidBoxPageViewModel.NextBidPrice,
|
||||
ProductId: bidBoxPageViewModel.ProductId,
|
||||
CustomerId: bidBoxPageViewModel.CustomerId
|
||||
};
|
||||
if (!Model.IsGuest)
|
||||
{
|
||||
if (Model.FirstProductToAuction != null)
|
||||
{
|
||||
var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
|
||||
var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin);
|
||||
var title = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "Your bid is leading" : "Place a bid!";
|
||||
|
||||
<div class="d-flex justify-content-between" id="otherAuctionItems">
|
||||
<a href="@(string.IsNullOrEmpty(Model.LastProductUrl) ? "#" : Model.LastProductUrl)" @(string.IsNullOrEmpty(Model.LastProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.LastProductImageUrl) ? "https://placehold.co/400" : Model.LastProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.LastProductUrl) ? "Start of list" : "Back to last")</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<a href="@(string.IsNullOrEmpty(Model.NextProductUrl) ? "#" : Model.NextProductUrl)" @(string.IsNullOrEmpty(Model.NextProductUrl) ? "disabled" : string.Empty)>
|
||||
<div class="card mb-3" style="max-width: 540px;">
|
||||
<div class="row g-0">
|
||||
<div class="col-md-4">
|
||||
<img src="@(string.IsNullOrEmpty(Model.NextProductImageUrl) ? "https://placehold.co/400" : Model.NextProductImageUrl)" class="img-fluid rounded-start" alt="...">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">@(string.IsNullOrEmpty(Model.NextProductUrl) ? "End of list" : "Coming up next...")</h5>
|
||||
<p class="card-text">@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
<div id="publicProductBidBox" class="p-3 @bgClass text-white">
|
||||
<h4 id="bidBoxTitle">@title</h4>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<strong>Base Price:</strong>
|
||||
<span class="value">
|
||||
@($"{Model.BasePrice:c}")
|
||||
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<strong>Bid Step:</strong>
|
||||
<span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(!bidButtonActive ? "disabled" : string.Empty)>
|
||||
Bid @($"{Model.NextBidPrice:c}")
|
||||
</button>
|
||||
@* <button id="bidButton" class="btn btn-success">
|
||||
|
||||
Bid @String.Format("{0:c}", Model.NextBidPrice)
|
||||
</button> *@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@* <button id="testButton" class="btn btn-success">
|
||||
TestButton
|
||||
</button> *@
|
||||
|
||||
<div id="bidFeedback" class="mt-3"></div>
|
||||
</div>
|
||||
|
||||
|
||||
if (Model.IsAdmin)
|
||||
{
|
||||
<div id="publicProductBidBoxAdmin" class="p-3 bg-secondary text-white">
|
||||
<h4>Manage auction!</h4>
|
||||
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
|
||||
|
||||
|
||||
<div>
|
||||
<button id="signalROpenItemButton" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled hidden")>
|
||||
Open item
|
||||
</button>
|
||||
<button id="signalRPauseItemButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.Active || Model.AuctionStatus == AuctionStatus.FirstWarning || Model.AuctionStatus == AuctionStatus.SecondWarning ? string.Empty : "disabled hidden")>
|
||||
Pause auction
|
||||
</button>
|
||||
<button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Revert bid
|
||||
</button>
|
||||
<button id="signalRResetItemButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
|
||||
Reset auction
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled hidden" : string.Empty)>
|
||||
First warning
|
||||
</button>
|
||||
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled hidden" : string.Empty)>
|
||||
Second warning
|
||||
</button>
|
||||
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled hidden" : string.Empty)>
|
||||
Finished
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>No access to admin level buttons</p>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div id="publicProductBidBoxGuest" class="p-3 bg-primary text-white">
|
||||
<h4>This item is under auction!</h4>
|
||||
<div id="bidBoxGuestMessage" class="d-flex justify-content-between mb-3">
|
||||
|
||||
<p>Please log in or register to participate!</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<script>
|
||||
var bidBoxPageViewModel;
|
||||
|
||||
$(window).load(function () {
|
||||
try {
|
||||
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e); // Logs the error
|
||||
}
|
||||
console.log("bidBoxPageViewModel " + bidBoxPageViewModel);
|
||||
console.log(bidBoxPageViewModel.WidgetZone);
|
||||
console.log(typeof sendMessageToServer);
|
||||
|
||||
$("#signalRBidButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRBidButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
if (!bidBoxPageViewModel) {
|
||||
console.log("we need viewmodel data");
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
|
||||
var bidMessage = {
|
||||
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionId: bidBoxPageViewModel.AuctionId,
|
||||
BidPrice: bidBoxPageViewModel.NextBidPrice,
|
||||
ProductId: bidBoxPageViewModel.ProductId,
|
||||
CustomerId: bidBoxPageViewModel.CustomerId
|
||||
};
|
||||
|
||||
var content = JSON.stringify(bidMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#signalROpenItemButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalROpenItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Active);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRCloseItemButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRCloseItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Sold);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRFirstWarningButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRFirstWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.FirstWarning);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRSecondWarningButton").on("click", function () {
|
||||
|
||||
var content = JSON.stringify(bidMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
});
|
||||
document.getElementById("signalRSecondWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
$("#signalROpenItemButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalROpenItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Active);
|
||||
sendAuctionStatusChange(AuctionStatus.SecondWarning);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRCloseItemButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRCloseItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Sold);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRFirstWarningButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRFirstWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
$("#signalRPauseItemButton").on("click", function () {
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.FirstWarning);
|
||||
document.getElementById("signalRPauseItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRSecondWarningButton").on("click", function () {
|
||||
sendAuctionStatusChange(AuctionStatus.Pause);
|
||||
|
||||
document.getElementById("signalRSecondWarningButton").disabled = true;
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
$("#signalRRevertBidButton").on("click", function () {
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.SecondWarning);
|
||||
document.getElementById("signalRRevertBidButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRPauseItemButton").on("click", function () {
|
||||
if (!bidBoxPageViewModel) {
|
||||
console.log("we need viewmodel data");
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
|
||||
document.getElementById("signalRPauseItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
var revertMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
};
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.Pause);
|
||||
var content = JSON.stringify(revertMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRRevertBidButton").on("click", function () {
|
||||
return false;
|
||||
});
|
||||
$("#signalRResetItemButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRResetItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.None);
|
||||
|
||||
document.getElementById("signalRRevertBidButton").disabled = true;
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
//var status = bidBoxPageViewModel.auctionDto.productToAuctionDtos[0].auctionStatus;
|
||||
//setButtons(status);
|
||||
});
|
||||
|
||||
if (!bidBoxPageViewModel) {
|
||||
console.log("we need viewmodel data");
|
||||
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
}
|
||||
function sendAuctionStatusChange(auctionStatus) {
|
||||
|
||||
var revertMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
};
|
||||
// Create the message object
|
||||
var auctionMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionStatus: auctionStatus
|
||||
};
|
||||
|
||||
var content = JSON.stringify(revertMessage);
|
||||
console.log("WTF " + content);
|
||||
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
// Convert to JSON and log
|
||||
var content = JSON.stringify(auctionMessage);
|
||||
console.log(content);
|
||||
|
||||
return false;
|
||||
});
|
||||
$("#signalRResetItemButton").on("click", function () {
|
||||
|
||||
document.getElementById("signalRResetItemButton").disabled = true;
|
||||
event.preventDefault();
|
||||
|
||||
sendAuctionStatusChange(AuctionStatus.None);
|
||||
// Send the message via SignalR
|
||||
sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
|
||||
return false;
|
||||
});
|
||||
//var status = bidBoxPageViewModel.auctionDto.productToAuctionDtos[0].auctionStatus;
|
||||
//setButtons(status);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function sendAuctionStatusChange(auctionStatus) {
|
||||
function SendRevertAuctionBidRequest() {
|
||||
|
||||
// Create the message object
|
||||
var auctionMessage = {
|
||||
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
|
||||
AuctionStatus: auctionStatus
|
||||
};
|
||||
var revertButtonElement = document.getElementById("signalRRevertBidButton");
|
||||
revertButtonElement.disabled = true;
|
||||
sendMessageServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId);
|
||||
}
|
||||
|
||||
// Convert to JSON and log
|
||||
var content = JSON.stringify(auctionMessage);
|
||||
console.log(content);
|
||||
|
||||
// Send the message via SignalR
|
||||
sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
|
||||
function refreshPublicBidBox(data) {
|
||||
|
||||
return false;
|
||||
}
|
||||
//TODO: is it for me?
|
||||
// if () {
|
||||
// data.AuctionDto.
|
||||
// }
|
||||
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
||||
var budButtonElement = document.getElementById("signalRBidButton");
|
||||
var licitStepElement = document.getElementById("licitStepText");
|
||||
var bidBox = document.getElementById("publicProductBidBox");
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle");
|
||||
console.log(data);
|
||||
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
|
||||
var winnerId = data.auctionDto.productToAuctionDtos[0].winnerCustomerId;
|
||||
var isMyBid;
|
||||
|
||||
if (winnerId == bidBoxPageViewModel.CustomerId) {
|
||||
isMyBid = true;
|
||||
|
||||
function SendRevertAuctionBidRequest() {
|
||||
}
|
||||
|
||||
var revertButtonElement = document.getElementById("signalRRevertBidButton");
|
||||
revertButtonElement.disabled = true;
|
||||
sendMessageServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId);
|
||||
}
|
||||
console.log(productAuctionMappingId);
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
||||
//var status = AuctionStatus.TEST;
|
||||
|
||||
//if (status == AuctionStatus.FirstWarning) {
|
||||
setButtons(status);
|
||||
//}
|
||||
|
||||
function refreshPublicBidBox(data) {
|
||||
// if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
// console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
// }
|
||||
|
||||
//TODO: is it for me?
|
||||
// if () {
|
||||
// data.AuctionDto.
|
||||
// }
|
||||
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
||||
var budButtonElement = document.getElementById("signalRBidButton");
|
||||
var licitStepElement = document.getElementById("licitStepText");
|
||||
var bidBox = document.getElementById("publicProductBidBox");
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle");
|
||||
console.log(data);
|
||||
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
|
||||
var winnerId = data.auctionDto.productToAuctionDtos[0].winnerCustomerId;
|
||||
var isMyBid;
|
||||
|
||||
if (winnerId == bidBoxPageViewModel.CustomerId) {
|
||||
isMyBid = true;
|
||||
if (widgetPriceElement) {
|
||||
|
||||
}
|
||||
|
||||
console.log(productAuctionMappingId);
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
||||
//var status = AuctionStatus.TEST;
|
||||
|
||||
//if (status == AuctionStatus.FirstWarning) {
|
||||
setButtons(status);
|
||||
//}
|
||||
|
||||
// if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
// console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
// }
|
||||
|
||||
if (widgetPriceElement) {
|
||||
|
||||
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
|
||||
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
|
||||
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
|
||||
bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
|
||||
budButtonElement.disabled = false;
|
||||
if (isMyBid) {
|
||||
console.log("This is my bid");
|
||||
const list = bidBox.classList;
|
||||
list.add("bg-success");
|
||||
list.remove("bg-primary");
|
||||
budButtonElement.textContent = "Good job";
|
||||
bidBoxTitle.textContent = "Your bid is leading!"
|
||||
if (bidBoxPageViewModel.IsAdmin) {
|
||||
console.log("I AM WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
|
||||
budButtonElement.disabled = false;
|
||||
}
|
||||
else {
|
||||
console.log("I AM NOT WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
|
||||
budButtonElement.disabled = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const list = bidBox.classList;
|
||||
list.add("bg-primary");
|
||||
list.remove("bg-success");
|
||||
bidBoxTitle.textContent = "Place a bid!"
|
||||
budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
|
||||
|
||||
}
|
||||
|
||||
console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
|
||||
//budButtonElement.disabled = false;
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
console.log("Not for this product");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
function handleAuctionUpdate(data) {
|
||||
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle");
|
||||
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
var itemStatus = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
||||
//var itemStatus = AuctionStatus.TEST;
|
||||
|
||||
console.log("handle auction update called" + productAuctionMappingId);
|
||||
console.log("auction status:" + itemStatus);
|
||||
if (widgetPriceElement) {
|
||||
|
||||
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
|
||||
if (itemStatus == AuctionStatus.None) {
|
||||
bidBoxTitle.textContent = "The auction has not started yet";
|
||||
}
|
||||
else if (itemStatus == AuctionStatus.Pause) {
|
||||
bidBoxTitle.textContent = "The auction is paused! Please hold on...";
|
||||
}
|
||||
else if (itemStatus == AuctionStatus.FirstWarning) {
|
||||
bidBoxTitle.textContent = "First warning!";
|
||||
}
|
||||
else if (itemStatus == AuctionStatus.SecondWarning) {
|
||||
bidBoxTitle.textContent = "Secnod warning! Hurry up!";
|
||||
}
|
||||
|
||||
setButtons(itemStatus);
|
||||
|
||||
console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
|
||||
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
console.log("Not for this product");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setButtons(auctionStatus) {
|
||||
console.log("SetButtons called: " + auctionStatus);
|
||||
|
||||
// Button IDs and their default states for each AuctionStatus
|
||||
//true = disabled
|
||||
const buttonStates = {
|
||||
[AuctionStatus.None]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Active]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.FirstWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.SecondWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Pause]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
[AuctionStatus.Sold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.NotSold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
[AuctionStatus.TEST]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// Get the states for the given auctionStatus
|
||||
const states = buttonStates[auctionStatus];
|
||||
if (!states) {
|
||||
console.error("Unknown AuctionStatus: ", auctionStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply the states to each button
|
||||
Object.keys(states).forEach((buttonId) => {
|
||||
const button = document.getElementById(buttonId);
|
||||
if (button) {
|
||||
button.disabled = states[buttonId];
|
||||
button.hidden = states[buttonId];
|
||||
} else {
|
||||
console.warn(`Button with ID ${buttonId} not found.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
|
||||
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
|
||||
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
|
||||
bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
|
||||
budButtonElement.disabled = false;
|
||||
if (isMyBid) {
|
||||
console.log("This is my bid");
|
||||
const list = bidBox.classList;
|
||||
list.add("bg-success");
|
||||
list.remove("bg-primary");
|
||||
budButtonElement.textContent = "Good job";
|
||||
bidBoxTitle.textContent = "Your bid is leading!"
|
||||
if (bidBoxPageViewModel.IsAdmin) {
|
||||
console.log("I AM WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
|
||||
budButtonElement.disabled = false;
|
||||
}
|
||||
else {
|
||||
console.log("I AM NOT WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
|
||||
budButtonElement.disabled = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const list = bidBox.classList;
|
||||
list.add("bg-primary");
|
||||
list.remove("bg-success");
|
||||
bidBoxTitle.textContent = "Place a bid!"
|
||||
budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
|
||||
|
||||
}
|
||||
|
||||
console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
|
||||
//budButtonElement.disabled = false;
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
console.log("Not for this product");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
function handleAuctionUpdate(data) {
|
||||
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
|
||||
var bidBoxTitle = document.getElementById("bidBoxTitle");
|
||||
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
|
||||
|
||||
//TODO: TESZT STATUS!!! - JTEST.
|
||||
var itemStatus = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
||||
//var itemStatus = AuctionStatus.TEST;
|
||||
|
||||
console.log("handle auction update called" + productAuctionMappingId);
|
||||
console.log("auction status:" + itemStatus);
|
||||
if (widgetPriceElement) {
|
||||
|
||||
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
|
||||
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
|
||||
|
||||
if (itemStatus == AuctionStatus.None) {
|
||||
bidBoxTitle.textContent = "The auction has not started yet";
|
||||
}
|
||||
else if (itemStatus == AuctionStatus.Pause) {
|
||||
bidBoxTitle.textContent = "The auction is paused! Please hold on...";
|
||||
}
|
||||
else if (itemStatus == AuctionStatus.FirstWarning) {
|
||||
bidBoxTitle.textContent = "First warning!";
|
||||
}
|
||||
else if (itemStatus == AuctionStatus.SecondWarning) {
|
||||
bidBoxTitle.textContent = "Secnod warning! Hurry up!";
|
||||
}
|
||||
|
||||
setButtons(itemStatus);
|
||||
|
||||
console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
|
||||
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
console.log("Not for this product");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setButtons(auctionStatus) {
|
||||
console.log("SetButtons called: " + auctionStatus);
|
||||
|
||||
// Button IDs and their default states for each AuctionStatus
|
||||
//true = disabled
|
||||
const buttonStates = {
|
||||
[AuctionStatus.None]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Active]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.FirstWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.SecondWarning]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.Pause]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
[AuctionStatus.Sold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: true,
|
||||
signalRResetItemButton: true,
|
||||
},
|
||||
[AuctionStatus.NotSold]: {
|
||||
signalRBidButton: true,
|
||||
signalRFirstWarningButton: true,
|
||||
signalRSecondWarningButton: true,
|
||||
signalROpenItemButton: true,
|
||||
signalRCloseItemButton: true,
|
||||
signalRPauseItemButton: true,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
[AuctionStatus.TEST]: {
|
||||
signalRBidButton: false,
|
||||
signalRFirstWarningButton: false,
|
||||
signalRSecondWarningButton: false,
|
||||
signalROpenItemButton: false,
|
||||
signalRCloseItemButton: false,
|
||||
signalRPauseItemButton: false,
|
||||
signalRRevertBidButton: false,
|
||||
signalRResetItemButton: false,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
// Get the states for the given auctionStatus
|
||||
const states = buttonStates[auctionStatus];
|
||||
if (!states) {
|
||||
console.error("Unknown AuctionStatus: ", auctionStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply the states to each button
|
||||
Object.keys(states).forEach((buttonId) => {
|
||||
const button = document.getElementById(buttonId);
|
||||
if (button) {
|
||||
button.disabled = states[buttonId];
|
||||
button.hidden = states[buttonId];
|
||||
} else {
|
||||
console.warn(`Button with ID ${buttonId} not found.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue