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 FruitBank.Common.Dtos;
using FruitBank.Common.Interfaces;
using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.SignalRs;
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.Models;
using Nop.Services.Orders;
@ -15,33 +18,24 @@ using Nop.Web.Framework.Mvc.Filters;
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;
private readonly CustomOrderModelFactory _orderModelFactory = orderModelFactory as CustomOrderModelFactory;
public async Task<OrderListModelExtended> GetOrderModelsByFilter(OrderSearchModel searchModel)
[SignalR(SignalRTags.GetAllOrderDtos)]
public async Task<List<OrderDto>> GetAllOrderDtos()
{
var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel);
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 await ctx.OrderDtos.GetAllDtos().ToListAsync();
}
return orderListModel;
[SignalR(SignalRTags.GetOrderDtoById)]
public async Task<OrderDto> GetOrderDtoById(int orderId)
{
return await ctx.OrderDtos.GetDtoByIdAsync(orderId);
}
[SignalR(SignalRTags.GetPendingOrderModels)]
public async Task<OrderListModelExtended> GetPendingOrderModels()
[SignalR(SignalRTags.GetPendingOrderDtos)]
public async Task<List<OrderDto>> GetPendingOrderDtos()
{
var orderSearchModel = new OrderSearchModel
{
OrderStatusIds = new List<int> { 1 }
};
return await GetOrderModelsByFilter(orderSearchModel);
return await ctx.OrderDtos.GetAllByStatusDto(OrderStatus.Pending).ToListAsync();
}
}
@ -64,6 +58,15 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
// ... 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)]
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)
{
//prepare model
var orderListModel = await GetOrderModelsByFilter(searchModel);
var orderListModel = await GetOrderListModelByFilter(searchModel);
var valami = Json(orderListModel);
Console.WriteLine(valami);
return valami;
}
public async Task<OrderListModelExtended> GetOrderModelsByFilter(OrderSearchModel searchModel)
public async Task<OrderListModelExtended> GetOrderListModelByFilter(OrderSearchModel searchModel)
{
//return _customOrderService.
var orderListModel = await _orderModelFactory.PrepareOrderListModelExtendedAsync(searchModel);
@ -104,15 +107,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
return orderListModel;
}
[SignalR(SignalRTags.GetPendingOrderModels)]
public async Task<OrderListModelExtended> GetPendingOrderModels()
public async Task<OrderListModelExtended> GetPendingOrderListModel()
{
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()

View File

@ -23,10 +23,12 @@ using System.Transactions;
using FruitBank.Common.Dtos;
using Mango.Nop.Core.Dtos;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Nop.Core.Domain.Orders;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class FruitBankDbContext : MgDbContextBase,
IOrderDtoDbSet<OrderDtoDbTable>,
IPartnerDbSet<PartnerDbTable>,
IShippingDbSet<ShippingDbTable>,
IShippingDocumentDbSet<ShippingDocumentDbTable>,
@ -41,6 +43,8 @@ public class FruitBankDbContext : MgDbContextBase,
private readonly IProductService _productService;
private readonly IStaticCacheManager _staticCacheManager;
public OrderDtoDbTable OrderDtos { get; set; }
public PartnerDbTable Partners { get; set; }
public ShippingDbTable Shippings { 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,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
OrderDtoDbTable orderDtoDbTable,
IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Product> productRepository,
IRepository<Customer> customerRepository,
@ -73,6 +78,7 @@ public class FruitBankDbContext : MgDbContextBase,
_fruitBankAttributeService = fruitBankAttributeService;
Files = filesDbTable;
OrderDtos = orderDtoDbTable;
Partners = partnerDbTable;
Shippings = shippingDbTable;
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.Data;
using Nop.Services.Logging;
using static LinqToDB.Reflection.Methods.LinqToDB.Insert;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;

View File

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

View File

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

View File

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