Courses.Buisness.CategoryService.Delete C# (CSharp) Method

Delete() public method

Удаление категории
public Delete ( CategoryViewModel categoryView ) : void
categoryView CategoryViewModel
return void
        public void Delete(CategoryViewModel categoryView)
        {
            Category categoryForDelete = categoryRepository.Get(categoryView.Id);
            IEnumerable<Category> childCategory = categoryRepository.Get(1, categoryRepository.Count(m => true), m => m.ParentCategoryId == categoryView.Id);
            foreach (Category c in childCategory)
            {
                c.ParentCategory = categoryForDelete.ParentCategory;
                c.ParentCategoryId = categoryForDelete.ParentCategoryId;
                categoryRepository.Update(c);
            }

            categoryRepository.Delete(categoryForDelete);
        }

Usage Example

Ejemplo n.º 1
0
 public void DeleteTest()
 {
     ICategoryService _categoryService = new CategoryService(new CategoryRepository(), new CategoryFilterFactory());
     CategoryViewModel _categoryViewModel = GetCategoryViewModel();
     _categoryService.Add(_categoryViewModel);
     _categoryService.Delete(_categoryViewModel);
     Assert.IsNull(_categoryService.GetByID(1));
 }