Пример #1
0
        public Category CategoryCreateTest()
        {
            var category = new Category {
                Name = "Category1",
                Description = "Description1",
                Parent = null
            };

            Repository.Data.Save(category);
            Assert.True(category.Id != Guid.Empty);
            return category;
        }
Пример #2
0
        public static CategoryModel Copy(this CategoryModel categoryModel, Category category )
        {
            categoryModel.Id = category.Id;
            categoryModel.Name = category.Name;
            categoryModel.Description = category.Description;
            categoryModel.HasImage = category.HasImage;

            if(category.Parent != null)
            {
                categoryModel.Parent = new CategoryModel();
                categoryModel.Parent.Copy(category.Parent);
            }
            else
            {
                categoryModel.Parent = null;
            }

            return categoryModel;
        }
Пример #3
0
        public void CreateCategory( String CategoryDropDown, string Id )
        {
            var category = new Category { Parent = null };

            Guid parentId;
            if(Guid.TryParse(CategoryDropDown, out parentId))
            {
                var parentCategory = Repository.Data.Get<Category>(parentId);
                category.Parent = parentCategory;
            }

            Guid editedId;
            if (Guid.TryParse(Id, out editedId))
            {
                category = Repository.Data.Get<Category>(editedId);
            }

            if (TryUpdateModel (category))
            {
                Repository.Data.Save(category);
            }

            ProductModelService.Service.ClearSearchCriteria();
        }
Пример #4
0
        private List<Category> GetAllCategoryRecursively(Category category)
        {
            var combinedCategories =  new List<Category>{category};

            try
            {
                var childVategories = Repository.Data.Get<Category>().Where(x => x.Parent != null && x.Parent.Id == category.Id).All();

                if (!childVategories.Any())
                    return new List<Category> { category };

                foreach (var child in childVategories)
                {
                    combinedCategories.AddRange(GetAllCategoryRecursively(child));
                }
            }
            catch(Exception ex)
            {
                ILog log = LogManager.GetLogger(typeof(ActionHelper));
                log.Error(ex);
            }

            return combinedCategories;
        }
Пример #5
0
        private bool ChildExist( Category category )
        {
            IEnumerable<Category> categories =
                Repository.Data.Get<Category>().Where(x => x.Parent.Id == category.Id).All();

            return categories.Count() > 0;
        }