This commit is contained in:
Loretta 2025-10-15 07:57:03 +02:00
parent d36b647f2f
commit 5069b9be80
11 changed files with 248 additions and 105 deletions

View File

@ -1,5 +1,6 @@
using AyCode.Services.SignalRs; using AyCode.Services.SignalRs;
using FruitBank.Common.Dtos; using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
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;
@ -41,7 +42,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers
[NonAction] public Task<List<OrderDto>> GetAllOrderDtos() => _customOrderSignalREndpoint.GetAllOrderDtos(); [NonAction] public Task<List<OrderDto>> GetAllOrderDtos() => _customOrderSignalREndpoint.GetAllOrderDtos();
[NonAction]public Task<OrderDto> GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId); [NonAction]public Task<OrderDto> GetOrderDtoById(int orderId) => _customOrderSignalREndpoint.GetOrderDtoById(orderId);
[NonAction]public Task<List<OrderDto>> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos(); [NonAction]public Task<List<OrderDto>> GetPendingOrderDtos() => _customOrderSignalREndpoint.GetPendingOrderDtos();
[NonAction] public Task<List<OrderDto>> GetAllByIds(int[] orderIds) => _customOrderSignalREndpoint.GetAllByIds(orderIds); [NonAction]public Task<OrderDto> SetOrderStatusToComplete(int orderId) => _customOrderSignalREndpoint.SetOrderStatusToComplete(orderId);
[NonAction] public Task<List<OrderDto>> GetAllOrderDtoByIds(int[] orderIds) => _customOrderSignalREndpoint.GetAllOrderDtoByIds(orderIds);
[NonAction] public Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet) => _customOrderSignalREndpoint.AddOrUpdateMeasuredOrderItemPallet(orderItemPallet);
#endregion CustomOrderSignalREndpoint #endregion CustomOrderSignalREndpoint
[CheckPermission(StandardPermission.Orders.ORDERS_VIEW)] [CheckPermission(StandardPermission.Orders.ORDERS_VIEW)]

View File

