Пример #1
0
        public ServiceResult Update(Product product)
        {
            var existsCategory = _categoryRepository.Exists(x => x.Id == product.CategoryId);

            if (!existsCategory)
            {
                return(ServiceResult.Fail(ServiceError.ForeignKeyNotFound(nameof(Product.CategoryId))));
            }

            _productRepository.Update(product);
            return(ServiceResult.Success());
        }
Пример #2
0
        public ServiceResult Add(Product product)
        {
            var isCategoryExist = _categoryRepository.Exists(x => x.Id == product.CategoryId);

            if (!isCategoryExist)
            {
                return(ServiceResult.Fail(ServiceError.ForeignKeyNotFound(nameof(Product.CategoryId))));
            }

            product.Id = default;
            _productRepository.Add(product);
            return(ServiceResult.Success());
        }