improvements, fixes
This commit is contained in:
parent
56123bc787
commit
23e7b6a603
|
|
@ -117,7 +117,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
{
|
||||
_logger.Detail($"GetShippingItems invoked");
|
||||
|
||||
return await ctx.ShippingItems.GetAll().ToListAsync();
|
||||
return await ctx.ShippingItems.GetAll(true).ToListAsync();
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetShippingItemById)]
|
||||
|
|
@ -125,7 +125,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
{
|
||||
_logger.Detail($"GetShippingItemById invoked; id: {id}");
|
||||
|
||||
var shippingItem = await ctx.ShippingItems.GetByIdAsync(id);
|
||||
var shippingItem = await ctx.ShippingItems.GetByIdAsync(id, true);
|
||||
|
||||
if (shippingItem.NetWeight <= 0) _logger.Error($"shippingItem.NetWeight == 0");
|
||||
return shippingItem;
|
||||
|
|
@ -162,7 +162,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
{
|
||||
_logger.Detail($"GetShippingDocuments invoked");
|
||||
|
||||
return await ctx.ShippingDocuments.GetAll().ToListAsync();
|
||||
return await ctx.ShippingDocuments.GetAll(true).ToListAsync();
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetShippingDocumentById)]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
|
|||
using Nop.Services.Catalog;
|
||||
using NUglify.Helpers;
|
||||
using System.Transactions;
|
||||
using LinqToDB;
|
||||
using Nop.Core.ComponentModel;
|
||||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
|
||||
|
|
@ -89,6 +91,8 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
private static readonly ReaderWriterLockSlim _locker = new(LockRecursionPolicy.NoRecursion);
|
||||
|
||||
public async Task<bool> UpdateShippingItemAsync(ShippingItem shippingItem)
|
||||
{
|
||||
if (shippingItem == null)
|
||||
|
|
@ -97,8 +101,11 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
return await Task.FromResult(false);
|
||||
}
|
||||
|
||||
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||
{
|
||||
//using (new ReaderWriteLockDisposable(_locker))
|
||||
//_locker.EnterWriteLock();
|
||||
//try
|
||||
//{
|
||||
using var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
|
||||
try
|
||||
{
|
||||
//Mi van ha nem jött meg a termék? Nem fogják tudni menteni... - J.
|
||||
|
|
@ -127,50 +134,48 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
return await Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
shippingItem.IsMeasured = product != null && shippingItem.IsValidMeasuringValues();
|
||||
|
||||
await ShippingItems.UpdateAsync(shippingItem);
|
||||
|
||||
//TODO: a measuredweight-eket is! - J.
|
||||
if (shippingItem.ProductId == dbShippingItem.ProductId &&
|
||||
shippingItem.IsMeasured == dbShippingItem.IsMeasured && shippingItem.IsMeasurable == dbShippingItem.IsMeasurable &&
|
||||
shippingItem.MeasuredQuantity == dbShippingItem.MeasuredQuantity &&
|
||||
shippingItem.MeasuredNetWeight == dbShippingItem.MeasuredNetWeight && shippingItem.MeasuredGrossWeight == dbShippingItem.MeasuredGrossWeight)
|
||||
if (shippingItem.ProductId != dbShippingItem.ProductId ||
|
||||
shippingItem.IsMeasured != dbShippingItem.IsMeasured || shippingItem.IsMeasurable != dbShippingItem.IsMeasurable ||
|
||||
shippingItem.MeasuredQuantity != dbShippingItem.MeasuredQuantity ||
|
||||
shippingItem.MeasuredNetWeight != dbShippingItem.MeasuredNetWeight || shippingItem.MeasuredGrossWeight != dbShippingItem.MeasuredGrossWeight)
|
||||
{
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
var productIdUnchanged = shippingItem.ProductId == dbShippingItem.ProductId;
|
||||
|
||||
//TODO: productIdUnchanged-et lekezelni! - J.
|
||||
var productIdUnchanged = shippingItem.ProductId == dbShippingItem.ProductId;
|
||||
|
||||
if (shippingItem.IsMeasured)
|
||||
{
|
||||
product!.StockQuantity += shippingItem.MeasuredQuantity.GetValueOrDefault(0);
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product))
|
||||
if (shippingItem.IsMeasured)
|
||||
{
|
||||
Logger.Error($"UpdateProductStockQuantity() == false; shippingItem! id: {product.Id}");
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (dbShippingItem.IsMeasured)
|
||||
{
|
||||
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
|
||||
|
||||
if (product != null)
|
||||
{
|
||||
product.StockQuantity -= dbShippingItem.MeasuredQuantity.GetValueOrDefault(0);
|
||||
product!.StockQuantity += shippingItem.MeasuredQuantity.GetValueOrDefault(0);
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product))
|
||||
{
|
||||
Logger.Error($"UpdateProductStockQuantity() == false; dbShippingItem! id: {product.Id}");
|
||||
Logger.Error($"UpdateProductStockQuantity() == false; shippingItem! id: {product.Id}");
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
|
||||
|
||||
if (dbShippingItem.IsMeasured)
|
||||
{
|
||||
product = await Products.GetByIdAsync(dbShippingItem.ProductId);
|
||||
|
||||
if (product != null)
|
||||
{
|
||||
product.StockQuantity -= dbShippingItem.MeasuredQuantity.GetValueOrDefault(0);
|
||||
|
||||
if (!await UpdateProductStockQuantityAsync(product))
|
||||
{
|
||||
Logger.Error($"UpdateProductStockQuantity() == false; dbShippingItem! id: {product.Id}");
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
else Logger.Warning($"product == null; dbShippingItem.ProductId: {dbShippingItem.ProductId}");
|
||||
}
|
||||
}
|
||||
//else //TODO: productIdUnchanged-et lekezelni! - J.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -179,7 +184,11 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
}
|
||||
|
||||
transaction.Complete();
|
||||
}
|
||||
//}
|
||||
//finally
|
||||
//{
|
||||
// _locker.ExitWriteLock();
|
||||
//}
|
||||
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue