Exemple #1
0
        public static List <Category> Seed(this List <Category> list, Action <SeedOptions> options)
        {
            var r        = new Random();
            var _options = new SeedOptions();

            options(_options);
            for (int i = 1; i <= _options.ParentCount; i++)
            {
                var parentCat = new Category {
                    Name = "Parent", Parent = null, Id = i.ToString()
                };
                parentCat.DepthDefinition.MaxChildren = r.Next(3, 7);
                list.Add(parentCat);
                parentCat.SeedChildren(list, _options);
            }
            return(list);
        }
Exemple #2
0
        private static void SeedChildren(this Category parentCat, List <Category> root, SeedOptions options, int?depth = null)
        {
            var r = new Random();

            depth = (depth != null ? depth : ((parentCat.DepthDefinition != null && parentCat.DepthDefinition.Depth > 0) ? parentCat.DepthDefinition.Depth : options.DepthDefinition.Depth)) - 1;
            for (int k = 1; k <= ((parentCat.DepthDefinition != null && parentCat.DepthDefinition.MaxChildren > 0) ? parentCat.DepthDefinition.MaxChildren : options.ChildrenCount); k++)
            {
                var child = new Category(true)
                {
                    Name = $"Child", Parent = parentCat, Id = $"{parentCat.Id}_{k}"
                };
                child.DepthDefinition.MaxDepth    = r.Next(4, 8);
                child.DepthDefinition.MaxChildren = r.Next(2, 4);
                if (depth > 0)
                {
                    root.Add(child);
                    child.SeedChildren(root, options, depth);
                }
            }
        }