72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using AyCode.Core.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Nop.Data;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Models;
|
|
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
|
using Nop.Services.Catalog;
|
|
using Nop.Services.Logging;
|
|
using Nop.Web.Areas.Admin.Factories;
|
|
using Nop.Web.Framework.Controllers;
|
|
using Nop.Web.Models.Catalog;
|
|
|
|
namespace Nop.Plugin.Misc.AuctionPlugin.Controllers;
|
|
|
|
public class AuctionController : BasePluginController
|
|
{
|
|
|
|
protected readonly AuctionService _auctionService;
|
|
protected readonly ILogger _logger;
|
|
protected readonly IProductService _productService;
|
|
protected readonly MyProductModelFactory _productModelFactory;
|
|
|
|
public AuctionController(AuctionService auctionService, ILogger logger, IProductService productService, MyProductModelFactory productModelFactory)
|
|
{
|
|
_auctionService = auctionService;
|
|
_logger = logger;
|
|
_productService = productService;
|
|
_productModelFactory = productModelFactory;
|
|
}
|
|
|
|
// GET
|
|
public IActionResult Index()
|
|
{
|
|
//var a = new Auction();
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> PlaceBid([FromBody] AuctionBid model)
|
|
{
|
|
|
|
await _logger.InformationAsync("PlaceBid called");
|
|
|
|
//if (model.BidPrice < CurrentPrice + LicitStep)
|
|
//{
|
|
// return BadRequest("Bid price is too low.");
|
|
//}
|
|
|
|
// kéne valami visszajelzés
|
|
await _auctionService.InsertBidAsync(model);
|
|
bool bidSuccess = true;
|
|
if (bidSuccess)
|
|
{
|
|
return Ok(new { message = "Your bid was successfully placed!" });
|
|
}
|
|
else
|
|
{
|
|
return BadRequest("Failed to place bid. Please try again.");
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> RefreshAuctionWidget([FromBody] RefreshWidgetRequest request)
|
|
{
|
|
await _logger.InformationAsync($"Refresh auction widget called from {request.WidgetZone} with data of {request.ProductId}");
|
|
|
|
var product = await _productService.GetProductByIdAsync(request.ProductId);
|
|
ProductDetailsModel detailsModel = await _productModelFactory.PrepareProductDetailsModelAsync(product);
|
|
|
|
return ViewComponent("AuctionPublic", new { widgetZone = request.WidgetZone, additionalData = detailsModel });
|
|
}
|
|
} |