private void GetDescendants(CatalogCategory catalogCategory, List <CatalogCategory> descendants)
        {
            var children = this._categories.Where(x => x.Parent == catalogCategory);

            foreach (var kid in children)
            {
                GetDescendants(kid, descendants);
            }

            descendants.Add(catalogCategory);
        }
Beispiel #2
0
        private CatalogProduct(CatalogProductId catalogProductId, ProductId productId, string displayName, CatalogCategory catalogCategory)
            : base(catalogProductId)
        {
            if (string.IsNullOrWhiteSpace(displayName))
            {
                throw new DomainException($"{nameof(displayName)} is empty.");
            }

            this.ProductId       = productId ?? throw new ArgumentNullException(nameof(productId));
            this.CatalogCategory = catalogCategory ?? throw new ArgumentNullException(nameof(catalogCategory));

            this.DisplayName = displayName;
        }
        public IEnumerable <CatalogCategory> GetDescendantsOfCatalogCategory(CatalogCategory catalogCategory)
        {
            if (catalogCategory == null)
            {
                throw new DomainException($"{nameof(catalogCategory)} is null.");
            }

            var descendants = new List <CatalogCategory>();

            this.GetDescendants(catalogCategory, descendants);

            return(descendants);
        }
        private CatalogCategory(CatalogCategoryId catalogCategoryId, CatalogId catalogId, CategoryId categoryId, string displayName, CatalogCategory parent = null)
            : base(catalogCategoryId)
        {
            this.CatalogId  = catalogId ?? throw new ArgumentNullException(nameof(catalogId));
            this.CategoryId = categoryId ?? throw new ArgumentNullException(nameof(categoryId));

            if (string.IsNullOrWhiteSpace(displayName))
            {
                throw new DomainException($"{nameof(displayName)} is empty.");
            }

            this.DisplayName = displayName;
            this.Parent      = parent;
        }
        public void RemoveCatalogCategoryWithDescendants(CatalogCategory catalogCategory)
        {
            if (catalogCategory == null)
            {
                throw new DomainException($"{nameof(catalogCategory)} is null.");
            }

            var descendants = this.GetDescendantsOfCatalogCategory(catalogCategory);

            foreach (var kid in descendants)
            {
                this._categories = this._categories.Where(x => x != kid).ToList();
            }
        }
        public CatalogCategory AddCategory(CategoryId categoryId, string displayName, CatalogCategory parentCatalogCategory = null)
        {
            if (categoryId == null)
            {
                throw new DomainException($"{nameof(categoryId)} is null");
            }

            if (this._categories.Any(x => x.Parent == parentCatalogCategory && x.CategoryId == categoryId))
            {
                throw new DomainException($"Category#{categoryId} is existing in Catalog#{this.Id}");
            }

            var catalogCategory =
                CatalogCategory.Create(this.Id, categoryId, displayName, parentCatalogCategory);

            this._categories.Add(catalogCategory);

            return(catalogCategory);
        }
Beispiel #7
0
 internal static CatalogProduct Create(ProductId productId, string displayName, CatalogCategory catalogCategory)
 => new CatalogProduct(productId, displayName, catalogCategory);
Beispiel #8
0
 private CatalogProduct(ProductId productId, string displayName, CatalogCategory catalogCategory)
     : this(CatalogProductId.New, productId, displayName, catalogCategory)
 {
 }
 internal static CatalogCategory Create(CatalogId catalogId, CategoryId categoryId, string displayName, CatalogCategory parent = null)
 => new CatalogCategory(catalogId, categoryId, displayName, parent);
 private CatalogCategory(CatalogId catalogId, CategoryId categoryId, string displayName, CatalogCategory parent = null)
     : this(CatalogCategoryId.New, catalogId, categoryId, displayName, parent)
 {
 }
 private CatalogCategory(CatalogId catalogId, CategoryId categoryId, string displayName, CatalogCategory parent = null)
     : this(IdentityFactory.Create <CatalogCategoryId>(), catalogId, categoryId, displayName, parent)
 {
 }
Beispiel #12
0
 private CatalogProduct(ProductId productId, string displayName, CatalogCategory catalogCategory)
     : this(IdentityFactory.Create <CatalogProductId>(), productId, displayName, catalogCategory)
 {
 }