improvements, fixes, etc...

This commit is contained in:
Loretta 2025-10-12 07:47:55 +02:00
parent ca1f59a5e1
commit 8da9c65328
8 changed files with 89 additions and 34 deletions

View File

@ -1,8 +1,11 @@
using AyCode.Services.SignalRs; using AyCode.Services.SignalRs;
using FruitBank.Common.Dtos;
using FruitBank.Common.Interfaces; using FruitBank.Common.Interfaces;
using FruitBank.Common.Server.Interfaces; using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.SignalRs; using FruitBank.Common.SignalRs;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Nop.Core.Domain.Orders;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.FruitBankPlugin.Factories; using Nop.Plugin.Misc.FruitBankPlugin.Factories;
using Nop.Plugin.Misc.FruitBankPlugin.Models; using Nop.Plugin.Misc.FruitBankPlugin.Models;
using Nop.Services.Orders; using Nop.Services.Orders;
@ -15,33 +18,24 @@ using Nop.Web.Framework.Mvc.Filters;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
{ {
public class CustomOrderSignalREndpoint(IOrderService orderService, IOrderModelFactory orderModelFactory) : ICustomOrderSignalREndpointServer public class CustomOrderSignalREndpoint(FruitBankDbContext ctx) : ICustomOrderSignalREndpointServer
{ {
private readonly IOrderService _orderService = orderService; [SignalR(SignalRTags.GetAllOrderDtos)]
private readonly CustomOrderModelFactory _orderModelFactory = orderModelFactory as CustomOrderModelFactory; public async Task<List<OrderDto>> GetAllOrderDtos()
public async Task<OrderListModelExtended> GetOrderModelsByFilter(OrderSearchModel searchModel)
{ {
var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel); return await ctx.OrderDtos.GetAllDtos().ToListAsync();
Console.WriteLine($"Total: {orderListModel.RecordsTotal}, Data Count: {orderListModel.Data.Count()}");
foreach (var item in orderListModel.Data.Take(3))
{
Console.WriteLine($"Order: {item.Id}, {item.CustomOrderNumber}");
}
return orderListModel;
} }
[SignalR(SignalRTags.GetPendingOrderModels)] [SignalR(SignalRTags.GetOrderDtoById)]
public async Task<OrderListModelExtended> GetPendingOrderModels() public async Task<OrderDto> GetOrderDtoById(int orderId)
{ {
var orderSearchModel = new OrderSearchModel return await ctx.OrderDtos.GetDtoByIdAsync(orderId);
{ }
OrderStatusIds = new List<int> { 1 }
};
return await GetOrderModelsByFilter(orderSearchModel); [SignalR(SignalRTags.GetPendingOrderDtos)]
public async Task<List<OrderDto>> GetPendingOrderDtos()
{
return await ctx.OrderDtos.GetAllByStatusDto(OrderStatus.Pending).ToListAsync();
} }
} }
@ -64,6 +58,15 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
// ... initialize other deps // ... initialize other deps
} }
#region CustomOrderSignalREndpoint
public Task<List<OrderDto>> GetAllOrderDtos()
=> _customOrderSignalREndpoint.GetAllOrderDtos();
public Task<OrderDto> GetOrderDtoById(int orderId)
=> _customOrderSignalREndpoint.GetOrderDtoById(orderId);
public Task<List<OrderDto>> GetPendingOrderDtos()
=> _customOrderSignalREndpoint.GetPendingOrderDtos();
#endregion CustomOrderSignalREndpoint
[CheckPermission(StandardPermission.Orders.ORDERS_VIEW)] [CheckPermission(StandardPermission.Orders.ORDERS_VIEW)]
public virtual async Task<IActionResult> List(List<int> orderStatuses = null, List<int> paymentStatuses = null, List<int> shippingStatuses = null) public virtual async Task<IActionResult> List(List<int> orderStatuses = null, List<int> paymentStatuses = null, List<int> shippingStatuses = null)
{ {
@ -83,14 +86,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
public async Task<IActionResult> OrderList(OrderSearchModel searchModel) public async Task<IActionResult> OrderList(OrderSearchModel searchModel)
{ {
//prepare model //prepare model
var orderListModel = await GetOrderModelsByFilter(searchModel); var orderListModel = await GetOrderListModelByFilter(searchModel);
var valami = Json(orderListModel); var valami = Json(orderListModel);
Console.WriteLine(valami); Console.WriteLine(valami);
return valami; return valami;
} }
public async Task<OrderListModelExtended> GetOrderModelsByFilter(OrderSearchModel searchModel) public async Task<OrderListModelExtended> GetOrderListModelByFilter(OrderSearchModel searchModel)
{ {
//return _customOrderService. //return _customOrderService.
var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel); var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel);
@ -104,15 +107,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
return orderListModel; return orderListModel;
} }
[SignalR(SignalRTags.GetPendingOrderModels)] public async Task<OrderListModelExtended> GetPendingOrderListModel()
public async Task<OrderListModelExtended> GetPendingOrderModels()
{ {
var orderSearchModel = new OrderSearchModel var orderSearchModel = new OrderSearchModel
{ {
OrderStatusIds = new List<int> { 1 } OrderStatusIds = new List<int> { (int)OrderStatus.Pending }
}; };
return await GetOrderModelsByFilter(orderSearchModel); return await GetOrderListModelByFilter(orderSearchModel);
} }
public virtual IActionResult Test() public virtual IActionResult Test()

