Compare commits

..

No commits in common. "992e4a6c40a04654cb94edf31395f1e70f123d59" and "169a4540c7d531b622a88782028e7d108706ebc7" have entirely different histories.

11 changed files with 104 additions and 151 deletions

View File

@ -98,7 +98,6 @@ public class AuctionPluginAdminController : BasePluginController
public async Task<IActionResult> AuctionList()
{
await _logger.InformationAsync("AnnouncementList called!");
var model = new AuctionViewModel();
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml", model);
}
@ -113,10 +112,6 @@ public class AuctionPluginAdminController : BasePluginController
objOfAuctionDomain.EndDateUtc = viewModel.EndDateUtc;
objOfAuctionDomain.Closed = viewModel.Closed;
objOfAuctionDomain.Created = DateTime.UtcNow;
//TODO: ezt kell majd használni! - J.
//var objOfAuctionDomain = viewModel.AuctionDto.CreateMainEntity();
await _auctionService.InsertAuctionAsync(objOfAuctionDomain);
//if (viewModel.IsActive == true)
@ -167,8 +162,11 @@ public class AuctionPluginAdminController : BasePluginController
{
_logger.Information("AssignProductToAuction has been called");
var result = await _auctionService.GetProductToAuctionsByAuctionIdAsync(1);
return Ok(result.ToJson());
}
@ -182,7 +180,10 @@ public class AuctionPluginAdminController : BasePluginController
var result = await _auctionService.AssignProductToAuctionAsync(Convert.ToInt32(model.ProductId),
Convert.ToDecimal(model.StartingPrice), Convert.ToDecimal(model.BidPrice), Convert.ToInt32(model.AuctionId));
if (result)
return Ok("Baaaazdmeeeeeeeeg");
return result != null ? Ok("Baaaazdmeeeeeeeeg") : StatusCode(500, "Error assigning product to auction.");
return StatusCode(500, "Error assigning product to auction.");
}
}

View File

