async Task <Guid> AddProductAttribute(ProductAttribute pPA, WooProductAttributeMap pWooAttributeMap)
        {
            Guid _ItemAttributeId = Guid.Empty;
            IAppRepository <WooProductAttributeMap> _WooAttributeMapRepository = _AppUnitOfWork.Repository <WooProductAttributeMap>();

            // Add Item Attribute if it does not exist
            _ItemAttributeId = await AddOrGetIDItemAttribute(pPA);

            if (pWooAttributeMap == null)
            {
                pWooAttributeMap = new WooProductAttributeMap
                {
                    WooProductAttributeId = (int)pPA.id,
                    ItemAttributeLookupId = _ItemAttributeId,
                    CanUpdate             = true
                };
            }
            else
            {
                pWooAttributeMap.WooProductAttributeId = (int)pPA.id;
                pWooAttributeMap.ItemAttributeLookupId = _ItemAttributeId;
            }
            // return Id if we update okay
            return((await _WooAttributeMapRepository.AddAsync(pWooAttributeMap) != AppUnitOfWork.CONST_WASERROR) ? _ItemAttributeId : Guid.Empty);      // did not updated so set _ItemAttributeId to ItemAttributeID to Guid.Empty = error== 0)
        }
        async Task <Guid> ImportAndMapAttributeData(ProductAttribute pPC)
        {
            Guid _ItemAttributeId = Guid.Empty;
            // Get repository for each database we are accessing. ItemAttribute. WooProductAttributeMap & WooSyncLog
            IAppRepository <WooProductAttributeMap> _WooAttributeMapRepository = _AppUnitOfWork.Repository <WooProductAttributeMap>();

            // Import the Attribute and set sync data
            ///first check if it exists in the mapping, just in case there has been a name change
            WooProductAttributeMap _wooAttributeMap = await _WooAttributeMapRepository.FindFirstAsync(wa => wa.WooProductAttributeId == pPC.id);

            if (_wooAttributeMap != null)   // the id exists so update
            {
                if (_wooAttributeMap.CanUpdate)
                {
                    _ItemAttributeId = await UpdateProductAttribute(pPC, _wooAttributeMap);
                }
                currImportCounters.TotalUpdated++;
            }
            else      // the id does not exists so add
            {
                _ItemAttributeId = await AddProductAttribute(pPC, _wooAttributeMap);

                currImportCounters.TotalAdded++;
            }

            return(_ItemAttributeId);
        }
        // Get the Variety's Parent id using the WooMapping, if is not found then return Empty
        private Guid GetVarietysParentAttributeID(uint?sourceParentId)
        {
            IAppRepository <WooProductAttributeMap> _wooProductAttributeMapRepo = _AppUnitOfWork.Repository <WooProductAttributeMap>();

            WooProductAttributeMap _wooProductAttributeMap = _wooProductAttributeMapRepo.FindFirst(wpa => wpa.WooProductAttributeId == sourceParentId);

            return((_wooProductAttributeMap == null) ? Guid.Empty : _wooProductAttributeMap.ItemAttributeLookupId);
        }
        async Task <Guid> UpdateProductAttribute(ProductAttribute pPA, WooProductAttributeMap pWooAttributeMap)
        {
            // we have found a mapping between the woo Product Attribute and our Attribute id so update the Attrbiute table just incase.
            Guid _ItemAttributeId = Guid.Empty;
            IAppRepository <WooProductAttributeMap> _WooProductAttributeMapRepository = _AppUnitOfWork.Repository <WooProductAttributeMap>();

            _ItemAttributeId = await AddOrUpdateItemAttribute(pPA, pWooAttributeMap.ItemAttributeLookupId);

            /// Now update the woo Attribute using the _ItemAttributeId returned.
            return((await _WooProductAttributeMapRepository.UpdateAsync(pWooAttributeMap) != AppUnitOfWork.CONST_WASERROR) ? _ItemAttributeId : Guid.Empty);      // did not updated so set _ItemAttributeId to ItemAttributeID to Guid.Empty = error
        }
        private async Task <int> GetAttributeTermParentId()
        {
            if (_WooParentAttributeId == -1)
            {
                IAppRepository <WooProductAttributeMap> _wooAttributeMapRepository = _AppUnitOfWork.Repository <WooProductAttributeMap>();
                WooProductAttributeMap wooProductAttributeMap = await _wooAttributeMapRepository.FindFirstAsync(wcm => wcm.ItemAttributeLookupId == _ParentItemAttributeLookupId);

                if (wooProductAttributeMap != null)
                {
                    _WooParentAttributeId = wooProductAttributeMap.WooProductAttributeId;
                }
                else
                {
                    _WooParentAttributeId = 0;   // to say it has been read
                }
            }
            return(_WooParentAttributeId);
        }
