private string toJsonComponent(ProductTreeIntegrationStatus status) { string result = string.Empty; dynamic record = new ExpandoObject(); record.U_STATUS = (int)status; result = JsonConvert.SerializeObject(record); return(result); }
async public Task Insert(ProductTree entity) { IBatchProducer batch = _serviceLayerConnector.CreateBatch(); batch = _serviceLayerConnector.CreateBatch(); string record = toJsonComponete(entity); batch.Post(HttpMethod.Post, "/ProductTrees", 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 { ProductTreeIntegrationStatus status = ProductTreeIntegrationStatus.Processed; if (response.internalResponses.Where(x => x.errorCode == "-2035").ToList().Count == 0) { if (response.internalResponses.Count(m => !m.success) != 0) { status = ProductTreeIntegrationStatus.Error; } } var prod = toJsonComponent(status); foreach (var item in entity.productTrees_Lines) { string query = Global.BuildQuery($"U_VSITPRODUCT_COMP('{item.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); } } } }