@ -1,14 +1,21 @@
using AyCode.Services.SignalRs; using AyCode.Core.Loggers;
using AyCode.Services.SignalRs;
using FruitBank.Common.Dtos; using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces;
using FruitBank.Common.Server.Interfaces; using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.SignalRs; using FruitBank.Common.SignalRs;
using Mango.Nop.Core.Loggers;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers; namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
public class CustomOrderSignalREndpoint(FruitBankDbContext ctx) : ICustomOrderSignalREndpointServer public class CustomOrderSignalREndpoint(FruitBankDbContext ctx, IEnumerable<IAcLogWriterBase> logWriters) : ICustomOrderSignalREndpointServer
{ {
private readonly ILogger _logger = new Logger<CustomOrderSignalREndpoint>(logWriters.ToArray());
[SignalR(SignalRTags.GetAllOrderDtos)] [SignalR(SignalRTags.GetAllOrderDtos)]
public async Task<List<OrderDto>> GetAllOrderDtos() public async Task<List<OrderDto>> GetAllOrderDtos()
{ {
@ -27,9 +34,82 @@ public class CustomOrderSignalREndpoint(FruitBankDbContext ctx) : ICustomOrderSi
return await ctx.OrderDtos.GetAllByOrderStatus(OrderStatus.Pending).ToListAsync(); return await ctx.OrderDtos.GetAllByOrderStatus(OrderStatus.Pending).ToListAsync();
} }
[SignalR(SignalRTags.GetAllByIdList)] [SignalR(SignalRTags.GetAllOrderDtoByIds)]
public async Task<List<OrderDto>> GetAllByIds(int[] orderIds) public async Task<List<OrderDto>> GetAllOrderDtoByIds(int[] orderIds)
{ {
return await ctx.OrderDtos.GetAllByIds(orderIds).ToListAsync(); return await ctx.OrderDtos.GetAllByIds(orderIds).ToListAsync();
} }
[SignalR(SignalRTags.SetOrderStatusToComplete)]
public async Task<OrderDto> SetOrderStatusToComplete(int orderId)
{
_logger.Detail($"SetOrderStatusToComplete invoked; orderId: {orderId}");
if (!await ctx.SetOrderStatusToCompleteSafe(orderId)) return null;
return await ctx.OrderDtos.GetByIdAsync(orderId);
}
[SignalR(SignalRTags.AddOrUpdateMeasuredOrderItemPallet)]
public async Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet)
{
ArgumentNullException.ThrowIfNull(orderItemPallet);
_logger.Detail($"AddOrUpdateMeasuredOrderItemPallet invoked; {orderItemPallet}");
if (!await ctx.AddOrUpdateOrderItemPalletSafeAsync(orderItemPallet)) return null;
return await ctx.OrderItemPallets.GetByIdAsync(orderItemPallet.Id, false);
}
//[SignalR(SignalRTags.AddOrderItemPallet)]
//public async Task<OrderItemPallet> AddOrderItemPallet(OrderItemPallet orderItemPallet)
//{
// ArgumentNullException.ThrowIfNull(orderItemPallet);
// _logger.Detail($"AddOrderItemPallet invoked; {orderItemPallet}");
// if (!await ctx.AddOrderItemPalletSafeAsync(orderItemPallet)) return null;
// return await ctx.OrderItemPallets.GetByIdAsync(orderItemPallet.Id, false);
//}
//[SignalR(SignalRTags.UpdateOrderItemPallet)]
//public async Task<OrderItemPallet> UpdateOrderItemPallet(OrderItemPallet orderItemPallet)
//{
// ArgumentNullException.ThrowIfNull(orderItemPallet);
// _logger.Detail($"UpdateOrderItemPallet invoked; {orderItemPallet}");
// if (!await ctx.UpdateOrderItemPalletSafeAsync(orderItemPallet)) return null;
// return await ctx.OrderItemPallets.GetByIdAsync(orderItemPallet.Id, false);
//}
//[SignalR(SignalRTags.AddOrUpdateMeasuredOrderItemPallets)]
//public async Task<ShippingItem> AddOrUpdateMeasuredOrderItemPallets(List<OrderItemPallet> orderItemPallets)
//{
// // ArgumentNullException.ThrowIfNull(orderItemPallets);
// // _logger.Detail($"AddOrUpdateMeasuredOrderItemPallets invoked; count: {orderItemPallets.Count}");
// // if (orderItemPallets.Count == 0) return null;
// // var shippingItemId = orderItemPallets.FirstOrDefault()!.ShippingItemId;
// // if (shippingItemId <= 0 || orderItemPallets.Any(x => x.ShippingItemId != shippingItemId)) return null;
// // var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemId, false);
// // shippingItem.orderItemPallets = orderItemPallets.Where(sip => sip.IsValidMeasuringValues(shippingItem.IsMeasurable)).ToList();
// // return await UpdateMeasuredShippingItem(shippingItem);
// return null;
//}
//[SignalR(SignalRTags.AddOrUpdateMeasuredOrderItemPallet)]
//public async Task<OrderItemPallet> AddOrUpdateMeasuredOrderItemPallet(OrderItemPallet orderItemPallet)
//{
// ArgumentNullException.ThrowIfNull(orderItemPallet);
// _logger.Detail($"AddOrUpdateMeasuredOrderItemPallet invoked; {orderItemPallet}");
// if (!await ctx.AddOrUpdateOrderItemPalletSafeAsync(orderItemPallet)) return null;
// return await ctx.OrderItemPallets.GetByIdAsync(orderItemPallet.Id, false);
//}
} }

View File