Beispiel #6
0
        async Task <Item> AddOrUpdateItemsAttributes(Item currItem, ProductAttributeLine prodAttrib, bool HasAttributes)
        {
            // if we get here then we have an item and it has an id
//            IAppRepository<ItemAttributeLookup> _itemAttributeLookupRepo = _AppUnitOfWork.Repository<ItemAttributeLookup>();
            IAppRepository <WooProductAttributeMap> _wooProductAttributeMapRepo = _AppUnitOfWork.Repository <WooProductAttributeMap>();
            // check if this is an update or an add for categories and attributes
            WooProductAttributeMap _wooProductAttributeMap = await _wooProductAttributeMapRepo.FindFirstAsync(wpa => wpa.WooProductAttributeId == prodAttrib.id);

            if (_wooProductAttributeMap != null)
            {
                if ((HasAttributes) && (currItem.ItemAttributes.Exists(ic => ic.ItemAttributeLookupId == _wooProductAttributeMap.ItemAttributeLookupId)))
                {
                    // this attribute exists so just update it
                    ItemAttribute _itemAttribute = currItem.ItemAttributes.Find(ic => ic.ItemAttributeLookupId == _wooProductAttributeMap.ItemAttributeLookupId);
                    _itemAttribute.IsUsedForItemVariety = prodAttrib.variation == null ? false : (bool)prodAttrib.variation;  // the only thing that we can really update
                }
                else
                {
                    if (currItem.ItemAttributes == null)
                    {
                        currItem.ItemAttributes = new List <ItemAttribute>();
                    }
                    // create a new attribute and update the ItemDetails. Do not change Item Id as then EF core knows it is a new record.
                    currItem.ItemAttributes.Add(new ItemAttribute
                    {
                        IsUsedForItemVariety  = prodAttrib.variation == null ? false : (bool)prodAttrib.variation,
                        ItemAttributeLookupId = _wooProductAttributeMap.ItemAttributeLookupId,
                    });
                }
                //if (Convert.ToBoolean(prodAttrib.variation))
                //{   --> not sure why we had this but we were only adding terms / varieties if they were used for variations, but this means attributes are left hanging.
                currItem = await AddOrUpdateVarieties(currItem, prodAttrib, _wooProductAttributeMap); //--> need to check each attribute, IsAttributeVarietyUpddate);

                //}
            }
            return(currItem);
        }
Beispiel #7
0
        /// <summary>
        /// Add or update variation of this item
        /// </summary>
        /// <param name="currItem">the item </param>
        /// <param name="prodAttrib">the attribute</param>
        /// <returns>Item modified with new data</returns>
        async Task <Item> AddOrUpdateVarieties(Item currItem, ProductAttributeLine prodAttrib, WooProductAttributeMap currWooProductAttributeMap) //, bool IsAttributeVarietyUpddate)
        {
            IAppRepository <ItemAttributeVarietyLookup> _itemAttribVarietyLookupRepo = _AppUnitOfWork.Repository <ItemAttributeVarietyLookup>();
            ItemAttributeVarietyLookup _itemAttributeVarietyLookup = null;

            foreach (var attrbiTerm in prodAttrib.options)
            {
                _itemAttributeVarietyLookup = await _itemAttribVarietyLookupRepo.FindFirstAsync(ItemAttributeVariety => ItemAttributeVariety.VarietyName == attrbiTerm);

                if (_itemAttributeVarietyLookup != null)
                {
                    // found so update or add
                    ItemAttribute _itemAttribute = currItem.ItemAttributes.Find(ic => ic.ItemAttributeLookupId == currWooProductAttributeMap.ItemAttributeLookupId);
                    if (_itemAttribute == null)
                    {
                        return(currItem); // this should never occur
                    }
                    // does this attribute have this variety, if so update otherwise add
                    if ((_itemAttribute.ItemAttributeVarieties != null) && (_itemAttribute.ItemAttributeVarieties.Exists(iav => iav.ItemAttributeVarietyLookupId == _itemAttributeVarietyLookup.ItemAttributeVarietyLookupId)))
                    {
                        // this attribute variety / term exists so just update it. Do stuff here if we need - so far nada
                        //make sure this matches
                        ItemAttributeVariety _itemAttributeVariety = _itemAttribute.ItemAttributeVarieties.FirstOrDefault(iav => iav.ItemAttributeVarietyLookupId == _itemAttributeVarietyLookup.ItemAttributeVarietyLookupId);
                        ///-> can this be null? It should never be
                        // copy the whole item across just in case there have been changes
                        _itemAttributeVariety.ItemAttributeVarietyLookupDetail = _itemAttributeVarietyLookup;
                        _itemAttributeVariety.ItemAttributeId = _itemAttribute.ItemAttributeId;
                    }
                    else
                    {
                        // we have a attribute variety, this means we should have an attribute that, that belongs too.

                        if (_itemAttribute.ItemAttributeVarieties == null)
                        {
                            _itemAttribute.ItemAttributeVarieties = new List <ItemAttributeVariety>();
                        }
                        // create a new variety assume 1.0 as in 1-1 QTY and update the ItemDetails. Do not change Item Id as then EF core knows it is a new record.
                        _itemAttribute.ItemAttributeVarieties.Add(new ItemAttributeVariety
                        {
                            ItemAttributeVarietyLookupId     = _itemAttributeVarietyLookup.ItemAttributeVarietyLookupId,
                            ItemAttributeVarietyLookupDetail = _itemAttributeVarietyLookup,    // copy the whole attribute across
                            ItemAttributeId = _itemAttribute.ItemAttributeId,
                            UoMId           = _itemAttributeVarietyLookup.UoMId,
                            UoM             = _itemAttributeVarietyLookup.UoM,
                            UoMQtyPerItem   = 1.0
                        });
                    }
                }
            }
            return(currItem);
        }