improvements

This commit is contained in:
Loretta 2024-11-19 10:06:16 +01:00
parent 1c1bb07fa6
commit 90ad8c1085
10 changed files with 86 additions and 35 deletions

View File

@ -98,6 +98,7 @@ 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);
}
@ -112,6 +113,10 @@ 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)
@ -162,10 +167,7 @@ public class AuctionPluginAdminController : BasePluginController
{
_logger.Information("AssignProductToAuction has been called");
var result = await _auctionService.GetProductToAuctionsByAuctionIdAsync(1);
return Ok(result.ToJson());
}
@ -180,10 +182,7 @@ 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 StatusCode(500, "Error assigning product to auction.");
return result != null ? Ok("Baaaazdmeeeeeeeeg") : StatusCode(500, "Error assigning product to auction.");
}
}

View File

@ -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.Mvc.ModelBinding;
@ -8,6 +9,8 @@ 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

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

View File

@ -1,13 +1,17 @@
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; }
@ -21,6 +25,8 @@ public class AuctionDto : IAuctionDto
public AuctionDto(Auction auction)
{
if (auction == null) return;
Id = auction.Id;
AuctionName = auction.AuctionName;
AuctionType = auction.AuctionType;

View File

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

View File

@ -1,11 +1,22 @@
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 = 5,
FirstWarning = 10,
SecondWarning = 15,
SoldOut = 20,
NotSold = 25
Active = 1,
FirstWarning = 2,
SecondWarning = 4,
SoldOut = 8,
NotSold = 16
}

View File

@ -2,24 +2,29 @@
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities.Interfaces;
using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
public class AuctionHub : Hub<IAuctionHubClient>
{
ILogger _logger;
{
private readonly ILogger _logger;
private IAuctionService _auctionService;
//HubCallerContext _hubCallerContext;
public AuctionHub(ILogger logger)
public AuctionHub(IAuctionService auctionService, ILogger logger)
{
_logger = logger;
_logger = logger;
_auctionService = auctionService;
}
public override async Task OnConnectedAsync()
public override async Task OnConnectedAsync()
{
//await _logger.InformationAsync($"Caller connected: id{_hubCallerContext.ConnectionId}");
var userId = Context.ConnectionId;
await _logger.InformationAsync($"Caller connected with id: {userId}");
@ -28,6 +33,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
await _logger.InformationAsync($"Caller connected with name: {userName}");
}
await base.OnConnectedAsync();
}
@ -49,8 +55,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
public async Task SendPriceToUsers(string message)
{
await Clients.All.SendAsync("SendPrice", message);
await Clients.All.SendPrice(message); //SendAsync(nameof(IAuctionHubClient.SendPrice), message);
}
}
}
}

View File

@ -3,11 +3,15 @@ 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 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 StartingPrice { get; set; }

View File

@ -162,32 +162,50 @@ public class AuctionService : IAuctionService
#region Dtots
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)
{
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 auction = await _ctx.Auctions.GetByIdAsync(auctionId);
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)
{
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)
{
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<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)
return false;
return null;
var mapping = new ProductToAuctionMapping
{
@ -195,9 +213,10 @@ public class AuctionService : IAuctionService
StartingPrice = startingPrice,
BidPrice = bidPrice,
ProductAmount = 0,
AuctionStatus = Domains.Enums.AuctionStatus.Active,
AuctionStatus = Domains.Enums.AuctionStatus.Active, //Ez miért Active alapból? - J.
AuctionId = auctionId
};
try
{
await _ctx.ProductToAuctions.InsertAsync(mapping);
@ -207,7 +226,7 @@ public class AuctionService : IAuctionService
await _logger.InformationAsync(ex.ToString());
}
return true;
return mapping;
}
#endregion Dtos

View File

@ -43,5 +43,5 @@ public interface IAuctionService
Task<AuctionBidDto> GetAuctionBidDtoByIdAsync(int auctionBidId);
Task<bool> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId);
}