public ServiceResult RemoveById(int id) { var existsProduct = _productRepository.Exists(x => x.Id == id); if (!existsProduct) { return(ServiceResult.Fail(ServiceError.EntityNotFound(nameof(Product), (nameof(Product.Id), id)))); } _productRepository.Remove(new Product { Id = id }); return(ServiceResult.Success()); }
public ServiceResult RemoveById(int id) { var categoryCheckChild = _categoryRepository.CheckChildExist(x => x.Id == id); if (categoryCheckChild == null) { return(ServiceResult.Fail(ServiceError.EntityNotFound(nameof(Category), (nameof(Category.Id), id)))); } if (categoryCheckChild.IsProductExist) { return(ServiceResult.Fail(ServiceError.ForeignKeyUsing(nameof(Category), nameof(Category.Products)))); } _categoryRepository.Remove(new Category { Id = id }); return(ServiceResult.Success()); }