private static void SetFields(CrmBEOportunidadeVenda opportunityInfo, Opportunity jsonObject)
 {
     opportunityInfo.set_Entidade(jsonObject.Entity);
     opportunityInfo.set_Campanha(jsonObject.Campaign);
     opportunityInfo.set_CicloVenda(jsonObject.SellCycle);
     opportunityInfo.set_DataEncomenda(jsonObject.DateOrdered);
     opportunityInfo.set_DataExpiracao(jsonObject.ExpirationDate);
     opportunityInfo.set_DataRealEncomenda(jsonObject.RealBillingDate);
     opportunityInfo.set_Descricao(jsonObject.Description);
     opportunityInfo.set_MargemOV(jsonObject.MarginOV);
     opportunityInfo.set_Origem(jsonObject.Origin);
     opportunityInfo.set_ValorEncomendaOV(jsonObject.OrderValueOV);
     opportunityInfo.set_ValorPropostoOV(jsonObject.ProposedValueOV);
     opportunityInfo.set_Zona(jsonObject.Zone);
     opportunityInfo.set_EstadoVenda(jsonObject.Status);
     opportunityInfo.set_Vendedor(jsonObject.Seller);
     opportunityInfo.set_CriadoPor(jsonObject.CreatedBy);
     opportunityInfo.set_DataRealFacturacao(jsonObject.RealBillingDate);
     opportunityInfo.set_DataFecho(jsonObject.ClosureDate);
     opportunityInfo.set_MotivoPerda(jsonObject.LossMotive);
     opportunityInfo.set_Moeda(jsonObject.Currency);
     opportunityInfo.set_Resumo(jsonObject.Brief);
     opportunityInfo.set_TipoEntidade(jsonObject.EntityType);
     opportunityInfo.set_ValorTotalOV(jsonObject.TotalValueOV);
 }
        public static OpportunityInfo Insert(string sessionId, Opportunity jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var opportunityInfo    = new CrmBEOportunidadeVenda();
            var opportunityId      = PrimaveraEngine.GenerateHash();
            var opportunitiesTable = PrimaveraEngine.Engine.CRM.OportunidadesVenda;

            if (opportunitiesTable.Existe(opportunityId))
            {
                throw new EntityExistsException("oportunidade", true);
            }

            SetFields(opportunityInfo, jsonObject);
            opportunityInfo.set_CriadoPor(sessionId);
            opportunityInfo.set_Oportunidade(opportunityId);
            opportunityInfo.set_DataCriacao(DateTime.Now);
            opportunitiesTable.Actualiza(opportunityInfo);

            return(GenerateOpportunity(opportunityInfo));
        }