@ -20,6 +20,7 @@ using Nop.Plugin.Misc.FruitBankPlugin.Services;
using Nop.Services.Catalog; using Nop.Services.Catalog;
using Nop.Services.Common; using Nop.Services.Common;
using System.Transactions; using System.Transactions;
using DevExpress.XtraExport.Helpers;
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;
@ -29,6 +30,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class FruitBankDbContext : MgDbContextBase, public class FruitBankDbContext : MgDbContextBase,
IOrderDtoDbSet<OrderDtoDbTable>, IOrderDtoDbSet<OrderDtoDbTable>,
IOrderItemDtoDbSet<OrderItemDtoDbTable>,
IPartnerDbSet<PartnerDbTable>, IPartnerDbSet<PartnerDbTable>,
IShippingDbSet<ShippingDbTable>, IShippingDbSet<ShippingDbTable>,
IShippingDocumentDbSet<ShippingDocumentDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>,
@ -44,6 +46,7 @@ public class FruitBankDbContext : MgDbContextBase,
private readonly IStaticCacheManager _staticCacheManager; private readonly IStaticCacheManager _staticCacheManager;
public OrderDtoDbTable OrderDtos { get; set; } public OrderDtoDbTable OrderDtos { get; set; }
public OrderItemDtoDbTable OrderItemDtos { get; set; }
public PartnerDbTable Partners { get; set; } public PartnerDbTable Partners { get; set; }
public ShippingDbTable Shippings { get; set; } public ShippingDbTable Shippings { get; set; }
@ -64,7 +67,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, OrderDtoDbTable orderDtoDbTable, OrderItemDtoDbTable orderItemDtoDbTable, OrderItemPalletDbTable orderItemPalletDbTable,
IProductService productService, IStaticCacheManager staticCacheManager, IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Product> productRepository, IRepository<Product> productRepository,
IRepository<Customer> customerRepository, IRepository<Customer> customerRepository,
@ -78,15 +81,19 @@ public class FruitBankDbContext : MgDbContextBase,
_fruitBankAttributeService = fruitBankAttributeService; _fruitBankAttributeService = fruitBankAttributeService;
Files = filesDbTable; Files = filesDbTable;
OrderDtos = orderDtoDbTable;
Partners = partnerDbTable; Partners = partnerDbTable;
Products = productRepository;
OrderDtos = orderDtoDbTable;
OrderItemDtos = orderItemDtoDbTable;
OrderItemPallets = orderItemPalletDbTable;
Shippings = shippingDbTable; Shippings = shippingDbTable;
ShippingDocuments = shippingDocumentDbTable; ShippingDocuments = shippingDocumentDbTable;
ShippingItems = shippingItemDbTable; ShippingItems = shippingItemDbTable;
ShippingItemPallets = shippingItemPalletDbTable; ShippingItemPallets = shippingItemPalletDbTable;
ShippingDocumentToFiles = shippingDocumentToFilesDbTable; ShippingDocumentToFiles = shippingDocumentToFilesDbTable;
Products = productRepository;
Customers = customerRepository; Customers = customerRepository;
CustomerRoles = customerRoleRepository; CustomerRoles = customerRoleRepository;
CustomerRoleMappings = customerCustomerRoleMappingRepository; CustomerRoleMappings = customerCustomerRoleMappingRepository;
@ -299,19 +306,8 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public Task<bool> AddShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet) public Task<bool> AddShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
{ => TransactionSafeAsync(async tr => await AddShippingItemPalletAsync(shippingItemPallet) != null);
return TransactionSafeAsync(async tr =>
{
try
{
return (await AddShippingItemPalletAsync(shippingItemPallet)) != null;
}
catch (Exception ex)
{
throw new Exception($"AddShippingItemPalletSafeAsync->TransactionSafeAsync error! shippingItemPallet: {shippingItemPallet}; ex: {ex.Message}", ex);
}
});
}
public async Task<ShippingItemPallet?> UpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet) public async Task<ShippingItemPallet?> UpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
{ {
if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null; if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null;
@ -321,38 +317,21 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public Task<bool> UpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet) public Task<bool> UpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
{ => TransactionSafeAsync(async tr => await UpdateShippingItemPalletAsync(shippingItemPallet) != null);
return TransactionSafeAsync(async tr =>
{
try
{
return (await UpdateShippingItemPalletAsync(shippingItemPallet)) != null;
}
catch (Exception ex)
{
throw new Exception($"UpdateShippingItemPalletSafeAsync->TransactionSafeAsync error! shippingItemPallet: {shippingItemPallet}; ex: {ex.Message}", ex);
}
});
}
public Task AddOrUpdateShippingItemPalletsSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletsSafeAsync(shippingItem.ShippingItemPallets!, shippingItem); public Task AddOrUpdateShippingItemPalletsSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletsSafeAsync(shippingItem.ShippingItemPallets!, shippingItem);
public Task<bool> AddOrUpdateShippingItemPalletsSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem) public Task<bool> AddOrUpdateShippingItemPalletsSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem)
{ {
return TransactionSafeAsync(async tr => return TransactionSafeAsync(async tr =>
{
try
{ {
await AddOrUpdateShippingItemPalletAsync(shippingItemPallets, parentShippingItem); await AddOrUpdateShippingItemPalletAsync(shippingItemPallets, parentShippingItem);
return true; return true;
}
catch (Exception ex)
{
throw new Exception($"AddOrUpdateShippingItemPalletsSafeAsync->TransactionSafeAsync error! ex: {ex.Message}", ex);
}
}); });
} }
public Task AddOrUpdateShippingItemPalletAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletAsync(shippingItem.ShippingItemPallets!, shippingItem); public Task AddOrUpdateShippingItemPalletAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletAsync(shippingItem.ShippingItemPallets!, shippingItem);
public async Task AddOrUpdateShippingItemPalletAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem) public async Task AddOrUpdateShippingItemPalletAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem)
{ {
foreach (var shippingItemPallet in shippingItemPallets) foreach (var shippingItemPallet in shippingItemPallets)
@ -363,6 +342,7 @@ public class FruitBankDbContext : MgDbContextBase,
throw new Exception($"AddOrUpdateShippingItemPalletAsync->AddOrUpdateShippingItemPalletAsync() == null"); throw new Exception($"AddOrUpdateShippingItemPalletAsync->AddOrUpdateShippingItemPalletAsync() == null");
} }
} }
public async Task<bool> AddOrUpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet) public async Task<bool> AddOrUpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
=> await TransactionSafeAsync(async tr => await AddOrUpdateShippingItemPalletAsync(shippingItemPallet) != null); => await TransactionSafeAsync(async tr => await AddOrUpdateShippingItemPalletAsync(shippingItemPallet) != null);
@ -382,19 +362,76 @@ public class FruitBankDbContext : MgDbContextBase,
}); });
} }
public async Task<bool> SetOrderStatusToCompleteSafe(int orderId)
=> await TransactionSafeAsync(async tr => await SetOrderStatusToComplete(orderId) != null);
public async Task<OrderDto?> SetOrderStatusToComplete(int orderId)
{
var orderDto = await OrderDtos.GetByIdAsync(orderId);
if (orderDto == null) return null;
if (!orderDto.IsMeasured || orderDto.OrderStatus == OrderStatus.Complete) return null; //throw new Exception($"SetOrderDtoToComplete; orderDto.IsMeasured == false; {orderDto}");
orderDto.OrderStatus = OrderStatus.Complete;
await OrderDtos.UpdateAsync(orderDto);
foreach (var orderItemDto in orderDto.OrderItemDtos)
{
if (!orderItemDto.IsMeasurable) continue;
var gaNetWeight = CommonHelper.To<double>(orderItemDto.GenericAttributes.FirstOrDefault(x => x.Key == nameof(IMeasuringNetWeight.NetWeight))?.Value ?? "0");
await _fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<OrderItem, double>
(orderItemDto.Id, nameof(IMeasuringNetWeight.NetWeight), orderItemDto.NetWeight);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>
(orderItemDto.ProductId, -(orderItemDto.NetWeight-gaNetWeight), 0, orderItemDto.IsMeasurable, true);
}
return orderDto;
}
public async Task<OrderItemPallet?> AddOrderItemPalletAsync(OrderItemPallet orderItemPallet)
{
if (!await SetupOrderItemPalletMeauringValues(orderItemPallet)) return null;
await OrderItemPallets.InsertAsync(orderItemPallet);
return orderItemPallet;
}
public async Task<OrderItemPallet?> UpdateOrderItemPalletAsync(OrderItemPallet orderItemPallet)
{
if (!await SetupOrderItemPalletMeauringValues(orderItemPallet)) return null;
await OrderItemPallets.UpdateAsync(orderItemPallet);
return orderItemPallet;
}
public async Task<bool> AddOrUpdateOrderItemPalletSafeAsync(OrderItemPallet orderItemPallet)
=> await TransactionSafeAsync(async tr => await AddOrUpdateOrderItemPalletAsync(orderItemPallet) != null);
public async Task<OrderItemPallet?> AddOrUpdateOrderItemPalletAsync(OrderItemPallet orderItemPallet)
{
if (orderItemPallet.Id <= 0) return await AddOrderItemPalletAsync(orderItemPallet);
return await UpdateOrderItemPalletAsync(orderItemPallet);
}
private async Task<bool> SetupShippingItemPalletMeauringValues(ShippingItemPallet shippingItemPallet) private async Task<bool> SetupShippingItemPalletMeauringValues(ShippingItemPallet shippingItemPallet)
{ {
var shippingItem = shippingItemPallet.ShippingItem ?? await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false); var shippingItem = shippingItemPallet.ShippingItem ?? await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
if (shippingItem == null || shippingItemPallet.ShippingItemId != shippingItem.Id) return false; if (shippingItem == null || shippingItemPallet.ShippingItemId != shippingItem.Id) return false;
if (!shippingItem.IsMeasurable) shippingItemPallet.SetupCustomItemPalletMeauringValues(shippingItem.IsMeasurable);
{ return true;
shippingItemPallet.TareWeight = 0;
shippingItemPallet.PalletWeight = 0;
shippingItemPallet.GrossWeight = 0;
} }
shippingItemPallet.IsMeasured = shippingItemPallet.IsValidMeasuringValues(shippingItem.IsMeasurable); private async Task<bool> SetupOrderItemPalletMeauringValues(OrderItemPallet orderItemPallet)
{
var orderItemDto = orderItemPallet.OrderItemDto ?? await OrderItemDtos.GetByIdAsync(orderItemPallet.OrderItemId);
if (orderItemDto == null || orderItemPallet.OrderItemId != orderItemDto.Id) return false;
orderItemPallet.SetupCustomItemPalletMeauringValues(orderItemDto.IsMeasurable);
return true; return true;
} }