View File

@ -23,10 +23,12 @@ using System.Transactions;
using FruitBank.Common.Dtos; using FruitBank.Common.Dtos;
using Mango.Nop.Core.Dtos; using Mango.Nop.Core.Dtos;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using Nop.Core.Domain.Orders;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class FruitBankDbContext : MgDbContextBase, public class FruitBankDbContext : MgDbContextBase,
IOrderDtoDbSet<OrderDtoDbTable>,
IPartnerDbSet<PartnerDbTable>, IPartnerDbSet<PartnerDbTable>,
IShippingDbSet<ShippingDbTable>, IShippingDbSet<ShippingDbTable>,
IShippingDocumentDbSet<ShippingDocumentDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>,
@ -41,6 +43,8 @@ public class FruitBankDbContext : MgDbContextBase,
private readonly IProductService _productService; private readonly IProductService _productService;
private readonly IStaticCacheManager _staticCacheManager; private readonly IStaticCacheManager _staticCacheManager;
public OrderDtoDbTable OrderDtos { get; set; }
public PartnerDbTable Partners { get; set; } public PartnerDbTable Partners { get; set; }
public ShippingDbTable Shippings { get; set; } public ShippingDbTable Shippings { get; set; }
public ShippingDocumentDbTable ShippingDocuments { get; set; } public ShippingDocumentDbTable ShippingDocuments { get; set; }
@ -60,6 +64,7 @@ public class FruitBankDbContext : MgDbContextBase,
public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
OrderDtoDbTable orderDtoDbTable,
IProductService productService, IStaticCacheManager staticCacheManager, IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Product> productRepository, IRepository<Product> productRepository,
IRepository<Customer> customerRepository, IRepository<Customer> customerRepository,
@ -73,6 +78,7 @@ public class FruitBankDbContext : MgDbContextBase,
_fruitBankAttributeService = fruitBankAttributeService; _fruitBankAttributeService = fruitBankAttributeService;
Files = filesDbTable; Files = filesDbTable;
OrderDtos = orderDtoDbTable;
Partners = partnerDbTable; Partners = partnerDbTable;
Shippings = shippingDbTable; Shippings = shippingDbTable;
ShippingDocuments = shippingDocumentDbTable; ShippingDocuments = shippingDocumentDbTable;

View File

@ -0,0 +1,10 @@
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 TDbTable OrderDtos { get; set; }
}

View File

@ -0,0 +1,34 @@
using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
using LinqToDB;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Domain.Orders;
using Nop.Core.Events;
using Nop.Data;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class OrderDtoDbTable : MgDbTableBase<Order>
{
public OrderDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
public IQueryable<OrderDto> GetAllDtos()
{
return GetAll().Select(o => new OrderDto(o));
}
public Task<OrderDto> GetDtoByIdAsync(int orderId)
{
return GetAll().Where(x => x.Id == orderId).Select(o => new OrderDto(o)).FirstOrDefaultAsync(null);
}
public IQueryable<OrderDto> GetAllByStatusDto(OrderStatus orderStatus)
=> GetAll().Where(o => o.OrderStatusId == (int)orderStatus).Select(o => new OrderDto(o));
}

View File

@ -6,7 +6,6 @@ using Nop.Core.Configuration;
using Nop.Core.Events; using Nop.Core.Events;
using Nop.Data; using Nop.Data;
using Nop.Services.Logging; using Nop.Services.Logging;
using static LinqToDB.Reflection.Methods.LinqToDB.Insert;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;

