public void DeleteCategory(Category category)
        {
            var childrenCategory = _unitOfWork.CategoryRepository.Find(c => c.category_parent == category.category_id);
            
            foreach (var child in childrenCategory)
            {
                child.category_parent = 0;
                _unitOfWork.CategoryRepository.Update(child);
            }

            _unitOfWork.CategoryRepository.Delete(category);
            _unitOfWork.Commit();
        }
        public void UpdateCategory(Category category)
        {
            var categorySelected = GetCategoryById(category.category_parent);

            while (categorySelected != null)
            {
                if (category.category_id == categorySelected.category_id)
                {
                    category.category_parent = 0;
                    break;
                }
                categorySelected = GetCategoryById(categorySelected.category_parent);

            }
            if (categorySelected == null)
            {
                category.category_parent = category.category_parent;
            }

            _unitOfWork.CategoryRepository.Update(category);
            _unitOfWork.Commit();
        }
        public IHttpActionResult PostCategory(Category category)
        {
            if (ModelState.IsValid)
            {
                _categoryService.InsertCategory(category);
            }
            else
            {
                return BadRequest(ModelState);
            }

            return CreatedAtRoute("DefaultApi", new { id = category.category_id }, category);
        }
 public void InsertCategory(Category category)
 {
     _unitOfWork.CategoryRepository.Insert(category);
     _unitOfWork.Commit();
 }
        public IHttpActionResult PutCategory(int id, Category categoryModel)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            if (id != categoryModel.category_id)
                return BadRequest();

            var category = _categoryService.GetCategoryById(id);
            category.category_id = categoryModel.category_id;
            category.category_name = categoryModel.category_name;
            category.category_slug = categoryModel.category_slug;
            category.category_description = categoryModel.category_description;
            category.category_parent = categoryModel.category_parent;
            category.category_active = categoryModel.category_active;

            if (categoryModel != null)
                _categoryService.UpdateCategory(category);

            return StatusCode(HttpStatusCode.NoContent);
        }