rename: QuantityOnDocument, NetWeightOnDocument, GrossWeightOnDocument; improvements, fixes, etc...

This commit is contained in:
Loretta 2025-10-02 07:23:20 +02:00
parent 63abc01006
commit f231fd3165
11 changed files with 150 additions and 62 deletions

View File

@ -127,8 +127,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
_logger.Detail($"GetShippingItemById invoked; id: {id}");
var shippingItem = await ctx.ShippingItems.GetByIdAsync(id, true);
if (shippingItem.NetWeight <= 0) _logger.Error($"shippingItem.NetWeight == 0");
return shippingItem;
}
@ -139,10 +137,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
_logger.Detail($"UpdateShippingItem invoked; id: {shippingItem.Id}");
if (!await ctx.UpdateShippingItemAsync(shippingItem))
return null; //await ctx.ShippingItems.GetByIdAsync(shippingItem.Id);
return shippingItem;
if (!await ctx.UpdateShippingItemAsync(shippingItem)) return null;
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
}
[SignalR(SignalRTags.UpdateMeasuredShippingItem)]
@ -152,10 +148,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
_logger.Detail($"UpdateMeasuredShippingItem invoked; id: {shippingItem.Id}");
if (!await ctx.UpdateMeasuredShippingItemAsync(shippingItem))
return null; //await ctx.ShippingItems.GetByIdAsync(shippingItem.Id);
return shippingItem;
if (!await ctx.UpdateMeasuredShippingItemAsync(shippingItem)) return null;
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
}
[SignalR(SignalRTags.GetShippingDocuments)]

View File

@ -25,7 +25,7 @@ using Mango.Nop.Core.Dtos;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>, IShippingDbSet<ShippingDbTable>, IShippingItemDbSet<ShippingItemDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>, IShippingDbSet<ShippingDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>, IShippingItemDbSet<ShippingItemDbTable>, IShippingItemPalletDbSet<ShippingItemPalletDbTable>
{
private readonly FruitBankAttributeService _fruitBankAttributeService;
private readonly IStoreContext _storeContext;
@ -34,9 +34,10 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
public PartnerDbTable Partners { get; set; }
public ShippingDbTable Shippings { get; set; }
public ShippingItemDbTable ShippingItems { get; set; }
public ShippingDocumentDbTable ShippingDocuments { get; set; }
public ShippingItemDbTable ShippingItems { get; set; }
public ShippingItemPalletDbTable ShippingItemPallets { get; set; }
public IRepository<Product> Products { get; set; }
public IRepository<Customer> Customers { get; set; }
public IRepository<CustomerRole> CustomerRoles { get; set; }
@ -44,8 +45,8 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingDocumentDbTable shippingDocumentDbTable, IProductService productService, IStaticCacheManager staticCacheManager,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable,
IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Product> productRepository,
IRepository<Customer> customerRepository,
IRepository<CustomerCustomerRoleMapping> customerCustomerRoleMappingRepository,
@ -59,8 +60,9 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
Partners = partnerDbTable;
Shippings = shippingDbTable;
ShippingItems = shippingItemDbTable;
ShippingDocuments = shippingDocumentDbTable;
ShippingItems = shippingItemDbTable;
ShippingItemPallets = shippingItemPalletDbTable;
Products = productRepository;
Customers = customerRepository;
@ -156,9 +158,9 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
shippingItem.IsMeasurable = productIsMeasurable;
if (shippingItem.MeasuredQuantity <= 0) shippingItem.MeasuredQuantity = null;
if (!shippingItem.IsMeasurable || shippingItem.MeasuredNetWeight <= 0) shippingItem.MeasuredNetWeight = null;
if (!shippingItem.IsMeasurable || shippingItem.MeasuredGrossWeight <= 0) shippingItem.MeasuredGrossWeight = null;
if (shippingItem.MeasuredQuantity < 0) shippingItem.MeasuredQuantity = 0;
if (!shippingItem.IsMeasurable || shippingItem.MeasuredNetWeight < 0) shippingItem.MeasuredNetWeight = 0;
if (!shippingItem.IsMeasurable || shippingItem.MeasuredGrossWeight < 0) shippingItem.MeasuredGrossWeight = 0;
//Update előtt kivesszük a korábbi ShippingItem-et a db-ből! - J.
var dbShippingItem = await ShippingItems.GetByIdAsync(shippingItem.Id);
@ -183,23 +185,16 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
if (shippingItem.IsMeasured)
{
product!.StockQuantity += productIdUnchanged ? shippingItem.MeasuredQuantity!.Value - dbShippingItem.MeasuredQuantity.GetValueOrDefault(0) : shippingItem.MeasuredQuantity!.Value;
product!.StockQuantity += productIdUnchanged ? shippingItem.MeasuredQuantity - dbShippingItem.MeasuredQuantity : shippingItem.MeasuredQuantity;
if (!await UpdateProductStockQuantityAsync(product, true))
throw new Exception($"UpdateProductStockQuantity() == false; shippingItem! product.Id: {product.Id}");
if (productIsMeasurable)
{
var measuringValues = new MeasuringAttributeValues
{
Id = product.Id,
NetWeight = productIdUnchanged ? shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight.GetValueOrDefault(0) : shippingItem.MeasuredNetWeight,
GrossWeight = productIdUnchanged ? shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight.GetValueOrDefault(0) : shippingItem.MeasuredGrossWeight,
IsMeasurable = shippingItem.IsMeasurable
};
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
}
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(product.Id,
productIdUnchanged ? shippingItem.MeasuredNetWeight - dbShippingItem.MeasuredNetWeight : shippingItem.MeasuredNetWeight,
productIdUnchanged ? shippingItem.MeasuredGrossWeight - dbShippingItem.MeasuredGrossWeight : shippingItem.MeasuredGrossWeight,
shippingItem.IsMeasurable, true);
}
if (productIdUnchanged || !dbShippingItem.IsMeasured) return true;
@ -209,14 +204,14 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
if (product != null)
{
productIsMeasurable = await _fruitBankAttributeService.IsMeasurableEntityAsync<Product>(product.Id);
product.StockQuantity -= dbShippingItem.MeasuredQuantity.GetValueOrDefault(0);
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.GetValueOrDefault(0), -dbShippingItem.MeasuredGrossWeight.GetValueOrDefault(0), dbShippingItem.IsMeasurable);
var measuringValues = new MeasuringAttributeValues(product.Id, -dbShippingItem.MeasuredNetWeight, -dbShippingItem.MeasuredGrossWeight, dbShippingItem.IsMeasurable);
await _fruitBankAttributeService.InsertOrUpdateMeasuringAttributeValuesAsync<Product>(measuringValues, true);
}