View File

@ -0,0 +1,10 @@
using FruitBank.Common.Dtos;
using Mango.Nop.Core.Interfaces;
using Nop.Data;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
public interface IOrderItemDtoDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<OrderItemDto>
{
public TDbTable OrderItemDtos { get; set; }
}

View File

@ -12,7 +12,19 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class MeasuringItemPalletBaseDbTable<TEntity>(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger) : MgDbTableBase<TEntity>(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger) where TEntity public class MeasuringItemPalletBaseDbTable<TEntity>(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger) : MgDbTableBase<TEntity>(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger) where TEntity
: MgEntityBase, IMeasuringItemPalletBase : MgEntityBase, IMeasuringItemPalletBase
{ {
protected virtual void BeforeInsertOrUpdate(IMeasuringItemPalletBase measuringItemPalletBase) protected override void OnUpdate(TEntity entity)
{
BeforeInsertOrUpdate(entity);
base.OnUpdate(entity);
}
protected override void OnInsert(TEntity entity)
{
BeforeInsertOrUpdate(entity);
base.OnInsert(entity);
}
protected virtual void BeforeInsertOrUpdate(TEntity measuringItemPalletBase)
{ {
if (measuringItemPalletBase.IsValidSafeMeasuringValues()) return; if (measuringItemPalletBase.IsValidSafeMeasuringValues()) return;

View File

@ -11,6 +11,26 @@ using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class OrderItemDtoDbTable : MgDbTableBase<OrderItemDto>
{
public OrderItemDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
public IQueryable<OrderItemDto> GetAll(bool loadRelations)
{
return GetAll()
.LoadWith(oi => oi.OrderDto)
.LoadWith(oi => oi.OrderItemPallets)
.LoadWith(oi => oi.GenericAttributes)
.LoadWith(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes);
}
public Task<OrderItemDto> GetByIdAsync(int orderItemId) => GetAll(true).Where(x => x.Id == orderItemId).FirstOrDefaultAsync(null);
public IQueryable<OrderItemDto> GetAllByOrderId(int orderId)=> GetAll(true).Where(o => o.OrderId == orderId);
}
public class OrderDtoDbTable : MgDbTableBase<OrderDto> public class OrderDtoDbTable : MgDbTableBase<OrderDto>
{ {
@ -23,21 +43,14 @@ public class OrderDtoDbTable : MgDbTableBase<OrderDto>
{ {
return GetAll() return GetAll()
.LoadWith(o => o.GenericAttributes) .LoadWith(o => o.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.ProductDto).ThenLoad(prod=>prod.GenericAttributes) .LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.GenericAttributes) .LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets); .LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets);
} }
public Task<OrderDto> GetByIdAsync(int orderId) public Task<OrderDto> GetByIdAsync(int orderId) => GetAll(true).Where(x => x.Id == orderId).FirstOrDefaultAsync(null);
{
return GetAll(true).Where(x => x.Id == orderId).FirstOrDefaultAsync(null);
}
public IQueryable<OrderDto> GetAllByOrderStatus(OrderStatus orderStatus) public IQueryable<OrderDto> GetAllByOrderStatus(OrderStatus orderStatus) => GetAll(true).Where(o => o.OrderStatusId == (int)orderStatus);
=> GetAll(true).Where(o => o.OrderStatusId == (int)orderStatus);
public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds) public IQueryable<OrderDto> GetAllByIds(IEnumerable<int> orderIds) => GetAll(true).Where(o => orderIds.Contains(o.Id));
{
return GetAll(true).Where(o => orderIds.Contains(o.Id));
}
} }

