public async Task <DeleteProductCategoryOutput> DeleteProductCategoryAsync(DeleteProductCategoryInput input) { if (input.Id == 0) { throw new UserFriendlyException("خطا در دریافت اطلاعات"); } var pc = _productCategory.GetAll() .SingleOrDefault(p => p.Id == input.Id); if (pc == null) { throw new UserFriendlyException("آیتم مورد نظر وجود ندارد ویا حذف شده است !!!"); } if (_productRepo.GetAll().Any(p => p.ProductCategoryId == input.Id)) { throw new UserFriendlyException("برای این دسته بندی محصولی درج گردیده است !!!"); } _productCategory.Delete(pc); return(new DeleteProductCategoryOutput()); }
public void DeleteProductCategory(DeleteProductCategoryInput input) { var productcategory = _ProductCategoryRepository.Get(input.Id); productcategory.IsDeleted = true; _ProductCategoryRepository.Delete(productcategory); }
public async Task <ValidationResult> ValidateDeleteProductCategory(DeleteProductCategoryInput input) { ValidationResult validationResult = new(); var productCategory = await _repository.GetByNameAsync(input.Name); if (productCategory is null) { validationResult.Messages.Add(new(nameof(CreateProductCategoryInput.Name), "La categoria no existe.")); } return(validationResult); }
public async Task <OperationResult> DeleteAsync(DeleteProductCategoryInput input) { var validationResult = await _productCategoryValidator.ValidateDeleteProductCategory(input); if (validationResult.IsSuccess) { var entity = await _productCategoryRepository.GetByNameAsync(input.Name); await _productCategoryRepository.RemoveAsync(entity); await _productRepository.InactiveProductsByCategory(entity.Name); return(OperationResult.Success()); } return(OperationResult.Fail(validationResult)); }