View File

@ -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 IShippingItemPalletDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<ShippingItemPallet>
{
public TDbTable ShippingItemPallets { get; set; }
}

View File

@ -24,7 +24,7 @@ public class PartnerDbTable : MgDbTableBase<Partner>
return loadRelations
? GetAll()
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(s => s.Shipping)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(si => si.ShippingItems)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(si => si.ShippingItems).ThenLoad(sip => sip.ShippingItemPallets)
: GetAll();
}

View File

@ -23,7 +23,7 @@ public class ShippingDbTable : MgDbTableBase<Shipping>
{
return loadRelations
? GetAll()
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(si => si.ShippingItems)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(si => si.ShippingItems).ThenLoad(sip => sip.ShippingItemPallets)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(p => p.Partner)
: GetAll();
}

View File

@ -24,7 +24,7 @@ public class ShippingDocumentDbTable : MgDbTableBase<ShippingDocument>
return loadRelations
? GetAll()
.LoadWith(s => s.Shipping)
.LoadWith(si => si.ShippingItems)
.LoadWith(si => si.ShippingItems).ThenLoad(sip => sip.ShippingItemPallets)
.LoadWith(p => p.Partner)
: GetAll();
}

View File

@ -36,6 +36,7 @@ public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
? GetAll()
.LoadWith(si => si.ShippingDocument).ThenLoad(s => s.Shipping)
.LoadWith(si => si.ShippingDocument).ThenLoad(p => p.Partner)
.LoadWith(si => si.ShippingItemPallets)
.LoadWith(si => si.Product)
: GetAll();
}
@ -55,8 +56,8 @@ public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
private static void RoundMeasuredValue(ShippingItem shippingItem)
{
if (shippingItem.MeasuredNetWeight.HasValue) shippingItem.MeasuredNetWeight = double.Round(shippingItem.MeasuredNetWeight.Value, 1);
if (shippingItem.MeasuredGrossWeight.HasValue) shippingItem.MeasuredGrossWeight = double.Round(shippingItem.MeasuredGrossWeight.Value, 1);
shippingItem.MeasuredNetWeight = double.Round(shippingItem.MeasuredNetWeight, 1);
shippingItem.MeasuredGrossWeight = double.Round(shippingItem.MeasuredGrossWeight, 1);
}
}