@ -1,5 +1,4 @@
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Web.Framework.Models;
using Nop.Web.Framework.Mvc.ModelBinding;
@ -9,8 +8,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models
{
public string PageTitle { get; set; }
public AuctionDto AuctionDto { get; set; }
[NopResourceDisplayName("Name")]
public string AuctionName { get; set; }
public AuctionType AuctionType { get; set; }

View File

@ -50,16 +50,14 @@
};
addAntiForgeryToken(postData);
var jsonData = JSON.stringify(postData);
console.log("postData: " + jsonData);
debugger;
console.log("postData: " + JSON.stringify(postData));
// Perform AJAX call
$.ajax({
url: "/Admin/AuctionPluginAdmin/AssignProductToAuction", // Update to match your endpoint
type: "POST",
contentType: "application/json",
data: jsonData,
data: JSON.stringify(postData),
traditional: true,
success: function (response) {
alert("Product successfully assigned to the auction!");

View File

@ -19,8 +19,6 @@ public class AuctionBidDto : IAuctionBidDto
public AuctionBidDto(AuctionBid auctionBid)
{
if (auctionBid == null) return;
Id = auctionBid.Id;
ProductAuctionMappingId = auctionBid.ProductAuctionMappingId;
CustomerId = auctionBid.CustomerId;

View File

@ -1,17 +1,13 @@
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos.Interfaces;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Web.Framework.Mvc.ModelBinding;
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
public class AuctionDto : IAuctionDto
{
public int Id { get; set; }
[NopResourceDisplayName("Name")]
public string AuctionName { get; set; }
public AuctionType AuctionType { get; set; }
public DateTime StartDateUtc { get; set; }
public DateTime? EndDateUtc { get; set; }
@ -25,8 +21,6 @@ public class AuctionDto : IAuctionDto
public AuctionDto(Auction auction)
{
if (auction == null) return;
Id = auction.Id;
AuctionName = auction.AuctionName;
AuctionType = auction.AuctionType;

View File

@ -24,8 +24,6 @@ public class ProductToAuctionDto : IProductToAuctionDto
public ProductToAuctionDto(ProductToAuctionMapping productToAuction)
{
if (productToAuction == null) return;
Id = productToAuction.Id;
ProductId = productToAuction.ProductId;
AuctionId = productToAuction.AuctionId;

View File

@ -1,22 +1,11 @@
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
//public enum AuctionStatus : byte
//{
// None = 0,
// Active = 5,
// FirstWarning = 10,
// SecondWarning = 15,
// SoldOut = 20,
// NotSold = 25
//}
[Flags]
public enum AuctionStatus : byte
{
None = 0,
Active = 1,
FirstWarning = 2,
SecondWarning = 4,
SoldOut = 8,
NotSold = 16
Active = 5,
FirstWarning = 10,
SecondWarning = 15,
SoldOut = 20,
NotSold = 25
}

View File

@ -30,7 +30,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
switch (message.MessageType)
{
//nameof(IAuctionHubClient.SendPrice)
case "BidRequestMessage":
await HandleBidRequest(message.Data);
break;
@ -53,7 +52,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
await _logger.InformationAsync("Deserialization returned null. Message data might not match the expected structure.");
}
bidRequestMessage = a;
}
catch (Exception ex)
@ -62,9 +60,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
}
//AuctionBidRequest bidRequestMessage = new AuctionBidRequest();
try
{
if (bidRequestMessage != null)
{
await _logger.InformationAsync($"Bid received: - Auction:{bidRequestMessage.AuctionId} Product: {bidRequestMessage.ProductId} - Bid: {bidRequestMessage.BidPrice} - Customer: {bidRequestMessage.CustomerId}");
@ -95,11 +90,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
//save bid
try
{
await _auctionService.InsertBidAsync(auctionBid);
var result = _auctionService.InsertBidAsync(auctionBid);
}
catch (Exception e)
catch(Exception ex)
{
_logger.Error($"MessageHandling InsertBidAsync error: {e.ToString()}");
_logger.Error($"MessageHandling error: {ex.ToString()}");
}
//update product
@ -123,11 +119,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
await _hubContext.Clients.All.SendAsync("send", jsonMessage);
}
}
catch (Exception ex)
{
_logger.Error($"MessageHandling error: {ex.ToString()}");
}
}
}
}

View File

@ -3,15 +3,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
namespace Nop.Plugin.Misc.AuctionPlugin.Models
{
//TODO: Miért string minden property? - J.
public class AssignAuctionRequestModel //: AuctionDto
public class AssignAuctionRequestModel
{
//vagy az alábbi - J.
//public AuctionDto AuctionDto { get; set; }
public string ProductId { get; set; }
public string StartingPrice { get; set; }

View File

@ -162,43 +162,25 @@ public class AuctionService : IAuctionService
#region Dtots
public async Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId)
{
var auction = await _ctx.Auctions.GetByIdAsync(auctionId);
return auction == null ? null : new AuctionDto(auction);
return new AuctionDto(await _ctx.Auctions.GetByIdAsync(auctionId));
}
public async Task<AuctionDto> GetAuctionDtoWithProductByIdAsync(int auctionId, int productId)
{
var auction = await _ctx.Auctions.GetByIdAsync(auctionId);
if (auction == null) return null;
var auctionModel = new AuctionDto(await _ctx.Auctions.GetByIdAsync(auctionId));
auctionModel.ProductToAuctionDtos.AddRange(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId).Select(x => new ProductToAuctionDto(x)).ToListAsync());
var auctionDto = new AuctionDto(auction);
auctionDto.ProductToAuctionDtos.AddRange(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId).Select(x => new ProductToAuctionDto(x)).ToListAsync());
return auctionDto;
return auctionModel;
}
public async Task<ProductToAuctionDto> GetProductToAuctionDtoByIdAsync(int productToAuctionId)
{
var productToAuction = await _ctx.ProductToAuctions.GetByIdAsync(productToAuctionId);
return productToAuction == null ? null : new ProductToAuctionDto(productToAuction);
}
public async Task<AuctionDto> GetAuctionDtoByProductToAuctionIdAsync(int productToAuctionId, bool includeProductToAuctionDto = true)
{
var productTouctionDto = await GetProductToAuctionDtoByIdAsync(productToAuctionId);
if (productTouctionDto == null) return null;
var auctionDto = await GetAuctionDtoByIdAsync(productTouctionDto.AuctionId); //Ez sosem lehet null! - J.
if (includeProductToAuctionDto) auctionDto.ProductToAuctionDtos.Add(productTouctionDto);
return auctionDto;
return new ProductToAuctionDto(await _ctx.ProductToAuctions.GetByIdAsync(productToAuctionId));
}
public async Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId)
{
var auctionBid = await _ctx.AuctionBids.GetByIdAsync(auctionBidId);
return auctionBid == null ? null : new AuctionBidDto(auctionBid);
return new AuctionBidDto(await _ctx.AuctionBids.GetByIdAsync(auctionBidId));
}
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
@ -211,14 +193,16 @@ public class AuctionService : IAuctionService
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId).ToListAsync());
}
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
public async Task<bool> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
{
var auction = await GetAuctionDtoByIdAsync(auctionId);
var auction = await _ctx.Auctions.GetByIdAsync(auctionId);
if (auction == null)
return null;
return false;
//check if it is added already
var existedProductToAuction = (await GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productId)).FirstOrDefault();
if (existedProductToAuction != null) return existedProductToAuction;
var productToAuction = _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId);
if (productToAuction == null)
{
var mapping = new ProductToAuctionMapping
{
@ -226,10 +210,9 @@ public class AuctionService : IAuctionService
StartingPrice = startingPrice,
BidPrice = bidPrice,
ProductAmount = 0,
AuctionStatus = Domains.Enums.AuctionStatus.Active, //Ez miért Active alapból? - J.
AuctionStatus = Domains.Enums.AuctionStatus.Active,
AuctionId = auctionId
};
try
{
await _ctx.ProductToAuctions.InsertAsync(mapping);
@ -239,7 +222,13 @@ public class AuctionService : IAuctionService
await _logger.InformationAsync(ex.ToString());
}
return mapping;
return true;
}
else
{
//already added
return false;
}
}
#endregion Dtos

View File

@ -46,8 +46,9 @@ public interface IAuctionService
Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId);
Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId);
Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId);
Task<bool> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
}