View File

@ -15,24 +15,13 @@ public class OrderItemPalletDbTable : MeasuringItemPalletBaseDbTable<OrderItemPa
{ {
} }
protected override void OnUpdate(OrderItemPallet entity)
{
BeforeInsertOrUpdate(entity);
base.OnUpdate(entity);
}
protected override void OnInsert(OrderItemPallet entity)
{
BeforeInsertOrUpdate(entity);
base.OnInsert(entity);
}
public override IQueryable<OrderItemPallet> GetAll() => base.GetAll(); public override IQueryable<OrderItemPallet> GetAll() => base.GetAll();
public IQueryable<OrderItemPallet> GetAll(bool loadRelations) public IQueryable<OrderItemPallet> GetAll(bool loadRelations)
{ {
return loadRelations return loadRelations
? GetAll().LoadWith(oip => oip.OrderItemDto).ThenLoad(oi => oi.ProductDto) ? GetAll()
.LoadWith(oip => oip.OrderItemDto).ThenLoad(oi => oi.ProductDto)
: GetAll(); : GetAll();
} }

View File

@ -16,18 +16,6 @@ public class ShippingItemPalletDbTable : MeasuringItemPalletBaseDbTable<Shipping
{ {
} }
protected override void OnUpdate(ShippingItemPallet entity)
{
BeforeInsertOrUpdate(entity);
base.OnUpdate(entity);
}
protected override void OnInsert(ShippingItemPallet entity)
{
BeforeInsertOrUpdate(entity);
base.OnInsert(entity);
}
public override IQueryable<ShippingItemPallet> GetAll() => base.GetAll(); public override IQueryable<ShippingItemPallet> GetAll() => base.GetAll();
public IQueryable<ShippingItemPallet> GetAll(bool loadRelations) public IQueryable<ShippingItemPallet> GetAll(bool loadRelations)