View File

@ -0,0 +1,54 @@
using FruitBank.Common.Entities;
using LinqToDB;
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 ShippingItemPalletDbTable : MgDbTableBase<ShippingItemPallet>
{
public ShippingItemPalletDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
protected override void OnUpdate(ShippingItemPallet entity)
{
RoundMeasuredValue(entity);
base.OnUpdate(entity);
}
protected override void OnInsert(ShippingItemPallet entity)
{
RoundMeasuredValue(entity);
base.OnInsert(entity);
}
public override IQueryable<ShippingItemPallet> GetAll() => base.GetAll();
public IQueryable<ShippingItemPallet> GetAll(bool loadRelations)
{
return loadRelations
? GetAll()
.LoadWith(sip => sip.ShippingItem).ThenLoad(si => si.ShippingDocument).ThenLoad(sd => sd.Shipping)
.LoadWith(sip => sip.ShippingItem).ThenLoad(si => si.ShippingDocument).ThenLoad(p => p.Partner)
.LoadWith(sip => sip.ShippingItem).ThenLoad(si => si.Product)
: GetAll();
}
public Task<ShippingItemPallet> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(sip => sip.Id == id);
public IQueryable<ShippingItemPallet> GetAllByShippingItemIdAsync(int shippingItemId, bool loadRelations)
=> GetAll(loadRelations).Where(sip => sip.ShippingItemId == shippingItemId);
private static void RoundMeasuredValue(ShippingItemPallet shippingItem)
{
shippingItem.NetWeight = double.Round(shippingItem.NetWeight, 1);
shippingItem.GrossWeight = double.Round(shippingItem.GrossWeight, 1);
}
}

View File

@ -57,8 +57,9 @@ public class PluginNopStartup : INopStartup
services.AddScoped<FruitBankAttributeService>();
services.AddScoped<PartnerDbTable>();
services.AddScoped<ShippingDbTable>();
services.AddScoped<ShippingItemDbTable>();
services.AddScoped<ShippingDocumentDbTable>();
services.AddScoped<ShippingItemDbTable>();
services.AddScoped<ShippingItemPalletDbTable>();
services.AddScoped<FruitBankDbContext>();
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();

View File

@ -13,8 +13,9 @@ public partial class NameCompatibility : INameCompatibility
{
{ typeof(Partner), FruitBankConstClient.PartnerDbTableName },
{ typeof(Shipping), FruitBankConstClient.ShippingDbTableName },
{ typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName},
{ typeof(ShippingDocument), FruitBankConstClient.ShippingDocumentDbTableName },
{ typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName},
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
};

View File

