Example #1
0
        private string toJsonProduct(ProductIntegrationStatus status)
        {
            string  result = string.Empty;
            dynamic record = new ExpandoObject();

            record.U_STATUS = (int)status;
            result          = JsonConvert.SerializeObject(record);
            return(result);
        }
Example #2
0
        async public Task Insert(Items entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            batch = _serviceLayerConnector.CreateBatch();
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/Items", record);

            foreach (var i in entity.ItemBarCodes.Where(m => m.BarCode != entity.BarCode))
            {
                record = toJsonBarCode(i);
                batch.Post(HttpMethod.Post, "/BarCodes", record);
            }

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else
            {
                ProductIntegrationStatus status = ProductIntegrationStatus.Processed;

                if (response.internalResponses.Count(m => !m.success) != 0)
                {
                    status = ProductIntegrationStatus.Error;
                }

                var    prod           = toJsonProduct(status);
                string query          = Global.BuildQuery($"U_VSITPRODUCT('{entity.RecId}')");
                var    responseStatus = await _serviceLayerConnector.Patch(query, prod, true);

                if (!responseStatus.success)
                {
                    string message = $"Erro ao atualizar status de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
        }