Esempio n. 1
0
        private void GetChildren(ref Dictionary <string, object> node, string mainProd)
        {
            var items = structureRepository.ListByLevel(Convert.ToInt32(node["LVL"]) + 1, mainProd);

            if (items.Count() > 0)
            {
                foreach (var item in items)
                {
                    var seqArray = item.SEQ_NO.Split('.');
                    var seqNo    = seqArray[seqArray.Length - 1];
                    if (seqArray.Length == 1)
                    {
                        var itemDictionary = new Dictionary <string, object>()
                        {
                            { "LVL", item.LVL },
                            { "SEQ_NO", item.SEQ_NO },
                            { "ARTIKELCODE", item.ITEMREQ },
                            { "NL_DESCR", item.ITEMREQ_DESC },
                            { "EN_DESCR", item.EN_ITEMREQ_DESC },
                            { "DE_DESCR", item.DE_ITEMREQ_DESC },
                            { "FR_DESCR", item.FR_ITEMREQ_DESC },
                            { "QTY", item.QTY_PER_MAINPROD },
                        };

                        node.Add(seqNo, itemDictionary);
                        GetChildren(ref itemDictionary, mainProd);
                    }
                    else
                    {
                        var prevSeq = item.SEQ_NO.Substring(0, 3 + 4 * (item.LVL - 2));
                        if (prevSeq == (string)node["SEQ_NO"])
                        {
                            var itemDictionary = new Dictionary <string, object>()
                            {
                                { "LVL", item.LVL },
                                { "SEQ_NO", item.SEQ_NO },
                                { "ARTIKELCODE", item.ITEMREQ },
                                { "NL_DESCR", item.ITEMREQ_DESC },
                                { "EN_DESCR", item.EN_ITEMREQ_DESC },
                                { "DE_DESCR", item.DE_ITEMREQ_DESC },
                                { "FR_DESCR", item.FR_ITEMREQ_DESC },
                                { "QTY", item.QTY_PER_MAINPROD },
                            };

                            node.Add(seqNo, itemDictionary);
                            GetChildren(ref itemDictionary, mainProd);
                        }
                    }
                }
            }
            else
            {
                if (Convert.ToInt32(node["LVL"]) == 0)
                {
                    var product = productRepository.GetById(mainProd);

                    var itemDictionary = new Dictionary <string, object>()
                    {
                        { "LVL", "0" },
                        { "SEQ_NO", "001" },
                        { "ARTIKELCODE", mainProd },
                        { "NL_DESCR", product.NL },
                        { "EN_DESCR", product.EN },
                        { "DE_DESCR", product.DE },
                        { "FR_DESCR", product.FR },
                        { "QTY", 1 },
                    };
                    node.Add("001", itemDictionary);
                }
            }
        }