private async Task <ProductCategory> AddItemToWooOnlySync(ItemCategoryLookup addEntity) { IWooProductCategory _wooProductCategoryRepository = await GetIWooProductCategory(); if (_wooProductCategoryRepository == null) { return(null); } ProductCategory _wooProductCategory = new ProductCategory { name = addEntity.CategoryName, description = addEntity.CategoryName }; if ((addEntity.ParentCategoryId != null) && (addEntity.ParentCategoryId != Guid.Empty)) { WooCategoryMap _WooParentCategoryMap = await GetWooCategoryMapFromID(addEntity.ParentCategoryId); // if they have a parent get the mapped id if (_WooParentCategoryMap != null) { _wooProductCategory.parent = (uint)_WooParentCategoryMap.WooCategoryId; } } return(await _wooProductCategoryRepository.AddProductCategoryAsync(_wooProductCategory)); // should return a new version with ID }
private async Task <int> DeleteWooCategory(WooCategoryMap deleteWooCategoryMap) { int _result = AppUnitOfWork.CONST_WASERROR; // if all goes well this will be change to the number of records returned IWooProductCategory _WooProductCategoryRepository = await GetIWooProductCategory(); if (_WooProductCategoryRepository != null) { ProductCategory _tempWooCat = await _WooProductCategoryRepository.DeleteProductCategoryByIdAsync(deleteWooCategoryMap.WooCategoryId); _result = (_tempWooCat == null) ? AppUnitOfWork.CONST_WASERROR : Convert.ToInt32(_tempWooCat.id); // return the id } return(_result); }
//private async Task<ProductCategory> GetWooProductCategoryByName(string categoryName) //{ // IWooProductCategory _WooProductCategoryRepository = await GetIWooProductCategory(); // if (_WooProductCategoryRepository == null) // return null; // return _WooProductCategoryRepository.FindProductCategoryByName(categoryName); //} public override async Task <int> UpdateWooItemAsync(ItemCategoryLookupView updateViewEntity) { int _result = 0; /// null or not found if ((updateViewEntity.HasWooCategoryMap) && ((bool)(updateViewEntity.CanUpdateWooMap))) { IWooProductCategory _wooProductCategoryRepository = await GetIWooProductCategory(); if (_wooProductCategoryRepository != null) // - > if it does not exist then what? { WooCategoryMap _updateWooMapEntity = await GetWooCategoryMapFromID(updateViewEntity.ItemCategoryLookupId); if (_updateWooMapEntity == null) { // need to add the category -> this is done later. } else { ProductCategory _wooProductCategory = await _wooProductCategoryRepository.GetProductCategoryByIdAsync(_updateWooMapEntity.WooCategoryId); if (_wooProductCategory == null) { return(AppUnitOfWork.CONST_WASERROR); /// oops what happened >? } else { // get id of parent WooCategoryMap _ParentWooCategoryMap = await GetWooCategoryMapFromID(updateViewEntity.ParentCategoryId); int _newParentId = (_ParentWooCategoryMap == null) ? 0 : _ParentWooCategoryMap.WooCategoryId; if ((!_wooProductCategory.name.Equals(updateViewEntity.CategoryName)) || ((_wooProductCategory.parent ?? 0) != _newParentId)) { _wooProductCategory.name = updateViewEntity.CategoryName; // only update if necessary _wooProductCategory.parent = (uint)_newParentId; var _res = ((await _wooProductCategoryRepository.UpdateProductCategoryAsync(_wooProductCategory))); _result = ((_res == null) || (_res.id == null)) ? AppUnitOfWork.CONST_WASERROR : (int)_res.id; // if null there is an issue } } } } } return(_result); }