@ -2,7 +2,6 @@
using FruitBank.Common.Interfaces;
using FruitBank.Common.Models;
using Nop.Core;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common;
using Nop.Services.Common;
@ -10,18 +9,25 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
public class FruitBankAttributeService(IGenericAttributeService genericAttributeService, IStoreContext storeContext)
{
private const string NET_WEIGHT_KEY = nameof(IMeasuringAttributeValues.NetWeight);
private const string GROSS_WEIGHT_KEY = nameof(IMeasuringAttributeValues.GrossWeight);
private const string IS_MEASURABLE_KEY = nameof(IMeasuringAttributeValues.IsMeasurable);
public async Task<GenericAttribute?> GetGenericAttributeAsync<TEntity>(int entityId, string key, int storeId)
{
return (await genericAttributeService.GetAttributesForEntityAsync(entityId, typeof(TEntity).Name)).SingleOrDefault(ga => ga.StoreId == storeId && ga.Key == key);
}
public async Task<List<GenericAttribute>> GetMeasuringAttributesAsync<TEntity>(int entityId, int storeId)
public async Task<List<GenericAttribute>?> GetMeasuringAttributesAsync<TEntity>(int entityId, int storeId)
{
var measuringAttributes = (await genericAttributeService.GetAttributesForEntityAsync(entityId, typeof(TEntity).Name))
.Where(ga => ga.StoreId == storeId &&
(ga.Key is nameof(IMeasuringAttributeValues.NetWeight) or nameof(IMeasuringAttributeValues.GrossWeight) or nameof(IMeasuringAttributeValues.IsMeasurable)))
.Where(ga => ga.StoreId == storeId && ga.Key is NET_WEIGHT_KEY or GROSS_WEIGHT_KEY or IS_MEASURABLE_KEY)
.ToList();
if (measuringAttributes.Count == 0) return null;
if (measuringAttributes.Count != 3) throw new Exception($"FruitBankAttributeService->GetMeasuringAttributesAsync(); measuringAttributes.Count != 3; entityId: {entityId}");
return measuringAttributes;
}
@ -31,14 +37,13 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
public async Task<MeasuringAttributeValues?> GetMeasuringAttributeValuesAsync<TEntity>(int entityId, int storeId)
{
var measuringAttributes = await GetMeasuringAttributesAsync<TEntity>(entityId, storeId);
if (measuringAttributes.Count == 0) return null;
if (measuringAttributes == null) return null;
var measuringAttributeValues = new MeasuringAttributeValues(
entityId,
CommonHelper.To<double?>(measuringAttributes.FirstOrDefault(ga => ga.Key == nameof(IMeasuringAttributeValues.NetWeight))?.Value),
CommonHelper.To<double?>(measuringAttributes.FirstOrDefault(ga => ga.Key == nameof(IMeasuringAttributeValues.GrossWeight))?.Value),
CommonHelper.To<bool?>(measuringAttributes.FirstOrDefault(ga => ga.Key == nameof(IMeasuringAttributeValues.IsMeasurable))?.Value));
CommonHelper.To<double>(measuringAttributes.Single(ga => ga.Key == NET_WEIGHT_KEY).Value),
CommonHelper.To<double>(measuringAttributes.Single(ga => ga.Key == GROSS_WEIGHT_KEY).Value),
CommonHelper.To<bool>(measuringAttributes.Single(ga => ga.Key == IS_MEASURABLE_KEY).Value));
return measuringAttributeValues;
}
@ -46,42 +51,69 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
public Task<bool> IsMeasurableEntityAsync<TEntity>(int entityId) => IsMeasurableEntityAsync<TEntity>(entityId, storeContext.GetCurrentStore().Id);
public async Task<bool> IsMeasurableEntityAsync<TEntity>(int entityId, int storeId)
{
var measurableAttribute = await GetGenericAttributeAsync<TEntity>(entityId, nameof(IMeasuringAttributeValues.IsMeasurable), storeId);
var measurableAttribute = await GetGenericAttributeAsync<TEntity>(entityId, IS_MEASURABLE_KEY, storeId);
return measurableAttribute != null && CommonHelper.To<bool>(measurableAttribute.Value);
}
public async Task<MeasuringAttributeValues> InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(int entityId, double netWeight, double grossWeight, bool isMeasurable, bool cumulativeWeightUpdate)
{
var measuringAttributeValues = new MeasuringAttributeValues
{
Id = entityId,
NetWeight = netWeight,
GrossWeight = grossWeight,
IsMeasurable = isMeasurable
};
await InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(measuringAttributeValues, cumulativeWeightUpdate);
return measuringAttributeValues;
}
public Task InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(IMeasuringAttributeValues measuringAttributeValues, bool cumulativeWeightUpdate)
=> InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(measuringAttributeValues, cumulativeWeightUpdate, storeContext.GetCurrentStore().Id);
public async Task InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(IMeasuringAttributeValues measuringAttributeValues, bool cumulativeWeightUpdate, int storeId)
{
if (!measuringAttributeValues.HasValues()) throw new Exception($"FruitBankAttributeService->InsertOrUpdateMeasuringAttributeValuesAsync; measuringAttributeValues.HasValues() == false; keyGroup: {typeof(TEntity).Name} values: {measuringAttributeValues}");
if (!measuringAttributeValues.HasMeasuringValues()) throw new Exception($"FruitBankAttributeService->InsertOrUpdateMeasuringAttributeValuesAsync; measuringAttributeValues.HasMeasuringValues() == false; keyGroup: {typeof(TEntity).Name} values: {measuringAttributeValues}");
var entityId = measuringAttributeValues.Id;
var measuringAttributes = await GetMeasuringAttributesAsync<TEntity>(entityId, storeId);
var netWeightAttribute = measuringAttributes.FirstOrDefault(ma => ma.Key == nameof(IMeasuringAttributeValues.NetWeight));
if (netWeightAttribute != null) await UpdateMeasuringWeightAttributeValueAsync(netWeightAttribute, measuringAttributeValues.NetWeight!.Value, cumulativeWeightUpdate);
else await InsertGenericAttributeAsync<TEntity, double>(entityId, nameof(IMeasuringAttributeValues.NetWeight), measuringAttributeValues.NetWeight!.Value, storeId);
if (measuringAttributes == null)
{
await InsertGenericAttributeAsync<TEntity, double>(entityId, NET_WEIGHT_KEY, double.Round(measuringAttributeValues.NetWeight, 1), storeId);
await InsertGenericAttributeAsync<TEntity, double>(entityId, GROSS_WEIGHT_KEY, double.Round(measuringAttributeValues.GrossWeight, 1), storeId);
await InsertGenericAttributeAsync<TEntity, bool>(entityId, IS_MEASURABLE_KEY, measuringAttributeValues.IsMeasurable, storeId);
var grossWeightAttribute = measuringAttributes.FirstOrDefault(ma => ma.Key == nameof(IMeasuringAttributeValues.GrossWeight));
if (grossWeightAttribute != null) await UpdateMeasuringWeightAttributeValueAsync(grossWeightAttribute, measuringAttributeValues.GrossWeight!.Value, cumulativeWeightUpdate);
else await InsertGenericAttributeAsync<TEntity, double>(entityId, nameof(IMeasuringAttributeValues.GrossWeight), measuringAttributeValues.GrossWeight!.Value, storeId);
return;
}
var isMeasurableAttribute = measuringAttributes.FirstOrDefault(ma => ma.Key == nameof(IMeasuringAttributeValues.IsMeasurable));
if (isMeasurableAttribute != null) await UpdateGenericAttributeAsync(isMeasurableAttribute, measuringAttributeValues.IsMeasurable!.Value);
else await InsertGenericAttributeAsync<TEntity, bool>(entityId, nameof(IMeasuringAttributeValues.IsMeasurable), measuringAttributeValues.IsMeasurable!.Value, storeId);
await UpdateMeasuringWeightAttributeValueAsync(measuringAttributes.Single(ma => ma.Key == NET_WEIGHT_KEY), measuringAttributeValues.NetWeight, cumulativeWeightUpdate);
await UpdateMeasuringWeightAttributeValueAsync(measuringAttributes.Single(ma => ma.Key == GROSS_WEIGHT_KEY), measuringAttributeValues.GrossWeight, cumulativeWeightUpdate);
await UpdateGenericAttributeAsync(measuringAttributes.Single(ma => ma.Key == IS_MEASURABLE_KEY), measuringAttributeValues.IsMeasurable);
//var netWeightAttribute = measuringAttributes?.SingleOrDefault(ma => ma.Key == NET_WEIGHT_KEY);
//if (netWeightAttribute != null) await UpdateMeasuringWeightAttributeValueAsync(netWeightAttribute, measuringAttributeValues.NetWeight, cumulativeWeightUpdate);
//else await InsertGenericAttributeAsync<TEntity, double>(entityId, NET_WEIGHT_KEY, measuringAttributeValues.NetWeight, storeId);
//var grossWeightAttribute = measuringAttributes?.SingleOrDefault(ma => ma.Key == GROSS_WEIGHT_KEY);
//if (grossWeightAttribute != null) await UpdateMeasuringWeightAttributeValueAsync(grossWeightAttribute, measuringAttributeValues.GrossWeight, cumulativeWeightUpdate);
//else await InsertGenericAttributeAsync<TEntity, double>(entityId, GROSS_WEIGHT_KEY, measuringAttributeValues.GrossWeight, storeId);
//var isMeasurableAttribute = measuringAttributes?.SingleOrDefault(ma => ma.Key == IS_MEASURABLE_KEY);
//if (isMeasurableAttribute != null) await UpdateGenericAttributeAsync(isMeasurableAttribute, measuringAttributeValues.IsMeasurable);
//else await InsertGenericAttributeAsync<TEntity, bool>(entityId, IS_MEASURABLE_KEY, measuringAttributeValues.IsMeasurable, storeId);
}
private async Task UpdateMeasuringWeightAttributeValueAsync(GenericAttribute genericAttribute, double newWeightValue, bool cumulativeWeightUpdate)
{
await UpdateGenericAttributeAsync(genericAttribute, cumulativeWeightUpdate ? CommonHelper.To<double>(genericAttribute.Value) + newWeightValue : newWeightValue);
await UpdateGenericAttributeAsync(genericAttribute, double.Round((cumulativeWeightUpdate ? CommonHelper.To<double>(genericAttribute.Value) + newWeightValue : newWeightValue), 1));
}
public async Task DeleteAllMeasuringAttributesAsync<TEntity>(int entityId, int storeId)
{
var measuringAttributes = await GetMeasuringAttributesAsync<TEntity>(entityId, storeId);
if (measuringAttributes.Count == 0) return;
if (measuringAttributes == null) return;
foreach (var measuringAttribute in measuringAttributes)
{