private void GetAllChildren(Guid id, ICollection <ProductCategory> categoriesList)
        {
            ProductCategory category = _context.Set <ProductCategory>().Find(id);

            categoriesList.Add(category);

            foreach (ProductCategory child in category.AllChildren())
            {
                GetAllChildren(id, categoriesList);
            }
        }
        public List <ProductCategory> GetAllChildren(string id)
        {
            List <ProductCategory>        list           = new List <ProductCategory>();
            ProductCategory               parentCategory = _context.Set <ProductCategory>().Find(new Guid(id));
            IEnumerable <ProductCategory> childCategory;

            if (parentCategory != null)
            {
                list.Add(parentCategory);
                List <string> listId = new List <string>();
                listId.Add(id);
                while ((childCategory = FindByParentId(listId)).Count() != 0)
                {
                    list.AddRange(childCategory);
                    listId = childCategory.Select(x => x.ProductCategoryId.ToString()).ToList();
                }
                return(list);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
 public ServiceBase(IRepositoryContextBase repositoryContext, IEntityMapperBase <TEntity, TDTO> entityMapper)
 {
     _repository   = repositoryContext.Set <TEntity>();
     _entityMapper = entityMapper;
 }