Merge
This commit is contained in:
commit
caa2a86519
|
|
@ -15,6 +15,7 @@ using Mango.Nop.Core.Models;
|
|||
using Nop.Core;
|
||||
using Nop.Core.Domain.Customers;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Factories;
|
||||
using Nop.Services.Customers;
|
||||
using Nop.Services.Localization;
|
||||
using Nop.Web.Framework.Controllers;
|
||||
|
|
@ -154,7 +155,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
|
||||
_logger.Detail($"AddShippingItemPallet invoked; {shippingItemPallet}");
|
||||
|
||||
return await ctx.AddShippingItemPalletAsync(shippingItemPallet);
|
||||
if (!await ctx.AddShippingItemPalletSafeAsync(shippingItemPallet)) return null;
|
||||
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.UpdateShippingItemPallet)]
|
||||
|
|
@ -164,25 +166,39 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
|
||||
_logger.Detail($"UpdateShippingItemPallet invoked; {shippingItemPallet}");
|
||||
|
||||
return await ctx.UpdateShippingItemPalletAsync(shippingItemPallet);
|
||||
if (!await ctx.UpdateShippingItemPalletSafeAsync(shippingItemPallet)) return null;
|
||||
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.AddOrUpdateMeasuredShippingItemPallets)]
|
||||
public async Task<ShippingItem> AddOrUpdateMeasuredShippingItemPallets(List<ShippingItemPallet> shippingItemPallets)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(shippingItemPallets);
|
||||
// ArgumentNullException.ThrowIfNull(shippingItemPallets);
|
||||
|
||||
_logger.Detail($"AddOrUpdateMeasuredShippingItemPallets invoked; count: {shippingItemPallets.Count}");
|
||||
// _logger.Detail($"AddOrUpdateMeasuredShippingItemPallets invoked; count: {shippingItemPallets.Count}");
|
||||
|
||||
if (shippingItemPallets.Count == 0) return null;
|
||||
// if (shippingItemPallets.Count == 0) return null;
|
||||
|
||||
var shippingItemId = shippingItemPallets.FirstOrDefault()!.ShippingItemId;
|
||||
if (shippingItemId <= 0 || shippingItemPallets.Any(x => x.ShippingItemId != shippingItemId)) return null;
|
||||
// var shippingItemId = shippingItemPallets.FirstOrDefault()!.ShippingItemId;
|
||||
// if (shippingItemId <= 0 || shippingItemPallets.Any(x => x.ShippingItemId != shippingItemId)) return null;
|
||||
|
||||
var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemId, false);
|
||||
shippingItem.ShippingItemPallets = shippingItemPallets.Where(sip => sip.IsValidMeasuringValues(shippingItem.IsMeasurable)).ToList();
|
||||
// var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemId, false);
|
||||
// shippingItem.ShippingItemPallets = shippingItemPallets.Where(sip => sip.IsValidMeasuringValues(shippingItem.IsMeasurable)).ToList();
|
||||
|
||||
return await UpdateMeasuredShippingItem(shippingItem);
|
||||
// return await UpdateMeasuredShippingItem(shippingItem);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.AddOrUpdateMeasuredShippingItemPallet)]
|
||||
public async Task<ShippingItemPallet> AddOrUpdateMeasuredShippingItemPallet(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(shippingItemPallet);
|
||||
|
||||
_logger.Detail($"AddOrUpdateMeasuredShippingItemPallet invoked; {shippingItemPallet}");
|
||||
|
||||
if (!await ctx.AddOrUpdateShippingItemPalletSafeAsync(shippingItemPallet)) return null;
|
||||
return await ctx.ShippingItemPallets.GetByIdAsync(shippingItemPallet.Id, false);
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetShippingDocuments)]
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
IShippingDocumentDbSet<ShippingDocumentDbTable>,
|
||||
IShippingItemDbSet<ShippingItemDbTable>,
|
||||
IShippingItemPalletDbSet<ShippingItemPalletDbTable>,
|
||||
IOrderItemPalletDbSet<OrderItemPalletDbTable>,
|
||||
IShippingDocumentToFilesDbSet<ShippingDocumentToFilesDbTable>,
|
||||
IFilesDbSet<FilesDbTable>
|
||||
{
|
||||
|
|
@ -46,6 +47,8 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
public ShippingItemDbTable ShippingItems { get; set; }
|
||||
public ShippingItemPalletDbTable ShippingItemPallets { get; set; }
|
||||
|
||||
public OrderItemPalletDbTable OrderItemPallets { get; set; }
|
||||
|
||||
public FilesDbTable Files { get; set; }
|
||||
public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; }
|
||||
|
||||
|
|
@ -53,7 +56,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
public IRepository<Customer> Customers { get; set; }
|
||||
public IRepository<CustomerRole> CustomerRoles { get; set; }
|
||||
public IRepository<CustomerCustomerRoleMapping> CustomerRoleMappings { get; set; }
|
||||
|
||||
|
||||
public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext,
|
||||
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
|
||||
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
|
||||
|
|
@ -150,15 +153,6 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
});
|
||||
}
|
||||
|
||||
public async Task DeleteShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
await TransactionSafeAsync(async tr =>
|
||||
{
|
||||
await ShippingItemPallets.DeleteAsync(shippingItemPallet, false);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public Task<bool> UpdateMeasuredShippingItemSafeAsync(ShippingItem shippingItem)
|
||||
{
|
||||
if (shippingItem.IsValidMeasuringValues()) return UpdateShippingItemSafeAsync(shippingItem);
|
||||
|
|
@ -168,108 +162,101 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
}
|
||||
|
||||
public Task<bool> UpdateShippingItemSafeAsync(ShippingItem shippingItem)
|
||||
=> TransactionSafeAsync(async _ => await UpdateShippingItemAsync(shippingItem));
|
||||
|
||||
public async Task<bool> UpdateShippingItemAsync(ShippingItem shippingItem)
|
||||
{
|
||||
if (shippingItem == null)
|
||||
try
|
||||
{
|
||||
Logger.Error("shippingItem == null");
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
Product? product = null;
|
||||
var productIsMeasurable = false;
|
||||
|
||||
return TransactionSafeAsync(async tr =>
|
||||
{
|
||||
try
|
||||
if (shippingItem.ProductId > 0)
|
||||
{
|
||||
//Mi van ha nem jött meg a termék? Nem fogják tudni menteni... - J.
|
||||
product = await Products.GetByIdAsync(shippingItem.ProductId);
|
||||
|
||||
Product? product = null;
|
||||
var productIsMeasurable = false;
|
||||
if (product == null)
|
||||
throw new Exception($"shippingItem.ProductId > 0 && product == null; shippingItem.ProductId: {shippingItem.ProductId}");
|
||||
|
||||
if (shippingItem.ProductId > 0)
|
||||
{
|
||||
product = await Products.GetByIdAsync(shippingItem.ProductId);
|
||||
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
}
|
||||
|
||||
if (product == null)
|
||||
throw new Exception($"shippingItem.ProductId > 0 && product == null; shippingItem.ProductId: {shippingItem.ProductId}");
|
||||
shippingItem.IsMeasurable = productIsMeasurable;
|
||||
|
||||
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
}
|
||||
//if (shippingItem.ShippingItemPallets is { Count: > 0 }) await AddOrUpdateShippingItemPalletAsync(shippingItem);
|
||||
|
||||
shippingItem.IsMeasurable = productIsMeasurable;
|
||||
|
||||
if (shippingItem.ShippingItemPallets is { Count: > 0 }) await AddOrUpdateShippingItemPalletAsync(shippingItem);
|
||||
//await AddOrUpdateShippingItemPalletAsync(shippingItem.ShippingItemPallets.Where(x => x.IsValidMeasuringValues(shippingItem.IsMeasurable)), shippingItem);
|
||||
//await AddOrUpdateShippingItemPalletAsync(shippingItem.ShippingItemPallets.Where(x => x.IsValidMeasuringValues(shippingItem.IsMeasurable)), shippingItem);
|
||||
|
||||
//Nem tudhatjuk, h minden Pallet-et tartalmaz-e a shippingItem paraméter! A Biztonság kedvéért lekérjük db-ből! - J.
|
||||
shippingItem.ShippingItemPallets = await ShippingItemPallets.GetAllByShippingItemIdAsync(shippingItem.Id, false).ToListAsync();
|
||||
//Nem tudhatjuk, h minden Pallet-et tartalmaz-e a shippingItem paraméter! A Biztonság kedvéért lekérjük db-ből! - J.
|
||||
shippingItem.ShippingItemPallets = await ShippingItemPallets.GetAllByShippingItemIdAsync(shippingItem.Id, false).ToListAsync();
|
||||
|
||||
//Update előtt kivesszük a korábbi ShippingItem-et a db-ből! - J.
|
||||
var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id, false);
|
||||
if (dbShippingItem == null) throw new Exception($"dbShippingItem == null; shippingItem.Id: {shippingItem.Id}");
|
||||
//Update előtt kivesszük a korábbi ShippingItem-et a db-ből! - J.
|
||||
var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id, false);
|
||||
if (dbShippingItem == null) throw new Exception($"dbShippingItem == null; shippingItem.Id: {shippingItem.Id}");
|
||||
|
||||
var isMeasuredPrerequisite = product != null && shippingItem.PalletsOnDocument == shippingItem.ShippingItemPallets.Count
|
||||
&& shippingItem.ShippingItemPallets.All(x => x.IsMeasuredAndValid(shippingItem.IsMeasurable));
|
||||
var isMeasuredPrerequisite = product != null && shippingItem.PalletsOnDocument == shippingItem.ShippingItemPallets.Count
|
||||
&& shippingItem.ShippingItemPallets.All(x => x.IsMeasuredAndValid(shippingItem.IsMeasurable));
|
||||
|
||||
SetupShippingItemMeasuringValues(shippingItem, isMeasuredPrerequisite);
|
||||
shippingItem.IsMeasured = isMeasuredPrerequisite && shippingItem.IsValidMeasuringValues();
|
||||
SetupShippingItemMeasuringValues(shippingItem, isMeasuredPrerequisite);
|
||||
shippingItem.IsMeasured = isMeasuredPrerequisite && shippingItem.IsValidMeasuringValues();
|
||||
|
||||
await ShippingItems.UpdateAsync(shippingItem, shippingItem.IsMeasured != dbShippingItem.IsMeasured);
|
||||
|
||||
if (shippingItem.ProductId == dbShippingItem.ProductId &&
|
||||
shippingItem.IsMeasured == dbShippingItem.IsMeasured && shippingItem.IsMeasurable == dbShippingItem.IsMeasurable &&
|
||||
shippingItem.MeasuredQuantity == dbShippingItem.MeasuredQuantity &&
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
shippingItem.MeasuredNetWeight == dbShippingItem.MeasuredNetWeight &&
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
shippingItem.MeasuredGrossWeight == dbShippingItem.MeasuredGrossWeight)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var productIdChanged = shippingItem.ProductId != dbShippingItem.ProductId;
|
||||
|
||||
if (shippingItem.IsMeasured)
|
||||
{
|
||||
product!.StockQuantity += productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
|
||||
|
||||
if (productIsMeasurable)
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
|
||||
productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight,
|
||||
productIdChanged ? shippingItem.MeasuredGrossWeight : shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight,
|
||||
shippingItem.IsMeasurable, true);
|
||||
}
|
||||
|
||||
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
|
||||
if (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured)) return true;
|
||||
|
||||
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
|
||||
|
||||
if (product != null)
|
||||
{
|
||||
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
product.StockQuantity -= dbShippingItem.MeasuredQuantity;
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {product.Id}");
|
||||
|
||||
if (!productIsMeasurable) return true;
|
||||
|
||||
var measuringValues = new MeasuringAttributeValues(product.Id, -dbShippingItem.MeasuredNetWeight, -dbShippingItem.MeasuredGrossWeight, dbShippingItem.IsMeasurable);
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
|
||||
|
||||
}
|
||||
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
|
||||
//else //TODO: productIdUnchanged-et lekezelni! - J.
|
||||
await ShippingItems.UpdateAsync(shippingItem, shippingItem.IsMeasured != dbShippingItem.IsMeasured);
|
||||
|
||||
if (shippingItem.ProductId == dbShippingItem.ProductId &&
|
||||
shippingItem.IsMeasured == dbShippingItem.IsMeasured && shippingItem.IsMeasurable == dbShippingItem.IsMeasurable &&
|
||||
shippingItem.MeasuredQuantity == dbShippingItem.MeasuredQuantity &&
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
shippingItem.MeasuredNetWeight == dbShippingItem.MeasuredNetWeight &&
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
shippingItem.MeasuredGrossWeight == dbShippingItem.MeasuredGrossWeight)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
var productIdChanged = shippingItem.ProductId != dbShippingItem.ProductId;
|
||||
|
||||
if (shippingItem.IsMeasured)
|
||||
{
|
||||
throw new Exception($"UpdateShippingItemSafeAsync->TransactionSafeAsync error! shippingItem.Id: {shippingItem.Id}; ex: {ex.Message}", ex);
|
||||
product!.StockQuantity += productIdChanged ? shippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity;
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
|
||||
|
||||
if (productIsMeasurable)
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
|
||||
productIdChanged ? shippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight,
|
||||
productIdChanged ? shippingItem.MeasuredGrossWeight : shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight,
|
||||
shippingItem.IsMeasurable, true);
|
||||
}
|
||||
});
|
||||
|
||||
//if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
|
||||
if (!productIdChanged && (shippingItem.IsMeasured || !dbShippingItem.IsMeasured)) return true;
|
||||
|
||||
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
|
||||
|
||||
if (product != null)
|
||||
{
|
||||
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
product.StockQuantity -= dbShippingItem.MeasuredQuantity;
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product, true))
|
||||
throw new Exception($"UpdateProductStockQuantity() == false; dbShippingItem! product.Id: {product.Id}");
|
||||
|
||||
if (!productIsMeasurable) return true;
|
||||
|
||||
var measuringValues = new MeasuringAttributeValues(product.Id, -dbShippingItem.MeasuredNetWeight, -dbShippingItem.MeasuredGrossWeight, dbShippingItem.IsMeasurable);
|
||||
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
|
||||
|
||||
}
|
||||
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
|
||||
//else //TODO: productIdUnchanged-et lekezelni! - J.
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"UpdateShippingItemAsync error! {shippingItem}; ex: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetupShippingItemMeasuringValues(ShippingItem shippingItem, bool shippingItemIsMeasured)
|
||||
|
|
@ -342,8 +329,8 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
});
|
||||
}
|
||||
|
||||
public Task AddOrUpdateShippingItemPalletSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletSafeAsync(shippingItem.ShippingItemPallets!, shippingItem);
|
||||
public Task<bool> AddOrUpdateShippingItemPalletSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem)
|
||||
public Task AddOrUpdateShippingItemPalletsSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletsSafeAsync(shippingItem.ShippingItemPallets!, shippingItem);
|
||||
public Task<bool> AddOrUpdateShippingItemPalletsSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem)
|
||||
{
|
||||
return TransactionSafeAsync(async tr =>
|
||||
{
|
||||
|
|
@ -354,7 +341,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"AddOrUpdateShippingItemPalletSafeAsync->TransactionSafeAsync error! ex: {ex.Message}", ex);
|
||||
throw new Exception($"AddOrUpdateShippingItemPalletsSafeAsync->TransactionSafeAsync error! ex: {ex.Message}", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -370,6 +357,8 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
throw new Exception($"AddOrUpdateShippingItemPalletAsync->AddOrUpdateShippingItemPalletAsync() == null");
|
||||
}
|
||||
}
|
||||
public async Task<bool> AddOrUpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
|
||||
=> await TransactionSafeAsync(async tr => await AddOrUpdateShippingItemPalletAsync(shippingItemPallet) != null);
|
||||
|
||||
public async Task<ShippingItemPallet?> AddOrUpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
|
|
@ -378,6 +367,15 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
return await UpdateShippingItemPalletAsync(shippingItemPallet);
|
||||
}
|
||||
|
||||
public async Task DeleteShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
await TransactionSafeAsync(async tr =>
|
||||
{
|
||||
await ShippingItemPallets.DeleteAsync(shippingItemPallet, false);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<bool> SetupShippingItemPalletMeauringValues(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
var shippingItem = shippingItemPallet.ShippingItem ?? await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
|
||||
|
|
@ -385,6 +383,7 @@ public class FruitBankDbContext : MgDbContextBase,
|
|||
|
||||
if (!shippingItem.IsMeasurable)
|
||||
{
|
||||
shippingItemPallet.TareWeight = 0;
|
||||
shippingItemPallet.PalletWeight = 0;
|
||||
shippingItemPallet.GrossWeight = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
using FruitBank.Common.Entities;
|
||||
using Mango.Nop.Core.Interfaces;
|
||||
using Nop.Data;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
||||
|
||||
public interface IOrderItemPalletDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<OrderItemPallet>
|
||||
{
|
||||
public TDbTable OrderItemPallets { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using FruitBank.Common.Interfaces;
|
||||
using Mango.Nop.Core.Entities;
|
||||
using Mango.Nop.Core.Repositories;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Services.Logging;
|
||||
|
||||
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
|
||||
: MgEntityBase, IMeasuringItemPalletBase
|
||||
{
|
||||
protected virtual void BeforeInsertOrUpdate(IMeasuringItemPalletBase measuringItemPalletBase)
|
||||
{
|
||||
if (measuringItemPalletBase.IsValidSafeMeasuringValues()) return;
|
||||
|
||||
throw new Exception($"MeasuringItemPalletBaseDbTable->BeforeInsertOrUpdate(); Invalid measuring value(s); {measuringItemPalletBase}");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
using FruitBank.Common.Entities;
|
||||
using LinqToDB;
|
||||
using Nop.Core.Caching;
|
||||
using Nop.Core.Configuration;
|
||||
using Nop.Core.Events;
|
||||
using Nop.Data;
|
||||
using Nop.Services.Logging;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
public class OrderItemPalletDbTable : MeasuringItemPalletBaseDbTable<OrderItemPallet>
|
||||
{
|
||||
public OrderItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||
{
|
||||
}
|
||||
|
||||
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 IQueryable<OrderItemPallet> GetAll(bool loadRelations)
|
||||
{
|
||||
return loadRelations
|
||||
? GetAll().LoadWith(oip => oip.OrderItem)
|
||||
: GetAll();
|
||||
}
|
||||
|
||||
public Task<OrderItemPallet> GetByIdAsync(int id, bool loadRelations)
|
||||
=> GetAll(loadRelations).FirstOrDefaultAsync(oip => oip.Id == id);
|
||||
|
||||
public IQueryable<OrderItemPallet> GetAllByOrderItemIdAsync(int orderItemId, bool loadRelations)
|
||||
=> GetAll(loadRelations).Where(oip => oip.OrderItemId == orderItemId);
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ using Nop.Services.Logging;
|
|||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
public class ShippingItemPalletDbTable : MgDbTableBase<ShippingItemPallet>
|
||||
public class ShippingItemPalletDbTable : MeasuringItemPalletBaseDbTable<ShippingItemPallet>
|
||||
{
|
||||
public ShippingItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
||||
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
||||
|
|
@ -47,11 +47,4 @@ public class ShippingItemPalletDbTable : MgDbTableBase<ShippingItemPallet>
|
|||
|
||||
public IQueryable<ShippingItemPallet> GetAllByShippingItemIdAsync(int shippingItemId, bool loadRelations)
|
||||
=> GetAll(loadRelations).Where(sip => sip.ShippingItemId == shippingItemId);
|
||||
|
||||
private static void BeforeInsertOrUpdate(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
if (shippingItemPallet.IsValidSafeMeasuringValues()) return;
|
||||
|
||||
throw new Exception($"ShippingItemPalletDbTable->BeforeInsertOrUpdate(); Invalid measuring value(s); shippingItemPallet: {shippingItemPallet}");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
using AyCode.Core.Loggers;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using DevExpress.XtraPrinting.Native;
|
||||
using FruitBank.Common.Entities;
|
||||
using FruitBank.Common.Interfaces;
|
||||
using FruitBank.Common.Loggers;
|
||||
|
|
@ -19,15 +18,22 @@ using Nop.Services.Events;
|
|||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.EventConsumers;
|
||||
|
||||
public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, IEnumerable<IAcLogWriterBase> logWriters, IGenericAttributeService genericAttributeService) :
|
||||
MgEventConsumer(httpContextAccessor, logWriters), IConsumer<EntityUpdatedEvent<ShippingItem>>, IConsumer<EntityUpdatedEvent<ShippingDocument>>
|
||||
public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, IEnumerable<IAcLogWriterBase> logWriters) :
|
||||
MgEventConsumer(httpContextAccessor, logWriters),
|
||||
IConsumer<EntityDeletedEvent<Shipping>>,
|
||||
IConsumer<EntityInsertedEvent<ShippingItem>>,
|
||||
IConsumer<EntityUpdatedEvent<ShippingItem>>,
|
||||
IConsumer<EntityDeletedEvent<ShippingItem>>,
|
||||
IConsumer<EntityInsertedEvent<ShippingDocument>>,
|
||||
IConsumer<EntityUpdatedEvent<ShippingDocument>>,
|
||||
IConsumer<EntityDeletedEvent<ShippingDocument>>,
|
||||
IConsumer<EntityInsertedEvent<ShippingItemPallet>>,
|
||||
IConsumer<EntityUpdatedEvent<ShippingItemPallet>>,
|
||||
IConsumer<EntityDeletedEvent<ShippingItemPallet>>
|
||||
{
|
||||
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
||||
{
|
||||
var product = eventMessage.Entity;
|
||||
|
||||
await SaveCustomAttributesAsync(eventMessage.Entity);
|
||||
|
||||
var isMeasurableProduct = await fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
|
||||
|
||||
var shippingItems = await ctx.ShippingItems.Table
|
||||
|
|
@ -41,58 +47,36 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
|
|||
await base.HandleEventAsync(eventMessage);
|
||||
}
|
||||
|
||||
|
||||
public async Task HandleEventAsync(EntityInsertedEvent<Product> eventMessage)
|
||||
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItemPallet> eventMessage)
|
||||
{
|
||||
await SaveCustomAttributesAsync(eventMessage.Entity);
|
||||
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
|
||||
|
||||
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
|
||||
}
|
||||
|
||||
private async Task SaveCustomAttributesAsync(Product product)
|
||||
public async Task HandleEventAsync(EntityUpdatedEvent<ShippingItemPallet> eventMessage)
|
||||
{
|
||||
if (product == null)
|
||||
return;
|
||||
Logger.Info($"HandleEventAsync EntityUpdatedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
|
||||
|
||||
var form = httpContextAccessor.HttpContext?.Request?.Form;
|
||||
if (form == null || !form.Any())
|
||||
return;
|
||||
|
||||
var isMeasurable = form["IsMeasurable"].ToString().Contains("true");
|
||||
|
||||
// Save IsMeasurable
|
||||
if (form.ContainsKey("IsMeasurable"))
|
||||
{
|
||||
await genericAttributeService.SaveAttributeAsync(product, "IsMeasurable", isMeasurable);
|
||||
//Akkor ez kell? - Á.
|
||||
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, isMeasurable, false);
|
||||
}
|
||||
|
||||
// Save NetWeight
|
||||
if (form.ContainsKey("NetWeight"))
|
||||
{
|
||||
var netWeightStr = form["NetWeight"].ToString();
|
||||
if (!string.IsNullOrWhiteSpace(netWeightStr) && decimal.TryParse(netWeightStr, out var netWeight))
|
||||
{
|
||||
await genericAttributeService.SaveAttributeAsync(product, "NetWeight", netWeight);
|
||||
|
||||
//await fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id, 0, 0, , false);
|
||||
}
|
||||
}
|
||||
|
||||
// Save IncomingQuantity
|
||||
if (form.ContainsKey("IncomingQuantity"))
|
||||
{
|
||||
var incomingQtyStr = form["IncomingQuantity"].ToString();
|
||||
if (!string.IsNullOrWhiteSpace(incomingQtyStr) && int.TryParse(incomingQtyStr, out var incomingQuantity))
|
||||
{
|
||||
await genericAttributeService.SaveAttributeAsync(product, "IncomingQuantity", incomingQuantity);
|
||||
}
|
||||
}
|
||||
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
|
||||
}
|
||||
|
||||
public async Task HandleEventAsync(EntityDeletedEvent<ShippingItemPallet> eventMessage)
|
||||
{
|
||||
Logger.Info($"HandleEventAsync EntityDeletedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
|
||||
|
||||
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
|
||||
}
|
||||
|
||||
private async Task UpdateShippingItemMeasuringValuesAsync(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
var shippingItem = await ctx.ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
|
||||
await ctx.UpdateShippingItemAsync(shippingItem);
|
||||
}
|
||||
|
||||
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItem> eventMessage)
|
||||
{
|
||||
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItem>; id: {eventMessage.Entity.Id}");
|
||||
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
|
||||
|
||||
await UpdateShippingDocumentIsAllMeasuredAsync(eventMessage.Entity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public partial class NameCompatibility : INameCompatibility
|
|||
{ typeof(ShippingDocument), FruitBankConstClient.ShippingDocumentDbTableName },
|
||||
{ typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName},
|
||||
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
|
||||
{ typeof(OrderItemPallet), FruitBankConstClient.OrderItemPalletDbTableName},
|
||||
{ typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue