예제 #1
0
        public async Task<IResult> DeleteAsync(Category category)
        {
            var productsOfCategory = await _productDao.GetListAsync();

            bool hasDependencies = productsOfCategory.Any((product) =>
            {
                return product.CategoryId == category.Id;
            });

            if (hasDependencies)
            {
                return new SuccessResult(false, ResultMessages.CategoryNotDeleted);
            }
            await _categoryDao.DeleteAsync(category);
            return new SuccessResult(true, ResultMessages.CategoryDeleted);
        }