Merge branch 'main' of https://git2.aycode.com/Adam/Mango.Nop.Plugins
This commit is contained in:
commit
760e30847c
|
|
@ -98,6 +98,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
@ -112,6 +113,10 @@ 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)
|
||||||
|
|
@ -162,10 +167,7 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
@ -180,10 +182,7 @@ 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 StatusCode(500, "Error assigning product to auction.");
|
return result != null ? Ok("Baaaazdmeeeeeeeeg") : StatusCode(500, "Error assigning product to auction.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
@ -8,6 +9,8 @@ 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; }
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,16 @@
|
||||||
};
|
};
|
||||||
addAntiForgeryToken(postData);
|
addAntiForgeryToken(postData);
|
||||||
|
|
||||||
console.log("postData: " + JSON.stringify(postData));
|
var jsonData = 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: JSON.stringify(postData),
|
data: jsonData,
|
||||||
traditional: true,
|
traditional: true,
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
alert("Product successfully assigned to the auction!");
|
alert("Product successfully assigned to the auction!");
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
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; }
|
||||||
|
|
@ -21,6 +25,8 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,22 @@
|
||||||
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 = 5,
|
Active = 1,
|
||||||
FirstWarning = 10,
|
FirstWarning = 2,
|
||||||
SecondWarning = 15,
|
SecondWarning = 4,
|
||||||
SoldOut = 20,
|
SoldOut = 8,
|
||||||
NotSold = 25
|
NotSold = 16
|
||||||
}
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ 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;
|
||||||
|
|
@ -52,6 +53,7 @@ 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)
|
||||||
|
|
@ -60,66 +62,72 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
}
|
}
|
||||||
//AuctionBidRequest bidRequestMessage = new AuctionBidRequest();
|
//AuctionBidRequest bidRequestMessage = new AuctionBidRequest();
|
||||||
|
|
||||||
if (bidRequestMessage != null)
|
try
|
||||||
{
|
{
|
||||||
await _logger.InformationAsync($"Bid received: - Auction:{bidRequestMessage.AuctionId} Product: {bidRequestMessage.ProductId} - Bid: {bidRequestMessage.BidPrice} - Customer: {bidRequestMessage.CustomerId}");
|
|
||||||
//get product
|
|
||||||
|
|
||||||
var product = await _productService.GetProductByIdAsync(Convert.ToInt32(bidRequestMessage.ProductId));
|
if (bidRequestMessage != null)
|
||||||
|
|
||||||
if (product != null)
|
|
||||||
{
|
{
|
||||||
//validate the bidprice amount
|
await _logger.InformationAsync($"Bid received: - Auction:{bidRequestMessage.AuctionId} Product: {bidRequestMessage.ProductId} - Bid: {bidRequestMessage.BidPrice} - Customer: {bidRequestMessage.CustomerId}");
|
||||||
|
//get product
|
||||||
|
|
||||||
|
var product = await _productService.GetProductByIdAsync(Convert.ToInt32(bidRequestMessage.ProductId));
|
||||||
|
|
||||||
//set new price
|
if (product != null)
|
||||||
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
|
|
||||||
{
|
|
||||||
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,
|
//validate the bidprice amount
|
||||||
BidPrice = bidRequestMessage.BidPrice,
|
|
||||||
NextStepAmount = "50000"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var jsonMessage = JsonConvert.SerializeObject(bid, Formatting.Indented,
|
|
||||||
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }
|
|
||||||
);
|
|
||||||
|
|
||||||
await _hubContext.Clients.All.SendAsync("send", jsonMessage);
|
|
||||||
|
//set new price
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error($"MessageHandling error: {ex.ToString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,15 @@ 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
|
||||||
{
|
{
|
||||||
public class AssignAuctionRequestModel
|
//TODO: Miért string minden property? - J.
|
||||||
|
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; }
|
||||||
|
|
|
||||||
|
|
@ -162,25 +162,43 @@ public class AuctionService : IAuctionService
|
||||||
#region Dtots
|
#region Dtots
|
||||||
public async Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId)
|
public async Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId)
|
||||||
{
|
{
|
||||||
return new AuctionDto(await _ctx.Auctions.GetByIdAsync(auctionId));
|
var auction = 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 auctionModel = new AuctionDto(await _ctx.Auctions.GetByIdAsync(auctionId));
|
var auction = await _ctx.Auctions.GetByIdAsync(auctionId);
|
||||||
auctionModel.ProductToAuctionDtos.AddRange(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId).Select(x => new ProductToAuctionDto(x)).ToListAsync());
|
if (auction == null) return null;
|
||||||
|
|
||||||
return auctionModel;
|
var auctionDto = new AuctionDto(auction);
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
return new ProductToAuctionDto(await _ctx.ProductToAuctions.GetByIdAsync(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId)
|
public async Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId)
|
||||||
{
|
{
|
||||||
return new AuctionBidDto(await _ctx.AuctionBids.GetByIdAsync(auctionBidId));
|
var auctionBid = 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)
|
||||||
|
|
@ -193,42 +211,35 @@ 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<bool> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
|
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
|
||||||
{
|
{
|
||||||
var auction = await _ctx.Auctions.GetByIdAsync(auctionId);
|
var auction = await GetAuctionDtoByIdAsync(auctionId);
|
||||||
if (auction == null)
|
if (auction == null)
|
||||||
return false;
|
return null;
|
||||||
//check if it is added already
|
|
||||||
|
|
||||||
var productToAuction = _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId);
|
var existedProductToAuction = (await GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productId)).FirstOrDefault();
|
||||||
if (productToAuction == null)
|
if (existedProductToAuction != null) return existedProductToAuction;
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
var mapping = new ProductToAuctionMapping
|
try
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
//already added
|
await _ctx.ProductToAuctions.InsertAsync(mapping);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await _logger.InformationAsync(ex.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Dtos
|
#endregion Dtos
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,8 @@ 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);
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue