public static IEnumerable<HierarchyNode<ProductViewer>> GetConsolidatedProductForTreeview(ConsolidatedProduct consolidatedProduct, decimal qty)
        {
            var fp = consolidatedProduct.GetFlattenedProducts();
            ProductViewer pv = new ProductViewer
            {
                ProductId = consolidatedProduct.Id,
                ParentProductId = Guid.Empty,
                Description = consolidatedProduct.Description,
                TotalItems = 1 * qty,
                ProdType = "C",
                Level = 0,
                QtyPerConsolidatedProduct = 1
            };
            List<ProductViewer> pvs = fp.Select(n => new ProductViewer
            {
                ProductId = n.ProductId,
                ParentProductId = n.DirectParentId,
                Description = n.Description,
                Level = n.Level,
                ProdType = n.ProductDetailType.ToString(),
                TotalItems = n.TotalProductsForHomeConsolidatedProduct * qty,
                QtyPerConsolidatedProduct = n.QuantityPerConsolidatedProduct
            })
            .ToList();

            pvs.Add(pv);

            return pvs.AsHierarchy(n => n.ProductId, n => n.ParentProductId);
            
        }
Beispiel #2
0
 public ConsolidatedProduct CreateConsolidatedProduct(Guid Id, Product product, int quantity)
 {
     if (Id == Guid.Empty)
         throw new ArgumentException("Invalid ID");
     ConsolidatedProduct p = new ConsolidatedProduct(Id);
     p.ProductDetails.Add(new ConsolidatedProduct.ProductDetail {Product = product, QuantityPerConsolidatedProduct = quantity });
     return p;
 }
        private List<FlattenedProductDetail> _GetFlattenedProducts(ConsolidatedProduct homeConsolidatedProduct, int level, int noParentItems)
        {
            int _level = level + 1;
            List<FlattenedProductDetail> flattenedProducts = new List<FlattenedProductDetail>();
            foreach (var product in ProductDetails)
            {
               
                if (product.Product == null)
                    continue;

                int qty = product.QuantityPerConsolidatedProduct;
                if (product.ProductDetailType != DomainProductType.Consolidated)
                {
                    flattenedProducts.Add(new FlattenedProductDetail
                    {
                        Product = product.Product,
                        QuantityPerConsolidatedProduct = qty,
                        DirectParent = this,
                        HomeConsolidatedProduct = homeConsolidatedProduct,
                        TotalProductsForHomeConsolidatedProduct = qty * noParentItems,
                        Level = _level
                    });
                }
                else
                {
                    ConsolidatedProduct cp = product.Product as ConsolidatedProduct;
                    var fp1 = new FlattenedProductDetail
                        {
                            Product = cp,
                            QuantityPerConsolidatedProduct = qty,
                            DirectParent = this,
                            HomeConsolidatedProduct = homeConsolidatedProduct,
                            TotalProductsForHomeConsolidatedProduct = qty * noParentItems,
                            Level = _level
                        };
                    flattenedProducts.Add(fp1);

                    foreach (FlattenedProductDetail fpd in cp._GetFlattenedProducts(homeConsolidatedProduct, _level, 
                        fp1.TotalProductsForHomeConsolidatedProduct))
                    {
                        flattenedProducts.Add(fpd);
                    }
                }
            }

            return flattenedProducts;
        }
 public bool CanAddProductToConsolidatedProduct(Product productToAdd, ConsolidatedProduct productToAddTo)
 {
     bool isOkToAdd = true;
     foreach (var p in ProductDetails)
     {
         if (p.Product.Id == productToAdd.Id)
             isOkToAdd = false;
         if (p.Product is ConsolidatedProduct)
         {
             ConsolidatedProduct cp = p.Product as ConsolidatedProduct;
             isOkToAdd = cp.CanAddProductToConsolidatedProduct(productToAdd, productToAddTo);
         }
     }
     //cn : avoid adding itself
     if (productToAdd.Id == productToAddTo.Id)
         isOkToAdd = false;
     return isOkToAdd;
 }