merge
This commit is contained in:
commit
1e1d612b0f
|
|
@ -118,6 +118,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
|
||||||
MessageType = "bidNotification",
|
MessageType = "bidNotification",
|
||||||
Data = new BidNotificationMessage
|
Data = new BidNotificationMessage
|
||||||
{
|
{
|
||||||
|
//AuctionDto = TODO: ??? - J.
|
||||||
ProductName = viewModel.ProductName,
|
ProductName = viewModel.ProductName,
|
||||||
BidPrice = viewModel.BidPrice.ToString(),
|
BidPrice = viewModel.BidPrice.ToString(),
|
||||||
NextStepAmount = viewModel.NextStepAmount.ToString()
|
NextStepAmount = viewModel.NextStepAmount.ToString()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using Nop.Core.Configuration;
|
||||||
using Nop.Core.Events;
|
using Nop.Core.Events;
|
||||||
using Nop.Data;
|
using Nop.Data;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||||
|
|
||||||
|
|
@ -13,13 +14,24 @@ public class ProductToAuctionDbTable: MgDbTableBase<ProductToAuctionMapping>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<ProductToAuctionMapping> GetByAuctionAndProductId(int auctionId, int productId)
|
private static bool HasActiveAuctionStatus(AuctionStatus auctionStatus)
|
||||||
{
|
{
|
||||||
return Table.Where(x => x.AuctionId == auctionId && x.ProductId == productId);
|
return auctionStatus == AuctionStatus.Active;
|
||||||
|
//return auctionStatus.HasFlag(AuctionStatus.Active) || auctionStatus.HasFlag(AuctionStatus.FirstWarning) || auctionStatus.HasFlag(AuctionStatus.SecondWarning);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IQueryable<ProductToAuctionMapping> GetByProductId(int productId)
|
public IQueryable<ProductToAuctionMapping> GetByAuctionAndProductId(int auctionId, int productId, bool activeProductOnly = false)
|
||||||
{
|
{
|
||||||
return Table.Where(x => x.ProductId == productId);
|
return GetProductToAuctionsByAuctionId(auctionId, activeProductOnly).Where(x => x.ProductId == productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<ProductToAuctionMapping> GetByProductId(int productId, bool activeProductOnly = false)
|
||||||
|
{
|
||||||
|
return Table.Where(x => x.ProductId == productId && (!activeProductOnly || x.AuctionStatus == AuctionStatus.Active/*HasActiveAuctionStatus(x.AuctionStatus)*/));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQueryable<ProductToAuctionMapping> GetProductToAuctionsByAuctionId(int auctionId, bool activeProductOnly = false)
|
||||||
|
{
|
||||||
|
return Table.Where(x => x.AuctionId == auctionId && (!activeProductOnly || x.AuctionStatus == AuctionStatus.Active/*HasActiveAuctionStatus(x.AuctionStatus)*/));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
||||||
|
|
||||||
|
public abstract class AuctionNotificationBase
|
||||||
|
{
|
||||||
|
public AuctionDto AuctionDto { get; set; }
|
||||||
|
|
||||||
|
protected AuctionNotificationBase(){}
|
||||||
|
|
||||||
|
protected AuctionNotificationBase(AuctionDto auctionDto)
|
||||||
|
{
|
||||||
|
AuctionDto = auctionDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
||||||
|
|
||||||
|
public class AuctionProductStatusNotification : AuctionNotificationBase
|
||||||
|
{
|
||||||
|
public AuctionProductStatusNotification() { }
|
||||||
|
public AuctionProductStatusNotification(AuctionDto auctionDto):base(auctionDto) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
|
||||||
|
{
|
||||||
|
public class AuctionProductStatusRequest// : AuctionBidDto
|
||||||
|
{
|
||||||
|
public int ProductToAuctionId { get; set; }
|
||||||
|
public AuctionStatus AuctionStatus { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||||
|
|
||||||
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
||||||
|
|
||||||
|
public class AuctionStatusNotification : AuctionNotificationBase
|
||||||
|
{
|
||||||
|
public AuctionStatusNotification() { }
|
||||||
|
public AuctionStatusNotification(AuctionDto auctionDto):base(auctionDto) { }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ 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.Hubs.Messages
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
|
||||||
{
|
{
|
||||||
|
|
@ -11,10 +12,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
|
||||||
/// this message sends update to the clients. so it sends current (the already winner) price,
|
/// this message sends update to the clients. so it sends current (the already winner) price,
|
||||||
/// sends the ACTUAL bidstep, so the new price, and next bid can be calculated on the client side
|
/// sends the ACTUAL bidstep, so the new price, and next bid can be calculated on the client side
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BidNotificationMessage
|
public class BidNotificationMessage : AuctionNotificationBase
|
||||||
{
|
{
|
||||||
public string ProductName { get; set; }
|
public string ProductName { get; set; }
|
||||||
public string BidPrice { get; set; }
|
public string BidPrice { get; set; }
|
||||||
public string NextStepAmount { get; set; }
|
public string NextStepAmount { get; set; }
|
||||||
|
|
||||||
|
public BidNotificationMessage() { }
|
||||||
|
public BidNotificationMessage(AuctionDto auctionDto):base(auctionDto) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
using System;
|
|
||||||
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
|
|
||||||
{
|
|
||||||
public class OpenItemRequest : AuctionBidDto
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -12,8 +12,7 @@ using Newtonsoft.Json.Serialization;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Nop.Core;
|
using Nop.Core;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||||
using MimeKit;
|
using Nop.Services.Customers;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces;
|
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
{
|
{
|
||||||
|
|
@ -49,6 +48,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
//TODO: lock-olni! - J.
|
||||||
switch (message.MessageType)
|
switch (message.MessageType)
|
||||||
{
|
{
|
||||||
case "BidRequestMessage":
|
case "BidRequestMessage":
|
||||||
|
|
@ -56,7 +56,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "OpenItemRequestMessage":
|
case "OpenItemRequestMessage":
|
||||||
await HandleOpenItemMessageRequest(message.SenderId, message.Data.JsonTo<OpenItemRequest>());
|
await HandleProductToAuctionStatusChangedRequest(message.SenderId, message.Data.JsonTo<AuctionProductStatusRequest>());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Add other message types here
|
// Add other message types here
|
||||||
|
|
@ -66,47 +66,53 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleOpenItemMessageRequest(int senderId, OpenItemRequest openItemMessage)
|
private async Task HandleProductToAuctionStatusChangedRequest(int senderId, AuctionProductStatusRequest auctionProductStatusRequest)
|
||||||
{
|
{
|
||||||
if (openItemMessage == null)
|
if (auctionProductStatusRequest == null)
|
||||||
{
|
{
|
||||||
_logger.Error($"SignalRMessageHandler.HandleOpenItemMessageRequest(); openItemRequestMessage == null");
|
_logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); auctionProductStatusRequest == null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _logger.InformationAsync($"SignalRMessageHandler.HandleOpenItemMessageRequest(); Item to open: - ProductToAuctionMappingId: {openItemMessage.ProductAuctionMappingId}");
|
await _logger.InformationAsync($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); ProductToAuctionMappingId: {auctionProductStatusRequest.ProductToAuctionId}; Status: {auctionProductStatusRequest.AuctionStatus}({(int)auctionProductStatusRequest.AuctionStatus})");
|
||||||
|
|
||||||
//get auction
|
//TODO: if IsAdmin.. - J.
|
||||||
var auction = await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(openItemMessage.ProductAuctionMappingId);
|
//TODO: if nincs aktív item.. - J.
|
||||||
//get productToAuction
|
|
||||||
var productToAuction = await _auctionService.GetProductToAuctionDtoByIdAsync(openItemMessage.ProductAuctionMappingId);
|
|
||||||
|
|
||||||
auction.Closed = false;
|
var auction = await _auctionService.GetAuctionDtoByProductToAuctionIdAsync(auctionProductStatusRequest.ProductToAuctionId);
|
||||||
|
if (auction == null || auction.Closed)
|
||||||
await _logger.InformationAsync($"SignalRMessageHandler.HandleOpenItemMessageRequest(); Auction {auction.Id}, ProducToAuction {productToAuction.Id}");
|
|
||||||
//_auctionService.UpdateAuctionAsync(auction);
|
|
||||||
|
|
||||||
var notification = new AuctionUpdateNotificationMessage
|
|
||||||
{
|
{
|
||||||
AuctionId = auction.Id,
|
_logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); auction == null || auction.Closed");
|
||||||
};
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var productToAuction = await _auctionService.GetProductToAuctionMappingByIdAsync(auctionProductStatusRequest.ProductToAuctionId);
|
||||||
|
if (productToAuction == null)
|
||||||
var bid = new MessageWrapper
|
|
||||||
{
|
{
|
||||||
MessageType = "auctionEventNotification",
|
_logger.Error($"SignalRMessageHandler.HandleProductToAuctionStatusChangedRequest(); productToAuction == null");
|
||||||
SenderId = senderId,
|
return;
|
||||||
Data = notification.ToJson()
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
//await _hubContext.Clients.All.SendAsync("send", bid.ToJson());
|
|
||||||
|
|
||||||
|
|
||||||
|
switch (auctionProductStatusRequest.AuctionStatus)
|
||||||
|
{
|
||||||
|
case AuctionStatus.FirstWarning:
|
||||||
|
productToAuction.AuctionStatus = AuctionStatus.Active | AuctionStatus.FirstWarning;
|
||||||
|
break;
|
||||||
|
case AuctionStatus.SecondWarning:
|
||||||
|
productToAuction.AuctionStatus = AuctionStatus.Active | AuctionStatus.SecondWarning;
|
||||||
|
break;
|
||||||
|
case AuctionStatus.None:
|
||||||
|
case AuctionStatus.Active:
|
||||||
|
case AuctionStatus.SoldOut:
|
||||||
|
case AuctionStatus.NotSold:
|
||||||
|
default:
|
||||||
|
auctionProductStatusRequest.AuctionStatus = auctionProductStatusRequest.AuctionStatus;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _auctionService.UpdateProductToAuctionMappingAsync(productToAuction);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -125,11 +131,20 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _logger.InformationAsync($"SignalRMessageHandler.HandleBidRequest(); Bid received: - Auction: {bidRequestMessage.AuctionId} Product: {bidRequestMessage.ProductId} - Bid: {bidRequestMessage.BidPrice} - Customer: {bidRequestMessage.CustomerId}");
|
await _logger.InformationAsync($"SignalRMessageHandler.HandleBidRequest(); Bid received; Auction: {bidRequestMessage.AuctionId}; Product: {bidRequestMessage.ProductId}; Bid: {bidRequestMessage.BidPrice}; Customer: {bidRequestMessage.CustomerId}");
|
||||||
|
|
||||||
if (bidRequestMessage.CustomerId != (await _workContext.GetCurrentCustomerAsync()).Id)
|
//CustomerService a = new CustomerService()a.IsGuestAsync()
|
||||||
|
var customer = await _workContext.GetCurrentCustomerAsync();
|
||||||
|
if (customer == null || bidRequestMessage.CustomerId != customer.Id) //|| !customer.Active) //TODO: ??? - J.
|
||||||
{
|
{
|
||||||
_logger.Error($"SignalRMessageHandler.HandleBidRequest(); bidRequestMessage.CustomerId != (await _workContext.GetCurrentCustomerAsync()).Id");
|
_logger.Error($"SignalRMessageHandler.HandleBidRequest(); customer == null || bidRequestMessage.CustomerId != customer.Id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var auction = await _auctionService.GetAuctionDtoByIdAsync(bidRequestMessage.AuctionId);
|
||||||
|
if (auction.Closed)
|
||||||
|
{
|
||||||
|
_logger.Warning($"SignalRMessageHandler.HandleBidRequest(); auction.Closed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,15 +155,15 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
return; //ha nincs product vagy exception van, akkor ne broadcast-eljük ki az invalid Bid-et! - J.
|
return; //ha nincs product vagy exception van, akkor ne broadcast-eljük ki az invalid Bid-et! - J.
|
||||||
}
|
}
|
||||||
|
|
||||||
var mapping = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(bidRequestMessage.AuctionId, bidRequestMessage.ProductId);
|
var activeProductAuction = (await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(bidRequestMessage.AuctionId, bidRequestMessage.ProductId, true)).FirstOrDefault();
|
||||||
if (mapping == null || mapping.Count == 0)
|
if (activeProductAuction == null) //|| productAuction.WinnerCustomerId == customer.Id)
|
||||||
{
|
{
|
||||||
_logger.Error($"SignalRMessageHandler.HandleBidRequest(); mapping == null || mapping.Count == 0");
|
_logger.Warning($"SignalRMessageHandler.HandleBidRequest(); activeProductAuction == null");
|
||||||
return; //ha nincs ProductToAuction, akkor ne broadcast-eljük ki az invalid Bid-et! - J.
|
return; //TODO: - J.
|
||||||
}
|
}
|
||||||
|
|
||||||
var auctionBid = bidRequestMessage.CreateMainEntity();
|
var auctionBid = bidRequestMessage.CreateMainEntity();
|
||||||
auctionBid.ProductAuctionMappingId = mapping.FirstOrDefault()!.Id;
|
auctionBid.ProductAuctionMappingId = activeProductAuction.Id;
|
||||||
|
|
||||||
//TODO: validate the bidprice amount
|
//TODO: validate the bidprice amount
|
||||||
if (product.Price >= auctionBid.BidPrice)
|
if (product.Price >= auctionBid.BidPrice)
|
||||||
|
|
@ -164,12 +179,16 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
product.Price = bidRequestMessage.BidPrice;
|
product.Price = bidRequestMessage.BidPrice;
|
||||||
await _productService.UpdateProductAsync(product);
|
await _productService.UpdateProductAsync(product);
|
||||||
|
|
||||||
|
activeProductAuction.StartingPrice = product.OldPrice;
|
||||||
|
activeProductAuction.BidPrice = product.Price;
|
||||||
|
await _auctionService.UpdateProductToAuctionMappingAsync(activeProductAuction);
|
||||||
|
|
||||||
// Optionally broadcast to all clients
|
// Optionally broadcast to all clients
|
||||||
var bid = new MessageWrapper
|
var bid = new MessageWrapper
|
||||||
{
|
{
|
||||||
MessageType = "bidNotification",
|
MessageType = "bidNotification",
|
||||||
SenderId = senderId,
|
SenderId = senderId,
|
||||||
Data = new BidNotificationMessage
|
Data = new BidNotificationMessage(await _auctionService.GetAuctionDtoWithProductByIdAsync(auction.Id, activeProductAuction.ProductId, true))
|
||||||
{
|
{
|
||||||
ProductName = auctionBid.ProductId.ToString(),
|
ProductName = auctionBid.ProductId.ToString(),
|
||||||
BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture),
|
BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture),
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||||
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||||
using Nop.Services.Logging;
|
using Nop.Services.Logging;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Services;
|
namespace Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||||
|
|
@ -90,7 +91,7 @@ public class AuctionService : IAuctionService
|
||||||
/// A task that represents the asynchronous operation
|
/// A task that represents the asynchronous operation
|
||||||
/// The task result contains the bids
|
/// The task result contains the bids
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public virtual async Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue)
|
public async Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue)
|
||||||
{
|
{
|
||||||
var rez = new List<AuctionBid>();
|
var rez = new List<AuctionBid>();
|
||||||
//var rez = await _shortTermCacheManager.GetAsync(async () => await _customerBidRepository.GetAllAsync(query =>
|
//var rez = await _shortTermCacheManager.GetAsync(async () => await _customerBidRepository.GetAllAsync(query =>
|
||||||
|
|
@ -105,12 +106,12 @@ public class AuctionService : IAuctionService
|
||||||
return new PagedList<AuctionBid>(rez, pageIndex, pageSize);
|
return new PagedList<AuctionBid>(rez, pageIndex, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task<AuctionBid> GetBidByIdAsync(int bidId)
|
public async Task<AuctionBid> GetBidByIdAsync(int bidId)
|
||||||
{
|
{
|
||||||
return await _ctx.AuctionBids.GetByIdAsync(bidId);
|
return await _ctx.AuctionBids.GetByIdAsync(bidId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task InsertBidAsync(AuctionBid auctionBid)
|
public async Task InsertBidAsync(AuctionBid auctionBid)
|
||||||
{
|
{
|
||||||
if (await ValidateAuctionBid(auctionBid))
|
if (await ValidateAuctionBid(auctionBid))
|
||||||
{
|
{
|
||||||
|
|
@ -119,7 +120,7 @@ public class AuctionService : IAuctionService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task UpdateBidAsync(AuctionBid auctionBid)
|
public async Task UpdateBidAsync(AuctionBid auctionBid)
|
||||||
{
|
{
|
||||||
if (await ValidateAuctionBid(auctionBid))
|
if (await ValidateAuctionBid(auctionBid))
|
||||||
{
|
{
|
||||||
|
|
@ -133,19 +134,25 @@ public class AuctionService : IAuctionService
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pickupPoint">Pickup point</param>
|
/// <param name="pickupPoint">Pickup point</param>
|
||||||
/// <returns>A task that represents the asynchronous operation</returns>
|
/// <returns>A task that represents the asynchronous operation</returns>
|
||||||
public virtual async Task DeleteBidAsync(AuctionBid pickupPoint)
|
public async Task DeleteBidAsync(AuctionBid pickupPoint)
|
||||||
{
|
{
|
||||||
await _ctx.AuctionBids.DeleteAsync(pickupPoint, false);
|
await _ctx.AuctionBids.DeleteAsync(pickupPoint, false);
|
||||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region auctions
|
#region auctions
|
||||||
public virtual async Task InsertAuctionAsync(Auction auction)
|
public async Task InsertAuctionAsync(Auction auction)
|
||||||
{
|
{
|
||||||
await _ctx.Auctions.InsertAsync(auction, false);
|
await _ctx.Auctions.InsertAsync(auction, false);
|
||||||
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task UpdateAuctionAsync(Auction auction)
|
||||||
|
{
|
||||||
|
await _ctx.Auctions.UpdateAsync(auction);
|
||||||
|
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IList<Auction>> GetAllAuctionsAsync()
|
public async Task<IList<Auction>> GetAllAuctionsAsync()
|
||||||
{
|
{
|
||||||
return await _ctx.Auctions.GetAllAuctionsAsync();
|
return await _ctx.Auctions.GetAllAuctionsAsync();
|
||||||
|
|
@ -153,8 +160,7 @@ public class AuctionService : IAuctionService
|
||||||
|
|
||||||
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems = false)
|
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByAuctionIdAsync(int auctionId, bool onlyActiveItems = false)
|
||||||
{
|
{
|
||||||
//return (await _ctx.Auctions.GetAllAsync(auctions => auctions.OrderByDescending(x => x.StartDateUtc), _ => default)).ToList();
|
return await _ctx.ProductToAuctions.GetProductToAuctionsByAuctionId(auctionId, onlyActiveItems).ToListAsync();
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -166,13 +172,13 @@ public class AuctionService : IAuctionService
|
||||||
return auction == null ? null : new AuctionDto(auction);
|
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, bool activeProductOnly = false)
|
||||||
{
|
{
|
||||||
var auction = await _ctx.Auctions.GetByIdAsync(auctionId);
|
var auction = await _ctx.Auctions.GetByIdAsync(auctionId);
|
||||||
if (auction == null) return null;
|
if (auction == null) return null;
|
||||||
|
|
||||||
var auctionDto = new AuctionDto(auction);
|
var auctionDto = new AuctionDto(auction);
|
||||||
auctionDto.ProductToAuctionDtos.AddRange(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId).Select(x => new ProductToAuctionDto(x)).ToListAsync());
|
auctionDto.ProductToAuctionDtos.AddRange((await GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productId, activeProductOnly)).Select(x => new ProductToAuctionDto(x)));
|
||||||
|
|
||||||
return auctionDto;
|
return auctionDto;
|
||||||
}
|
}
|
||||||
|
|
@ -206,9 +212,9 @@ public class AuctionService : IAuctionService
|
||||||
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync());
|
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId)
|
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly = false)
|
||||||
{
|
{
|
||||||
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId).ToListAsync());
|
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
|
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)
|
||||||
|
|
@ -226,7 +232,7 @@ public class AuctionService : IAuctionService
|
||||||
StartingPrice = startingPrice,
|
StartingPrice = startingPrice,
|
||||||
BidPrice = bidPrice,
|
BidPrice = bidPrice,
|
||||||
ProductAmount = 0,
|
ProductAmount = 0,
|
||||||
AuctionStatus = Domains.Enums.AuctionStatus.Active, //Ez miért Active alapból? - J.
|
AuctionStatus = AuctionStatus.Active, //TODO: Ez miért Active alapból? - J.
|
||||||
AuctionId = auctionId
|
AuctionId = auctionId
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -242,5 +248,16 @@ public class AuctionService : IAuctionService
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ProductToAuctionMapping> GetProductToAuctionMappingByIdAsync(int productToAuctionMappingId)
|
||||||
|
{
|
||||||
|
return await _ctx.ProductToAuctions.GetByIdAsync(productToAuctionMappingId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateProductToAuctionMappingAsync(ProductToAuctionMapping productToAuctionMapping)
|
||||||
|
{
|
||||||
|
await _ctx.ProductToAuctions.UpdateAsync(productToAuctionMapping);
|
||||||
|
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Dtos
|
#endregion Dtos
|
||||||
}
|
}
|
||||||
|
|
@ -32,6 +32,7 @@ public interface IAuctionService
|
||||||
Task DeleteBidAsync(AuctionBid pickupPoint);
|
Task DeleteBidAsync(AuctionBid pickupPoint);
|
||||||
|
|
||||||
Task InsertAuctionAsync(Auction auction);
|
Task InsertAuctionAsync(Auction auction);
|
||||||
|
Task UpdateAuctionAsync(Auction auction);
|
||||||
|
|
||||||
Task<IList<Auction>> GetAllAuctionsAsync();
|
Task<IList<Auction>> GetAllAuctionsAsync();
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ public interface IAuctionService
|
||||||
Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId);
|
Task<AuctionDto> GetAuctionDtoByIdAsync(int auctionId);
|
||||||
|
|
||||||
|
|
||||||
Task<AuctionDto> GetAuctionDtoWithProductByIdAsync(int auctionId, int productId);
|
Task<AuctionDto> GetAuctionDtoWithProductByIdAsync(int auctionId, int productId, bool activeProductOnly);
|
||||||
|
|
||||||
Task<ProductToAuctionDto> GetProductToAuctionDtoByIdAsync(int productToAuctionId);
|
Task<ProductToAuctionDto> GetProductToAuctionDtoByIdAsync(int productToAuctionId);
|
||||||
|
|
||||||
|
|
@ -49,5 +50,7 @@ public interface IAuctionService
|
||||||
Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
|
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, bool activeProductOnly);
|
||||||
|
Task<ProductToAuctionMapping> GetProductToAuctionMappingByIdAsync(int productToAuctionMappingId);
|
||||||
|
Task UpdateProductToAuctionMappingAsync(ProductToAuctionMapping productToAuctionMapping);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue