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() public async Task<IActionResult> AuctionList()
{ {
await _logger.InformationAsync("AnnouncementList called!"); await _logger.InformationAsync("AnnouncementList called!");
var model = new AuctionViewModel(); var model = new AuctionViewModel();
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml", model); return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AuctionList.cshtml", model);
} }
@ -113,10 +112,6 @@ public class AuctionPluginAdminController : BasePluginController
objOfAuctionDomain.EndDateUtc = viewModel.EndDateUtc; objOfAuctionDomain.EndDateUtc = viewModel.EndDateUtc;
objOfAuctionDomain.Closed = viewModel.Closed; objOfAuctionDomain.Closed = viewModel.Closed;
objOfAuctionDomain.Created = DateTime.UtcNow; objOfAuctionDomain.Created = DateTime.UtcNow;
//TODO: ezt kell majd használni! - J.
//var objOfAuctionDomain = viewModel.AuctionDto.CreateMainEntity();
await _auctionService.InsertAuctionAsync(objOfAuctionDomain); await _auctionService.InsertAuctionAsync(objOfAuctionDomain);
//if (viewModel.IsActive == true) //if (viewModel.IsActive == true)
@ -167,7 +162,10 @@ public class AuctionPluginAdminController : BasePluginController
{ {
_logger.Information("AssignProductToAuction has been called"); _logger.Information("AssignProductToAuction has been called");
var result = await _auctionService.GetProductToAuctionsByAuctionIdAsync(1); var result = await _auctionService.GetProductToAuctionsByAuctionIdAsync(1);
return Ok(result.ToJson()); return Ok(result.ToJson());
} }
@ -182,7 +180,10 @@ public class AuctionPluginAdminController : BasePluginController
var result = await _auctionService.AssignProductToAuctionAsync(Convert.ToInt32(model.ProductId), var result = await _auctionService.AssignProductToAuctionAsync(Convert.ToInt32(model.ProductId),
Convert.ToDecimal(model.StartingPrice), Convert.ToDecimal(model.BidPrice), Convert.ToInt32(model.AuctionId)); 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.Models;
using Nop.Web.Framework.Mvc.ModelBinding; using Nop.Web.Framework.Mvc.ModelBinding;
@ -9,8 +8,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models
{ {
public string PageTitle { get; set; } public string PageTitle { get; set; }
public AuctionDto AuctionDto { get; set; }
[NopResourceDisplayName("Name")] [NopResourceDisplayName("Name")]
public string AuctionName { get; set; } public string AuctionName { get; set; }
public AuctionType AuctionType { get; set; } public AuctionType AuctionType { get; set; }

View File

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

View File

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

View File

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

View File

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

View File

@ -1,22 +1,11 @@
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; 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 public enum AuctionStatus : byte
{ {
None = 0, None = 0,
Active = 1, Active = 5,
FirstWarning = 2, FirstWarning = 10,
SecondWarning = 4, SecondWarning = 15,
SoldOut = 8, SoldOut = 20,
NotSold = 16 NotSold = 25
} }

View File

@ -30,7 +30,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
switch (message.MessageType) switch (message.MessageType)
{ {
//nameof(IAuctionHubClient.SendPrice)
case "BidRequestMessage": case "BidRequestMessage":
await HandleBidRequest(message.Data); await HandleBidRequest(message.Data);
break; 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."); await _logger.InformationAsync("Deserialization returned null. Message data might not match the expected structure.");
} }
bidRequestMessage = a; bidRequestMessage = a;
} }
catch (Exception ex) catch (Exception ex)
@ -62,72 +60,66 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
} }
//AuctionBidRequest bidRequestMessage = new AuctionBidRequest(); //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}");
//get product
if (bidRequestMessage != null) var product = await _productService.GetProductByIdAsync(Convert.ToInt32(bidRequestMessage.ProductId));
if (product != null)
{ {
await _logger.InformationAsync($"Bid received: - Auction:{bidRequestMessage.AuctionId} Product: {bidRequestMessage.ProductId} - Bid: {bidRequestMessage.BidPrice} - Customer: {bidRequestMessage.CustomerId}"); //validate the bidprice amount
//get product
var product = await _productService.GetProductByIdAsync(Convert.ToInt32(bidRequestMessage.ProductId));
if (product != null)
{
//validate the bidprice amount
//set new price //set new price
product.Price = Convert.ToDecimal(bidRequestMessage.BidPrice); product.Price = Convert.ToDecimal(bidRequestMessage.BidPrice);
}
List<ProductToAuctionMapping> mapping = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(Convert.ToInt32(bidRequestMessage.AuctionId), Convert.ToInt32(bidRequestMessage.ProductId));
AuctionBid auctionBid = new AuctionBid();
auctionBid.ProductId = Convert.ToInt32(bidRequestMessage.ProductId);
auctionBid.CustomerId = Convert.ToInt32(bidRequestMessage.CustomerId);
auctionBid.BidPrice = Convert.ToDecimal(bidRequestMessage.BidPrice);
auctionBid.ProductAuctionMappingId = mapping.FirstOrDefault().Id;
//save bid
try
{
await _auctionService.InsertBidAsync(auctionBid);
}
catch (Exception e)
{
_logger.Error($"MessageHandling InsertBidAsync error: {e.ToString()}");
}
//update product
await _productService.UpdateProductAsync(product);
// Optionally broadcast to all clients
var bid = new MessageWrapper
{
MessageType = "bidNotification",
Data = new BidNotificationMessage
{
ProductName = bidRequestMessage.ProductId,
BidPrice = bidRequestMessage.BidPrice,
NextStepAmount = "50000"
}
};
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }
);
await _hubContext.Clients.All.SendAsync("send", jsonMessage);
} }
List<ProductToAuctionMapping> mapping = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(Convert.ToInt32(bidRequestMessage.AuctionId), Convert.ToInt32(bidRequestMessage.ProductId));
AuctionBid auctionBid = new AuctionBid();
auctionBid.ProductId = Convert.ToInt32(bidRequestMessage.ProductId);
auctionBid.CustomerId = Convert.ToInt32(bidRequestMessage.CustomerId);
auctionBid.BidPrice = Convert.ToDecimal(bidRequestMessage.BidPrice);
auctionBid.ProductAuctionMappingId = mapping.FirstOrDefault().Id;
//save bid
try
{
var result = _auctionService.InsertBidAsync(auctionBid);
}
catch(Exception ex)
{
_logger.Error($"MessageHandling error: {ex.ToString()}");
}
//update product
await _productService.UpdateProductAsync(product);
// Optionally broadcast to all clients
var bid = new MessageWrapper
{
MessageType = "bidNotification",
Data = new BidNotificationMessage
{
ProductName = bidRequestMessage.ProductId,
BidPrice = bidRequestMessage.BidPrice,
NextStepAmount = "50000"
}
};
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }
);
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.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
namespace Nop.Plugin.Misc.AuctionPlugin.Models namespace Nop.Plugin.Misc.AuctionPlugin.Models
{ {
//TODO: Miért string minden property? - J. public class AssignAuctionRequestModel
public class AssignAuctionRequestModel //: AuctionDto
{ {
//vagy az alábbi - J.
//public AuctionDto AuctionDto { get; set; }
public string ProductId { get; set; } public string ProductId { get; set; }
public string StartingPrice { get; set; } public string StartingPrice { get; set; }

View File

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

View File

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