This commit is contained in:
Adam 2025-10-12 19:21:52 +02:00
commit e9ac19406e
7 changed files with 55 additions and 37 deletions

View File

@ -18,27 +18,6 @@ using Nop.Web.Framework.Mvc.Filters;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
{
public class CustomOrderSignalREndpoint(FruitBankDbContext ctx) : ICustomOrderSignalREndpointServer
{
[SignalR(SignalRTags.GetAllOrderDtos)]
public async Task<List<OrderDto>> GetAllOrderDtos()
{
return await ctx.OrderDtos.GetAllDtos().ToListAsync();
}
[SignalR(SignalRTags.GetOrderDtoById)]
public async Task<OrderDto> GetOrderDtoById(int orderId)
{
return await ctx.OrderDtos.GetDtoByIdAsync(orderId);
}
[SignalR(SignalRTags.GetPendingOrderDtos)]
public async Task<List<OrderDto>> GetPendingOrderDtos()
{
return await ctx.OrderDtos.GetAllByStatusDto(OrderStatus.Pending).ToListAsync();
}
}
[Area(AreaNames.ADMIN)]
[AuthorizeAdmin]
public class CustomOrderController : BaseAdminController, ICustomOrderSignalREndpointServer

View File

@ -0,0 +1,29 @@
using AyCode.Services.SignalRs;
using FruitBank.Common.Dtos;
using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.SignalRs;
using Nop.Core.Domain.Orders;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
public class CustomOrderSignalREndpoint(FruitBankDbContext ctx) : ICustomOrderSignalREndpointServer
{
[SignalR(SignalRTags.GetAllOrderDtos)]
public async Task<List<OrderDto>> GetAllOrderDtos()
{
return await ctx.OrderDtos.GetAllDtos().ToListAsync();
}
[SignalR(SignalRTags.GetOrderDtoById)]
public async Task<OrderDto> GetOrderDtoById(int orderId)
{
return await ctx.OrderDtos.GetDtoByIdAsync(orderId);
}
[SignalR(SignalRTags.GetPendingOrderDtos)]
public async Task<List<OrderDto>> GetPendingOrderDtos()
{
return await ctx.OrderDtos.GetAllByStatusDto(OrderStatus.Pending).ToListAsync();
}
}

View File

@ -1,10 +1,11 @@
using Mango.Nop.Core.Interfaces;
using FruitBank.Common.Dtos;
using Mango.Nop.Core.Interfaces;
using Nop.Core.Domain.Orders;
using Nop.Data;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
public interface IOrderDtoDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<Order>
public interface IOrderDtoDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<OrderDto>
{
public TDbTable OrderDtos { get; set; }
}

View File

@ -12,7 +12,7 @@ using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class OrderDtoDbTable : MgDbTableBase<Order>
public class OrderDtoDbTable : MgDbTableBase<OrderDto>
{
public OrderDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
@ -21,14 +21,18 @@ public class OrderDtoDbTable : MgDbTableBase<Order>
public IQueryable<OrderDto> GetAllDtos()
{
return GetAll().Select(o => new OrderDto(o));
return GetAll()
.LoadWith(o => o.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.ProductDto)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets);
}
public Task<OrderDto> GetDtoByIdAsync(int orderId)
{
return GetAll().Where(x => x.Id == orderId).Select(o => new OrderDto(o)).FirstOrDefaultAsync(null);
return GetAllDtos().Where(x => x.Id == orderId).FirstOrDefaultAsync(null);
}
public IQueryable<OrderDto> GetAllByStatusDto(OrderStatus orderStatus)
=> GetAll().Where(o => o.OrderStatusId == (int)orderStatus).Select(o => new OrderDto(o));
=> GetAllDtos().Where(o => o.OrderStatusId == (int)orderStatus);
}

View File

@ -174,12 +174,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
public async Task<OrderListModelExtended> PrepareOrderListModelExtendedAsync(OrderSearchModel searchModel)
{
var orderListModel = await PrepareOrderListModelAsync(searchModel);
var orderListModelExtended = new OrderListModelExtended();
var extendedRows = new List<OrderModelExtended>(orderListModel.RecordsFiltered);
PropertyHelper.CopyPublicValueTypeProperties(orderListModel, orderListModelExtended);
foreach (var orderModel in orderListModel.Data)
{
var orderModelExtended = new OrderModelExtended();
@ -190,8 +186,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
Console.WriteLine(orderModelExtended.Id);
extendedRows.Add(orderModelExtended);
}
orderListModel.Data = null;
var orderListModelExtended = orderListModel.ToJson().JsonTo<OrderListModelExtended>();
orderListModelExtended.Data = extendedRows;
return orderListModelExtended;
}

View File

@ -77,10 +77,10 @@ public class PluginNopStartup : INopStartup
services.AddScoped<IConsumer<OrderPlacedEvent>, EventConsumer>();
services.AddScoped<IOrderMeasurementService, OrderMeasurementService>();
services.AddScoped<PendingMeasurementCheckoutFilter>();
services.AddScoped<IOrderListModelExtended<OrderModelExtended>, OrderListModelExtended>();
services.AddScoped<OrderModel, OrderModelExtended>();
services.AddScoped<OrderSearchModel, OrderSearchModelExtended>();
//services.AddScoped<OrderListModel, OrderListModelExtended>();
//services.AddScoped<OrderModel, OrderModelExtended>();
//services.AddScoped<OrderSearchModel, OrderSearchModelExtended>();
services.AddScoped<IOrderModelFactory, CustomOrderModelFactory>();
services.AddScoped<IGenericAttributeService, GenericAttributeService>();

View File

@ -1,6 +1,8 @@
using FruitBank.Common;
using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Orders;
using Nop.Data.Mapping;
namespace Nop.Plugin.Misc.FruitBankPlugin.Mapping;
@ -12,7 +14,10 @@ public partial class NameCompatibility : INameCompatibility
/// </summary>
public Dictionary<Type, string> TableNames => new Dictionary<Type, string>
{
//{ typeof(OrderDto), "Order"},
{ typeof(ProductDto), nameof(Product)},
{ typeof(OrderDto), nameof(Order)},
{ typeof(OrderItemDto), nameof(OrderItem)},
{ typeof(Pallet), FruitBankConstClient.PalletDbTableName},
{ typeof(Files), FruitBankConstClient.FilesDbTableName},
{ typeof(Partner), FruitBankConstClient.PartnerDbTableName },