void ExecuteBulkInsert(List <MaestroProduct> plist)
        {
            UnitTypeManager um = new UnitTypeManager(context);
            MaestroUnitType unknownUnitType = um.GetUnknownItem();

            List <MaestroProduct> updatedProducts = new List <MaestroProduct>();

            foreach (MaestroProduct product in plist)
            {
                MaestroProduct existing = ProductCache.Instance.GetByQbId(product.QuickBooksProductId);
                if (existing != null)
                {
                    product.Id           = existing.Id;
                    product.UnitType     = existing.UnitType;
                    product.ProductGroup = existing.ProductGroup;
                    pm.Update(product);
                    updatedProducts.Add(existing);
                }
                else
                {
                    product.UnitType = unknownUnitType;
                }
            }

            List <ITransactionEntity> clist = plist.Where(q => !updatedProducts.Select(u => u.QuickBooksProductId).Contains(q.QuickBooksProductId)).Cast <ITransactionEntity>().ToList();

            if (clist.Count > 0)
            {
                pm.BulkInsert(clist);
            }

            if (updatedProducts.Count > 0)
            {
                updatedProducts.ForEach(p => pm.Update(p));
            }

            if (clist.Count > 0 || updatedProducts.Count > 0)
            {
                ProductCache.Instance.Reload(true);
            }
        }
        public override List <ITransactionEntity> Import()
        {
            StartSession();

            IMsgSetRequest         request = GetLatestMsgSetRequest();
            IItemNonInventoryQuery query   = request.AppendItemNonInventoryQueryRq();

            query.ORListQueryWithOwnerIDAndClass.ListWithClassFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
            //IItemQuery query = request.AppendItemQueryRq();
            IResponse res = GetResponse(request);

            //IORItemRetList returnList = res.Detail as IORItemRetList;
            IItemNonInventoryRetList returnList = res.Detail as IItemNonInventoryRetList;

            List <MaestroProduct> plist = new List <MaestroProduct>();

            List <IItemNonInventoryRet> mapSourceList = new List <IItemNonInventoryRet>();

            MaestroUnitType unknowUnitType = new UnitTypeManager(context).GetUnknownItem();


            int cnt = returnList.Count;

            for (int i = 0; i <= cnt - 1; i++)
            {
                IItemNonInventoryRet inv = returnList.GetAt(i);
                if (inv != null)
                {
                    string parentId = string.Empty;
                    if (inv.ParentRef != null)
                    {
                        parentId = ReadQbId(inv.ParentRef.ListID);
                    }

                    if (string.IsNullOrEmpty(parentId))
                    {
                        MaestroProduct product = GetMaestroProduct(inv);
                        plist.Add(product);
                    }

                    mapSourceList.Add(inv);//for late processing

                    /*
                     * if (ReadBool(inv.IsActive))
                     * {
                     *  string parentId = string.Empty;
                     *  if (inv.ParentRef != null)
                     *      parentId = ReadQbId(inv.ParentRef.ListID);
                     *
                     *  if (string.IsNullOrEmpty(parentId))
                     *  {
                     *      MaestroProduct product = GetMaestroProduct(inv);
                     *      plist.Add(product);
                     *  }
                     *
                     *  mapSourceList.Add(inv);//for late processing
                     * }
                     */
                    /*
                     * else
                     * {
                     *  string parentId = string.Empty;
                     *  if (inv.ParentRef != null)
                     *      parentId = ReadQbId(inv.ParentRef.ListID);
                     *
                     *  if (string.IsNullOrEmpty(parentId))
                     *  {
                     *      MaestroProduct product = GetMaestroProduct(inv);
                     *      //plist.Add(product);
                     *
                     *  }
                     *
                     *
                     *
                     *
                     * }*/
                }

                #region commented
                //WalkItemNonInventoryRet(inv);

                //IORItemRet qbc = returnList.GetAt(i);

                /*
                 * if (qbc.ItemNonInventoryRet != null)
                 * {
                 *  WalkItemNonInventoryRet(qbc.ItemNonInventoryRet);
                 *  //GetMaestroProduct(qbc.ItemNonInventoryRet);
                 * }*/
                #endregion commented
            }

            ExecuteBulkInsert(plist);
            ImportMaps(mapSourceList, plist);
            QuickBooksProductMapCache.Instance.Reload(true);

            return(plist.Cast <ITransactionEntity>().ToList());
        }