View File

@ -32,7 +32,9 @@ using Nop.Services.Tax;
using Nop.Services.Vendors; using Nop.Services.Vendors;
using Nop.Web.Areas.Admin.Factories; using Nop.Web.Areas.Admin.Factories;
using Nop.Web.Areas.Admin.Models.Orders; using Nop.Web.Areas.Admin.Models.Orders;
using System.Collections;
using System.Reflection; using System.Reflection;
using System.Runtime.Intrinsics.Arm;
namespace Nop.Plugin.Misc.FruitBankPlugin.Factories namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
{ {
@ -176,13 +178,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
var orderListModelExtended = new OrderListModelExtended(); var orderListModelExtended = new OrderListModelExtended();
var extendedRows = new List<OrderModelExtended>(orderListModel.RecordsFiltered); var extendedRows = new List<OrderModelExtended>(orderListModel.RecordsFiltered);
//TODO: Megnézni miért száll el az IEnumerable!!! - J. PropertyHelper.CopyPublicValueTypeProperties(orderListModel, orderListModelExtended);
//PropertyHelper.CopyPublicProperties(orderListModel, orderListModelExtended);
foreach (var orderModel in orderListModel.Data) foreach (var orderModel in orderListModel.Data)
{ {
var orderModelExtended = new OrderModelExtended(); var orderModelExtended = new OrderModelExtended();
PropertyHelper.CopyPublicProperties(orderModel, orderModelExtended); PropertyHelper.CopyPublicValueTypeProperties(orderModel, orderModelExtended);
orderModelExtended.IsMeasurable = await ShouldMarkAsNeedsMeasurementAsync(orderModel); orderModelExtended.IsMeasurable = await ShouldMarkAsNeedsMeasurementAsync(orderModel);
@ -190,7 +191,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
extendedRows.Add(orderModelExtended); extendedRows.Add(orderModelExtended);
} }
orderListModelExtended.Data = extendedRows; // Different cast approach orderListModelExtended.Data = extendedRows;
return orderListModelExtended; return orderListModelExtended;
} }

View File

@ -57,6 +57,8 @@ public class PluginNopStartup : INopStartup
//services.AddSingleton<SessionService>(); //services.AddSingleton<SessionService>();
services.AddScoped<FruitBankAttributeService>(); services.AddScoped<FruitBankAttributeService>();
services.AddScoped<OrderDtoDbTable>();
services.AddScoped<PartnerDbTable>(); services.AddScoped<PartnerDbTable>();
services.AddScoped<ShippingDbTable>(); services.AddScoped<ShippingDbTable>();
services.AddScoped<ShippingDocumentDbTable>(); services.AddScoped<ShippingDocumentDbTable>();
@ -65,7 +67,6 @@ public class PluginNopStartup : INopStartup
services.AddScoped<FilesDbTable>(); services.AddScoped<FilesDbTable>();
services.AddScoped<ShippingDocumentToFilesDbTable>(); services.AddScoped<ShippingDocumentToFilesDbTable>();
services.AddScoped<FruitBankDbContext>(); services.AddScoped<FruitBankDbContext>();
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>(); services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();
services.AddScoped<ICustomOrderSignalREndpointServer, CustomOrderSignalREndpoint>(); services.AddScoped<ICustomOrderSignalREndpointServer, CustomOrderSignalREndpoint>();

View File

@ -1,4 +1,5 @@
using FruitBank.Common; using FruitBank.Common;
using FruitBank.Common.Dtos;
using FruitBank.Common.Entities; using FruitBank.Common.Entities;
using Nop.Data.Mapping; using Nop.Data.Mapping;
@ -11,6 +12,7 @@ public partial class NameCompatibility : INameCompatibility
/// </summary> /// </summary>
public Dictionary<Type, string> TableNames => new Dictionary<Type, string> public Dictionary<Type, string> TableNames => new Dictionary<Type, string>
{ {
//{ typeof(OrderDto), "Order"},
{ typeof(Pallet), FruitBankConstClient.PalletDbTableName}, { typeof(Pallet), FruitBankConstClient.PalletDbTableName},
{ typeof(Files), FruitBankConstClient.FilesDbTableName}, { typeof(Files), FruitBankConstClient.FilesDbTableName},
{ typeof(Partner), FruitBankConstClient.PartnerDbTableName }, { typeof(Partner), FruitBankConstClient.PartnerDbTableName },