/// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = true;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var itemsSku = await _repository.ProductsSKUReal.GetSkuForFiles(cancellationToken, MAX_ELEMENTS_IN_QUEUE);

            //var items = _mapper.Map<IEnumerable<Usr_Stimpr>, IEnumerable<SKUFileDTO>>(await _repository.SKUFiles.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            if (!itemsSku.Any())
            {
                return(false);
            }

            foreach (var itemSku in itemsSku)
            {
                succesOperation = true;
                await _SKUFilesClient.DeleteAllSkuAsync(itemSku.Usr_Stmpdh_IdSKUvtex, cancellationToken);

                var itemsFiles = _mapper.Map <IEnumerable <Usr_Stimpr>, IEnumerable <SKUFileDTO> >(await _repository.SKUFiles.GetForVTEX(cancellationToken, itemSku.Usr_Stmpdh_IdSKUvtex));

                foreach (var item in itemsFiles)
                {
                    item.Url = $"{Configuration["VTEX:ImagesBasePath"]}/{item.Url}.jpg";

                    succesOperationWithNewID = await _SKUFilesClient.PostFileWithNewIDAsync(item, item.SKUId, cancellationToken);

                    if (!succesOperationWithNewID.Success)
                    {
                        succesOperation = false;
                    }
                }

                if (succesOperation)
                {
                    Stmpdh_Real SkuReal = await _repository.ProductsSKUReal
                                          .Get(cancellationToken, new object[] { itemSku.Stmpdh_Tippro.Trim(),
                                                                                 itemSku.Stmpdh_Artcod.Trim() });

                    if (succesOperationWithNewID.Success)
                    {
                        SkuReal.Usr_Vtex_Imgtra = "S";
                    }

                    await _repository.Complete();
                }
            }
            return(itemsSku.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var departmentSpecification  = _mapper.Map <IEnumerable <Usr_Sttcaa>, IEnumerable <SpecificationDTO> >(await _repository.DepartmentsSpecifications.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));
            var categorySpecification    = _mapper.Map <IEnumerable <Usr_Sttcax>, IEnumerable <SpecificationDTO> >(await _repository.CategorySpecifications.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));
            var subcategorySpecification = _mapper.Map <IEnumerable <Usr_Sttcay>, IEnumerable <SpecificationDTO> >(await _repository.SubcategorySpecifications.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            IEnumerable <SpecificationDTO> items = departmentSpecification.Concat(categorySpecification).Concat(subcategorySpecification).OrderBy(c => c.Sfl_LoginDateTime).Take(MAX_ELEMENTS_IN_QUEUE);

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);

                    break;

                case "UPDATE":
                    if (item.Id == 0)     //Quiere decir que no se dio de alta en vtex aun
                    {
                        succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);
                    }
                    else
                    {
                        succesOperation = await _client.PutAsync(item, item.Id.ToString(), cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    switch (item.Usr_St_Oalias)
                    {
                    case "USR_STTCAA":
                        Usr_Sttcaa DepartmentSpecificationTransfered = await _repository.DepartmentsSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        Usr_Sttcaa_Real DepartmentSpecificationReal = await _repository.DepartmentsSpecificationsReal
                                                                      .Get(cancellationToken, new object[] { DepartmentSpecificationTransfered.Usr_Sttcaa_Deptos.Trim(),
                                                                                                             DepartmentSpecificationTransfered.Usr_Sttcaa_Nombre.Trim() });

                        DepartmentSpecificationTransfered.Usr_Vtex_Transf = "S";
                        if (succesOperationWithNewID.Success)
                        {
                            DepartmentSpecificationReal.Usr_Sttcaa_Idvtex = succesOperationWithNewID.NewId;
                        }
                        await _repository.Complete();

                        break;

                    case "USR_STTCAX":
                        Usr_Sttcax CategorySpecificationTransfered = await _repository.CategorySpecifications.Get(cancellationToken, new object[] { item.RowId });

                        Usr_Sttcax_Real CategorySpecificationReal = await _repository.CategorySpecificationsReal
                                                                    .Get(cancellationToken, new object[] { CategorySpecificationTransfered.Usr_Sttcax_Deptos,
                                                                                                           CategorySpecificationTransfered.Usr_Sttcax_Catego,
                                                                                                           CategorySpecificationTransfered.Usr_Sttcax_Nombre });;
                        CategorySpecificationTransfered.Usr_Vtex_Transf = "S";
                        if (succesOperationWithNewID.Success)
                        {
                            CategorySpecificationReal.Usr_Sttcax_Idvtex = succesOperationWithNewID.NewId;
                        }
                        await _repository.Complete();

                        break;

                    case "USR_STTCAY":
                        Usr_Sttcay SubcategorySpecificationTransfered = await _repository.SubcategorySpecifications.Get(cancellationToken, new object[] { item.RowId });

                        Usr_Sttcay_Real SubcategorySpecificationReal = await _repository.SubcategorySpecificationsReal
                                                                       .Get(cancellationToken, new object[] { SubcategorySpecificationTransfered.Usr_Sttcay_Deptos,
                                                                                                              SubcategorySpecificationTransfered.Usr_Sttcay_Catego,
                                                                                                              SubcategorySpecificationTransfered.Usr_Sttcay_Subcat,
                                                                                                              SubcategorySpecificationTransfered.Usr_Sttcay_Nombre });

                        SubcategorySpecificationTransfered.Usr_Vtex_Transf = "S";
                        if (succesOperationWithNewID.Success)
                        {
                            SubcategorySpecificationReal.Usr_Sttcay_Idvtex = succesOperationWithNewID.NewId;
                        }
                        await _repository.Complete();

                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
                else
                {
                    switch (item.Usr_St_Oalias)
                    {
                    case "USR_STTCAA":
                        Usr_Sttcaa departmentSpecificationTransfered = await _repository.DepartmentsSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        departmentSpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_STTCAX":
                        Usr_Sttcax categorySpecificationTransfered = await _repository.CategorySpecifications.Get(cancellationToken, new object[] { item.RowId });

                        categorySpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_STTCAY":
                        Usr_Sttcay subcategorySpecificationTransfered = await _repository.SubcategorySpecifications.Get(cancellationToken, new object[] { item.RowId });

                        subcategorySpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    default:
                        break;
                    }

                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
Exemplo n.º 3
0
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var items = _mapper.Map <IEnumerable <Usr_Pratri>, IEnumerable <SKUSpecificationDTO> >(await _repository.ProductsAndSKUSpecifications.GetSKUSpecificationForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _SKUspecificationsClient.PostSKUSpecificationWithNewIDAsync(item, item.SKUId, cancellationToken);

                    break;

                case "UPDATE":
                    succesOperation = await _SKUspecificationsClient.PutSKUSpecificationAsync(item, item.SKUId.ToString(), cancellationToken);

                    break;

                case "DELETE":
                    if (item.Id != 0)
                    {
                        succesOperation = await _SKUspecificationsClient.DeleteSpecificationAsync(item, item.SKUId, item.Id, cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                    Usr_Pratri_Real productSpecificationReal = await _repository.ProductsAndSKUSpecificationsReal
                                                               .Get(cancellationToken, new object[] { productSpecificationTransfered.Usr_Pratri_Tippro.Trim(),
                                                                                                      productSpecificationTransfered.Usr_Pratri_Artcod.Trim(),
                                                                                                      productSpecificationTransfered.Usr_Pratri_Orden });


                    productSpecificationTransfered.Usr_Vtex_Transf = "S";
                    if (succesOperationWithNewID.Success)
                    {
                        productSpecificationReal.Usr_Pratri_Idvtex       = succesOperationWithNewID.NewId;
                        productSpecificationTransfered.Usr_Pratri_Idvtex = succesOperationWithNewID.NewId;
                    }

                    await _repository.Complete();
                }
                else
                {
                    Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                    productSpecificationTransfered.Usr_Vtex_Transf = "E";

                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
Exemplo n.º 4
0
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            IEnumerable <SkuDTO> items = _mapper.Map <IEnumerable <Stmpdh>, IEnumerable <SkuDTO> >(await _repository.ProductsSKU.GetSKUForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);

                    break;

                case "UPDATE":
                    if (item.Id == 0)     //Quiere decir que no se dio de alta en vtex aun
                    {
                        succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);
                    }
                    else
                    {
                        succesOperation = await _client.PutAsync(item, item.Id.ToString(), cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    if (item.RowId == 0) //Activacion de SKU
                    {
                        Stmpdh_Real SKUReal = await _repository.ProductsSKUReal
                                              .Get(cancellationToken, new object[] { item.RefId.Substring(0, 3),
                                                                                     item.RefId.Substring(3, 9) });


                        SKUReal.Usr_Vtex_Isacti = "S";
                    }
                    else
                    {
                        //21/10/2021: Se deja de usar tabla de log para transferir productos
                        //Stmpdh SKUTransfered = await _repository.ProductsSKU.Get(cancellationToken, new object[] { item.RowId });
                        Stmpdh_Real SKUReal = await _repository.ProductsSKUReal
                                              .Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(),
                                                                                     item.Stmpdh_Artcod.Trim() });

                        SKUReal.Usr_Vtex_Skutra = "S";

                        if (succesOperationWithNewID.Success)
                        {
                            SKUReal.Usr_Stmpdh_IdSKUvtex = succesOperationWithNewID.NewId;
                        }
                    }

                    await _repository.Complete();
                }
                else
                {
                    if (item.RowId != 0)
                    {
                        Stmpdh_Real Sku = await _repository.ProductsSKUReal.Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(),
                                                                                                                  item.Stmpdh_Artcod.Trim() });

                        Sku.Usr_Vtex_Skutra = "E";
                        await _repository.Complete();
                    }
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
Exemplo n.º 5
0
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var productsFather = _mapper.Map <IEnumerable <Usr_Stmpph>, IEnumerable <ProductDTO> >(await _repository.ProductsFather.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));
            var productsSKUA   = await _repository.ProductsSKU.GetProductForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE);

            var productsSKU = _mapper.Map <IEnumerable <Stmpdh>, IEnumerable <ProductDTO> >(await _repository.ProductsSKU.GetProductForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            IEnumerable <ProductDTO> items = productsFather.Concat(productsSKU).OrderBy(c => c.Sfl_LoginDateTime).Take(MAX_ELEMENTS_IN_QUEUE);

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);

                    break;

                case "UPDATE":
                    if (item.Id == 0)     //Quiere decir que no se dio de alta en vtex aun
                    {
                        succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);
                    }
                    else
                    {
                        succesOperation = await _client.PutAsync(item, item.Id.ToString(), cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    switch (item.Stmpdh_Oalias)
                    {
                    case "STMPDH":

                        //21/10/2021: Se deja de utilizar tabla de log para enviar productos
                        //Stmpdh productSKUTransfered = await _repository.ProductsSKU.Get(cancellationToken, new object[] {item.RowId});
                        Stmpdh_Real productSKUReal = await _repository.ProductsSKUReal
                                                     .Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(),
                                                                                            item.Stmpdh_Artcod.Trim() });


                        productSKUReal.Usr_Vtex_Transf = "S";
                        //productSKUTransfered.Usr_Vtex_Transf = "S";
                        if (succesOperationWithNewID.Success)
                        {
                            productSKUReal.Usr_Stmpdh_Idvtex = succesOperationWithNewID.NewId;
                            // productSKUTransfered.Usr_Stmpdh_Idvtex = succesOperationWithNewID.NewId;
                        }
                        break;

                    case "USR_STMPPH":
                        Usr_Stmpph productFatherTransfered = await _repository.ProductsFather.Get(cancellationToken, new object[] { item.RowId });

                        Usr_Stmpph_Real productFatherReal = await _repository.ProductsFatherReal
                                                            .Get(cancellationToken, new object[] { productFatherTransfered.Usr_Stmpph_Indcod.Trim() });


                        productFatherTransfered.Usr_Vtex_Transf = "S";
                        if (succesOperationWithNewID.Success)
                        {
                            productFatherReal.Usr_Stmpph_Idvtex = succesOperationWithNewID.NewId;
                        }
                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
                else
                {
                    switch (item.Stmpdh_Oalias)
                    {
                    case "STMPDH":
                        Stmpdh_Real productSKU = await _repository.ProductsSKUReal.Get(cancellationToken, new object[] { item.Stmpdh_Tippro.Trim(), item.Stmpdh_Artcod.Trim() });

                        productSKU.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_STMPPH":
                        Usr_Stmpph productFather = await _repository.ProductsFather.Get(cancellationToken, new object[] { item.RowId });

                        productFather.Usr_Vtex_Transf = "E";
                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
Exemplo n.º 6
0
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var productSpecifications       = _mapper.Map <IEnumerable <Usr_Pratri>, IEnumerable <ProductSpecificationDTO> >(await _repository.ProductsAndSKUSpecifications.GetProductSpecificationForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));
            var productFatherSpecifications = _mapper.Map <IEnumerable <Usr_Stmppa>, IEnumerable <ProductSpecificationDTO> >(await _repository.ProductsFatherSpecifications.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            IEnumerable <ProductSpecificationDTO> items = productSpecifications.Concat(productFatherSpecifications).OrderBy(c => c.Sfl_LoginDateTime).Take(MAX_ELEMENTS_IN_QUEUE);

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                case "UPDATE":
                    succesOperation = await _specificationsClient.PostProductSpecificationAsync(new List <ProductSpecificationDTO> {
                        item
                    }, item.ProductId, cancellationToken);

                    break;

                case "DELETE":
                    if (item.Id != 0)
                    {
                        succesOperation = await _specificationsClient.DeleteSpecificationAsync(item, item.ProductId, item.Id, cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    switch (item.Usr_St_Oalias)
                    {
                    case "USR_PRATRI":
                        Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productSpecificationTransfered.Usr_Vtex_Transf = "S";

                        break;

                    case "USR_STMPPA":
                        Usr_Stmppa productFatherSpecificationTransfered = await _repository.ProductsFatherSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productFatherSpecificationTransfered.Usr_Vtex_Transf = "S";
                        break;

                    case "USR_PRATRM":
                        Usr_Pratrm productMotoSpecificationTransfered = await _repository.ProductsFatherMotoSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productMotoSpecificationTransfered.Usr_Vtex_Transf = "S";
                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
                else
                {
                    switch (item.Usr_St_Oalias)
                    {
                    case "USR_PRATRI":
                        Usr_Pratri productSpecificationTransfered = await _repository.ProductsAndSKUSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productSpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_STMPPA":
                        Usr_Stmppa productFatherSpecificationTransfered = await _repository.ProductsFatherSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productFatherSpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    case "USR_PRATRM":
                        Usr_Pratrm productMotoSpecificationTransfered = await _repository.ProductsFatherMotoSpecifications.Get(cancellationToken, new object[] { item.RowId });

                        productMotoSpecificationTransfered.Usr_Vtex_Transf = "E";
                        break;

                    default:
                        break;
                    }
                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var items = _mapper.Map <IEnumerable <Usr_Sttvai>, IEnumerable <SpecificationValueDTO> >(await _repository.SpecificationValues.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);

                    break;

                case "UPDATE":
                    if (item.FieldValueId == 0)     //Quiere decir que no se dio de alta en vtex aun
                    {
                        succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);
                    }
                    else
                    {
                        succesOperation = await _client.PutAsync(item, item.FieldValueId.ToString(), cancellationToken);
                    }
                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    Usr_Sttvai specificationValueTransfered = await _repository.SpecificationValues.Get(cancellationToken, new object[] { item.RowId });

                    Usr_Sttvai_Real specificationValueReal = await _repository.SpecificationValuesReal.Get(cancellationToken, new object[] { specificationValueTransfered.Usr_Sttvai_Deptos.Trim(),
                                                                                                                                             specificationValueTransfered.Usr_Sttvai_Catego.Trim(),
                                                                                                                                             specificationValueTransfered.Usr_Sttvai_Subcat.Trim(),
                                                                                                                                             specificationValueTransfered.Usr_Sttvai_Fielid,
                                                                                                                                             specificationValueTransfered.Usr_Sttvai_Valor });

                    specificationValueTransfered.Usr_Vtex_Transf = "S";
                    if (succesOperationWithNewID.Success)
                    {
                        specificationValueReal.Usr_Sttvai_Idvtex = succesOperationWithNewID.NewId;
                    }
                    await _repository.Complete();
                }
                else
                {
                    Usr_Sttvai specificationValueTransfered = await _repository.SpecificationValues.Get(cancellationToken, new object[] { item.RowId });

                    specificationValueTransfered.Usr_Vtex_Transf = "E";
                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }
        /// </summary>
        /// <returns>Return true if there is more elements in the queue</returns>

        public async Task <bool> DequeueProcessAndCheckIfContinueAsync(CancellationToken cancellationToken)
        {
            bool succesOperation = false;
            VTEXNewIDResponse succesOperationWithNewID = new VTEXNewIDResponse();

            var items = _mapper.Map <IEnumerable <Usr_Prmoto>, IEnumerable <MotosDocumentDTO> >(await _repository.Motos.GetForVTEX(cancellationToken, MAX_ELEMENTS_IN_QUEUE));

            if (!items.Any())
            {
                return(false);
            }

            foreach (var item in items)
            {
                // Put in your internal queue to process async
                // It is not recommend to process direct here, if your systems start to get slow the item will be visible in the queue and you will process more the one time
                switch (item.Sfl_TableOperation)
                {
                case "INSERT":
                    succesOperationWithNewID = await _client.PostWithNewIDAsync(item, cancellationToken);

                    break;

                case "UPDATE":
                    succesOperation = await _client.PutAsync(item, item.DocumentId.ToString(), cancellationToken);

                    break;

                case "DELETE":
                    succesOperation = await _client.DeleteAsync(item.DocumentId.ToString(), cancellationToken);

                    break;

                default:
                    break;
                }

                if (succesOperation || succesOperationWithNewID.Success)
                {
                    if (item.RowId != 0) //Moto sin año hasta
                    {
                        Usr_Prmoto motoTransfered = await _repository.Motos.Get(cancellationToken, new object[] { item.RowId });

                        motoTransfered.Usr_Vtex_Transf   = "S";
                        motoTransfered.Usr_Prmoto_Idvtex = succesOperationWithNewID.NewIdString;
                    }

                    Usr_Prmoto_Real motoReal = await _repository.MotosReal.Get(cancellationToken, new object[] { item.idERP });

                    motoReal.Usr_Prmoto_Idvtex = succesOperationWithNewID.NewIdString ?? item.DocumentId;

                    if (item.anios != null && item.anios != "")
                    {
                        motoReal.Usr_Vtex_Anohastra = Convert.ToInt32(item.anios.Split("-")[item.anios.Split("-").Length - 1]);
                    }
                    else
                    {
                        motoReal.Usr_Vtex_Anohastra = DateTime.Now.Year;
                    }

                    await _repository.Complete();
                }
                else
                {
                    Usr_Prmoto motoTransfered = await _repository.Motos.Get(cancellationToken, new object[] { item.RowId });

                    motoTransfered.Usr_Vtex_Transf = "E";
                    await _repository.Complete();
                }
            }
            return(items.Count() == MAX_ELEMENTS_IN_QUEUE);
        }