async Task <int> UpdateWooCategoryMap(ItemCategoryLookupView updatedViewEntity) { int _recsUpdated = 0; WooCategoryMap updateWooCategoryMap = await GetWooMappedItemAsync(updatedViewEntity.ItemCategoryLookupId); if (updateWooCategoryMap != null) { if (updateWooCategoryMap.CanUpdate == updatedViewEntity.CanUpdateWooMap) { // not necessary to display message. // PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Warning, $"Woo Category Map for category: {pUpdatedItem.CategoryName} has not changed, so was not updated?"); } else { updateWooCategoryMap.CanUpdate = (bool)updatedViewEntity.CanUpdateWooMap; IAppRepository <WooCategoryMap> wooCategoryMapRepository = _appUnitOfWork.Repository <WooCategoryMap>(); _recsUpdated = await wooCategoryMapRepository.UpdateAsync(updateWooCategoryMap); _gridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Success, $"Category: {updatedViewEntity.CategoryName} was updated."); } } else { _gridSettings.PopUpRef.ShowNotification(PopUpAndLogNotification.NotificationType.Error, $"Woo Category Map for category: {updatedViewEntity.CategoryName} is no longer found, was it deleted?"); } return(_recsUpdated); }
async Task <Guid> ImportAndMapCategoryData(ProductCategory sourcePC, List <WooItemWithParent> sourceCategoriesWithParents) { Guid _itemCategoryLookupId = Guid.Empty; // Get repository for each database we are accessing. ItemCategoryLookup. WooProductCategoryMap & WooSyncLog IAppRepository <WooCategoryMap> _wooCategoryMapRepository = _AppUnitOfWork.Repository <WooCategoryMap>(); // Import the category and set sync data ///first check if it exists in the mapping, just in case there has been a name change WooCategoryMap _wooCategoryMap = await _wooCategoryMapRepository.FindFirstAsync(wpc => wpc.WooCategoryId == sourcePC.id); if (_wooCategoryMap != null) // the id exists so update { if (_wooCategoryMap.CanUpdate) { _itemCategoryLookupId = await UpdateProductCategory(sourcePC, _wooCategoryMap, sourceCategoriesWithParents); } currImportCounters.TotalUpdated++; } else // the id does not exists so add { _itemCategoryLookupId = await AddProductCategory(sourcePC, sourceCategoriesWithParents); currImportCounters.TotalAdded++; } return(_itemCategoryLookupId); }
/// <summary> /// Get Our Category Id using a Woo Category Id /// </summary> /// <param name="sourceWooCategoryId">The Woo Category Id</param> /// <returns></returns> async Task <Guid> GetCategoryById(int sourceWooCategoryId) { // using the category woo category mapping find the associated ID IAppRepository <WooCategoryMap> _wooCatrgoryMapRepository = _AppUnitOfWork.Repository <WooCategoryMap>(); WooCategoryMap _wooCategoryMap = await _wooCatrgoryMapRepository.FindFirstAsync(wc => wc.WooCategoryId == sourceWooCategoryId); return((_wooCategoryMap == null) ? Guid.Empty : _wooCategoryMap.ItemCategoryLookupId); }
async Task <Guid> UpdateProductCategory(ProductCategory updatedPC, WooCategoryMap targetWooCategoryMap, List <WooItemWithParent> sourceCategoriesWithParents) { Guid _itemCategoryLookupId = Guid.Empty; IAppRepository <WooCategoryMap> _wooCategoryMapRepository = _AppUnitOfWork.Repository <WooCategoryMap>(); // copy data across targetWooCategoryMap.WooCategoryName = updatedPC.name; targetWooCategoryMap.WooCategorySlug = updatedPC.slug; targetWooCategoryMap.WooCategoryParentId = (int)updatedPC.parent; _itemCategoryLookupId = await AddOrUpdateItemCategoryLookup(updatedPC, targetWooCategoryMap.ItemCategoryLookupId, sourceCategoriesWithParents); if (_itemCategoryLookupId != Guid.Empty) { /// Now update the woo categorY using the _itemCategoryLookupId returned. if (await _wooCategoryMapRepository.UpdateAsync(targetWooCategoryMap) == AppUnitOfWork.CONST_WASERROR) { // did not updated so set _itemCategoryLookupId to ItemCategoryLookupID to Guid.Empty = error _itemCategoryLookupId = Guid.Empty; } } return(_itemCategoryLookupId); }
async Task <Guid> AddProductCategory(ProductCategory newPC, List <WooItemWithParent> newCategoriesWithParents) { Guid _itemCategoryLookupId = Guid.Empty; IAppRepository <WooCategoryMap> _wooCategoryMapRepository = _AppUnitOfWork.Repository <WooCategoryMap>(); // Add Item Category if it does not exist _itemCategoryLookupId = await AddOrGetIDItemCategoryLookup(newPC, newCategoriesWithParents); if (_itemCategoryLookupId != Guid.Empty) { WooCategoryMap _wooCategoryMap = new WooCategoryMap { WooCategoryName = newPC.name, WooCategorySlug = newPC.slug, WooCategoryParentId = (int)newPC.parent, ItemCategoryLookupId = _itemCategoryLookupId, WooCategoryId = (int)newPC.id, CanUpdate = true }; //else was check if woomap was null //{ // _wooCategoryMap.WooCategoryName = pPC.name; // _wooCategoryMap.WooCategorySlug = pPC.slug; // _wooCategoryMap.WooCategoryParentId = pPC.parent; // _wooCategoryMap.ItemCategoryLookupId = _itemCategoryLookupId; // _wooCategoryMap.WooCategoryId = (int)pPC.id; //} if (await _wooCategoryMapRepository.AddAsync(_wooCategoryMap) == AppUnitOfWork.CONST_WASERROR) { // did not add so set _itemCategoryLookupId to ItemCategoryLookupID to Guid.Empty = error _itemCategoryLookupId = Guid.Empty; } } return(_itemCategoryLookupId); }