public async Task <ActionResultResponse> Delete(string tenantId, int productCategoryId) { var productCategoryInfo = await _productCategoryRepository.GetInfo(productCategoryId); if (productCategoryInfo == null) { return(new ActionResultResponse(-1, _productResourceService.GetString("Product category does not exists. Please try again."))); } if (productCategoryInfo.TenantId != tenantId) { return(new ActionResultResponse(-2, _sharedResourceService.GetString(ErrorMessage.NotHavePermission))); } // Check is has child. var productCategoryChildCount = await _productCategoryRepository.GetChildCount(productCategoryInfo.Id); if (productCategoryChildCount > 0) { return(new ActionResultResponse(-3, _productResourceService.GetString("This Product category has children product category. You can not delete this Product category."))); } // Check is has product. var isExistsProduct = await _productsCategorieRepository.CheckCategoryHasProduct(productCategoryId); if (isExistsProduct) { return(new ActionResultResponse(-4, _productResourceService.GetString("This Product category has product. You can not delete this Product category."))); } //Check in ProductsCategories -- if exists return message var result = await _productCategoryRepository.Delete(productCategoryInfo.Id); if (result > 0 && productCategoryInfo.ParentId.HasValue) { //Update parent product category child count. var childCount = await _productCategoryRepository.GetChildCount(productCategoryInfo.ParentId.Value); await _productCategoryRepository.UpdateChildCount(productCategoryInfo.ParentId.Value, childCount); } var childTrans = await _productCategoryTranslationRepository.GetAllByProductCategoryId(productCategoryInfo.Id); foreach (ProductCategoryTranslation childTran in childTrans) { childTran.IsDelete = productCategoryInfo.IsDelete; await _productCategoryTranslationRepository.Update(childTran); } return(new ActionResultResponse(result, result > 0 ? _productResourceService.GetString("Delete product category successful.") : _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong))); }
public bool Update(ProductCategoryTranslation productCategoryTranslation) { return(_productCategoryTranslationRepository.Update(productCategoryTranslation)); }