Example #1
0
        public void CleanUpInventory(Product p)
        {
            if (p == null)
            {
                return;
            }
            List <ProductInventory> allInventory = ProductInventories.FindByProductId(p.Bvin);

            if (allInventory == null)
            {
                return;
            }
            if (allInventory.Count < 1)
            {
                return;
            }

            if (p.HasVariants())
            {
                foreach (ProductInventory inv in allInventory)
                {
                    if (inv.VariantId.Trim() == string.Empty)
                    {
                        // Remove non-variant inventory levels
                        ProductInventories.Delete(inv.Bvin);
                    }

                    if (p.Variants.Where(y => y.Bvin == inv.VariantId).Count() <= 0)
                    {
                        // Remove variant inventory levels that don't apply anymore
                        ProductInventories.Delete(inv.Bvin);
                    }
                }
            }
            else
            {
                // Remove all variant inventory levels
                foreach (ProductInventory inv in allInventory)
                {
                    if (inv.VariantId.Trim() != string.Empty)
                    {
                        ProductInventories.Delete(inv.Bvin);
                    }
                }
            }
        }