| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using Comal.Classes;
- using InABox.Core;
- namespace Comal.Stores
- {
- public class ProductStore : BaseProductStore<Product>
- {
- protected override void AfterSave(Product entity)
- {
- base.AfterSave(entity);
- if (entity.HasOriginalValue("NettCost"))
- UpdateProductComponentCost(entity);
-
- if (entity.UnitOfMeasure.HasOriginalValue(nameof(ProductDimensionUnitLink.ID)))
- UpdateProductUOMs(entity);
- }
- private static List<Type>? _stockentitytypes = null;
-
- private void UpdateProductUOMs(Product entity)
- {
- // If this is a new Product (ie original value is Guid.Empty)
- if (entity.GetOriginalValue(x => x.ID, entity.ID) == Guid.Empty)
- return;
-
- _stockentitytypes ??= CoreUtils.TypeList(x => x.IsSubclassOf(typeof(StockEntity)));
- var _uom = Provider.Query(new Filter<ProductDimensionUnit>(x => x.ID).IsEqualTo(entity.UnitOfMeasure.ID))
- .ToObjects<ProductDimensionUnit>().FirstOrDefault() ?? new ProductDimensionUnit();
- //List<Task> _tasks = new List<Task>();
- foreach (var _stockentitytype in _stockentitytypes)
- {
- //var _task = Task.Run(() =>
- //{
- var _children = Provider.Query(
- _stockentitytype,
- new Filter<StockEntity>(x => x.Product.ID).IsEqualTo(entity.ID),
- Columns.None<StockEntity>()
- .Add(x => x.ID)
- .AddSubColumns(x => x.Dimensions, null)
- ).ToObjects(_stockentitytype).OfType<StockEntity>().ToArray();
- foreach (var _child in _children)
- _child.Dimensions.Unit.CopyFrom(_uom);
- var _updates = _children.Where(x => x.IsChanged()).ToArray();
- if (_updates.Any())
- Provider.Save(_stockentitytype,_updates);
- //});
- //_tasks.Add(_task);
- }
- //Task.WaitAll(_queries.ToArray());
- }
- protected override void AfterDelete(Product entity)
- {
- base.AfterDelete(entity);
- UpdateProductComponentCost(entity);
- }
- }
- }
|