View File

@ -35,14 +35,17 @@ using Nop.Web.Areas.Admin.Models.Orders;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using System.Runtime.Intrinsics.Arm; using System.Runtime.Intrinsics.Arm;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
namespace Nop.Plugin.Misc.FruitBankPlugin.Factories namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
{ {
public class CustomOrderModelFactory : OrderModelFactory public class CustomOrderModelFactory : OrderModelFactory
{ {
private FruitBankDbContext _ctx;
private readonly IOrderMeasurementService _orderMeasurementService; private readonly IOrderMeasurementService _orderMeasurementService;
public CustomOrderModelFactory( public CustomOrderModelFactory(
FruitBankDbContext ctx,
IOrderMeasurementService orderMeasurementService, IOrderMeasurementService orderMeasurementService,
AddressSettings addressSettings, AddressSettings addressSettings,
CatalogSettings catalogSettings, CatalogSettings catalogSettings,
@ -136,6 +139,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
taxSettings taxSettings
) )
{ {
_ctx = ctx;
_orderMeasurementService = orderMeasurementService; _orderMeasurementService = orderMeasurementService;
} }
@ -176,12 +180,14 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Factories
var orderListModel = await PrepareOrderListModelAsync(searchModel); var orderListModel = await PrepareOrderListModelAsync(searchModel);
var extendedRows = new List<OrderModelExtended>(orderListModel.RecordsFiltered); var extendedRows = new List<OrderModelExtended>(orderListModel.RecordsFiltered);
var orderDtosById = await _ctx.OrderDtos.GetAllByIds(orderListModel.Data.Select(x => x.Id)).ToDictionaryAsync(k => k.Id, v => v);
foreach (var orderModel in orderListModel.Data) foreach (var orderModel in orderListModel.Data)
{ {
var orderModelExtended = new OrderModelExtended(); var orderModelExtended = new OrderModelExtended();
PropertyHelper.CopyPublicValueTypeProperties(orderModel, orderModelExtended); PropertyHelper.CopyPublicValueTypeProperties(orderModel, orderModelExtended);
orderModelExtended.IsMeasurable = await ShouldMarkAsNeedsMeasurementAsync(orderModel); orderModelExtended.IsMeasurable = orderDtosById[orderModel.Id].IsMeasurable;// await ShouldMarkAsNeedsMeasurementAsync(orderModel);
Console.WriteLine(orderModelExtended.Id); Console.WriteLine(orderModelExtended.Id);
extendedRows.Add(orderModelExtended); extendedRows.Add(orderModelExtended);

View File

@ -59,6 +59,9 @@ public class PluginNopStartup : INopStartup
services.AddScoped<FruitBankAttributeService>(); services.AddScoped<FruitBankAttributeService>();
services.AddScoped<OrderDtoDbTable>(); services.AddScoped<OrderDtoDbTable>();
services.AddScoped<OrderItemDtoDbTable>();
services.AddScoped<OrderItemPalletDbTable>();
services.AddScoped<PartnerDbTable>(); services.AddScoped<PartnerDbTable>();
services.AddScoped<ShippingDbTable>(); services.AddScoped<ShippingDbTable>();
services.AddScoped<ShippingDocumentDbTable>(); services.AddScoped<ShippingDocumentDbTable>();

View File

@ -14,18 +14,20 @@ 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(Files), FruitBankConstClient.FilesDbTableName},
{ typeof(Pallet), FruitBankConstClient.PalletDbTableName},
{ typeof(Partner), FruitBankConstClient.PartnerDbTableName },
{ typeof(ProductDto), nameof(Product)}, { typeof(ProductDto), nameof(Product)},
{ typeof(OrderDto), nameof(Order)}, { typeof(OrderDto), nameof(Order)},
{ typeof(OrderItemDto), nameof(OrderItem)}, { typeof(OrderItemDto), nameof(OrderItem)},
{ typeof(OrderItemPallet), FruitBankConstClient.OrderItemPalletDbTableName},
{ typeof(Pallet), FruitBankConstClient.PalletDbTableName},
{ typeof(Files), FruitBankConstClient.FilesDbTableName},
{ typeof(Partner), FruitBankConstClient.PartnerDbTableName },
{ typeof(Shipping), FruitBankConstClient.ShippingDbTableName }, { typeof(Shipping), FruitBankConstClient.ShippingDbTableName },
{ typeof(ShippingDocument), FruitBankConstClient.ShippingDocumentDbTableName }, { typeof(ShippingDocument), FruitBankConstClient.ShippingDocumentDbTableName },
{ typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName}, { typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName},
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName}, { typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
{ typeof(OrderItemPallet), FruitBankConstClient.OrderItemPalletDbTableName},
{ typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName}, { typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName},
}; };