Exemplo n.º 1
0
        /// <summary>
        /// For each product
        ///     o If the product does not exists add and CopyWooDetails to new record increase Counter.added
        ///     o If product does exist and CanUpdate is true then Update by copying the WooDetaits that are not keys, increase Counter.update
        /// </summary>
        async Task <Guid> ImportAndMapWooProductData(Product currWooProd, List <WooItemWithParent> pProductsWithParents)
        {
            Guid _itemProductId = Guid.Empty;
            // Get repository for each database we are accessing. ItemProduct. WooProductMap & WooSyncLog
            IAppRepository <WooProductMap> _wooProductMapRepository = _AppUnitOfWork.Repository <WooProductMap>();

            // Import the Product and set sync data
            ///first check if it exists in the mapping, just in case there has been a name change
            WooProductMap _wooProductMap = await _wooProductMapRepository.FindFirstAsync(wp => wp.WooProductId == currWooProd.id);

            if (_wooProductMap != null)       // the id exists so update
            {
                if (_wooProductMap.CanUpdate) /// only if the product can be updated
                {
                    _itemProductId = await UpdateItemWithProduct(currWooProd, _wooProductMap, pProductsWithParents);
                }
            }
            else      // the id does not exists so add
            {
                _itemProductId = await AddProductToItems(currWooProd, pProductsWithParents);

                currImportCounters.TotalAdded++;
            }

            return(_itemProductId);
        }
Exemplo n.º 2
0
        //does not exists add and CopyWooDetails to new record increase Counter.added
        async Task <Guid> AddProductToItems(Product currWooProd, List <WooItemWithParent> pProductsWithParents)
        {
            Guid _itemId = Guid.Empty;
            IAppRepository <WooProductMap> _wooProductMapRepository = _AppUnitOfWork.Repository <WooProductMap>();

            //it may not be in the map, but we may have a product with tat name so see if we do -Add Item Product if it does not exist
            _itemId = await AddOrGetIDItem(currWooProd, pProductsWithParents);

            if (_itemId != Guid.Empty)
            {
                WooProductMap _wooProductMap = new WooProductMap
                {
                    WooProductId = (int)currWooProd.id,
                    ItemId       = _itemId,
                    CanUpdate    = true
                };
                if (await _wooProductMapRepository.AddAsync(_wooProductMap) == AppUnitOfWork.CONST_WASERROR)
                {
                    // did not add so set _ItemProductId to ItemProductID to Guid.Empty = error
                    _itemId = Guid.Empty;
                }
                currImportCounters.TotalAdded++;
            }
            return(_itemId);
        }
Exemplo n.º 3
0
        async Task <Guid> UpdateItemWithProduct(Product currWooProduct, WooProductMap currWooProductMap, List <WooItemWithParent> currWooProductsWithParents)
        {
            // We have found a mapping between the woo Product and our Product id so update the Attribute table just in case.
            Guid            _itemId         = Guid.Empty;
            Guid            _itemProductId  = Guid.Empty;
            IItemRepository _itemRepository = _AppUnitOfWork.itemRepository();
            // check if the Prod based on mapped id
            Item _item = await _itemRepository.FindFirstEagerLoadingItemAsync(i => i.ItemId == currWooProductMap.ItemId);

            /// Now update the woo Product using the _ItemProductId returned.
            if (_item != null)
            {    // we found the Item Id so update that Id
                _itemId = await UpdateItem(currWooProduct, _item, currWooProductsWithParents);

                currImportCounters.TotalUpdated++;
            }
            else
            {
                // if we got here then the product map is pointing to the wrong ID, so delete the ID and add the item
                await DeleteWooProductMap(currWooProductMap);

                _itemId = await AddProductToItems(currWooProduct, currWooProductsWithParents);
            }
            return(_itemId);
        }
Exemplo n.º 4
0
        // Get the Variety's Parent id using the WooMapping, if is not found then return Empty
        async Task <Guid> GetItemId(int currWooProductId)
        {
            IAppRepository <WooProductMap> _wooProductMapRepo = _AppUnitOfWork.Repository <WooProductMap>();

            WooProductMap _wooProductMap = await _wooProductMapRepo.FindFirstAsync(wpa => wpa.WooProductId == currWooProductId);

            return((_wooProductMap == null) ? Guid.Empty : _wooProductMap.ItemId);
        }
Exemplo n.º 5
0
        private async Task <int> DeleteWooProductMap(WooProductMap currWooProductMap)
        {
            IAppRepository <WooProductMap> _wooProductMapRepository = _AppUnitOfWork.Repository <WooProductMap>();

            return(await _wooProductMapRepository.DeleteByIdAsync(currWooProductMap.WooProductMapId));
        }