public static CustomerInfo Insert(string sessionId, Customer jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var customerInfo   = new GcpBECliente();
            var customerId     = PrimaveraEngine.GenerateName(jsonObject.Nome);
            var customersTable = PrimaveraEngine.Engine.Comercial.Clientes;

            if (customersTable.Existe(customerId))
            {
                throw new EntityExistsException("cliente", false);
            }

            customerInfo.set_Cliente(customerId);
            SetFields(customerInfo, jsonObject);
            customerInfo.set_Moeda("EUR");
            customerInfo.set_Situacao("ACTIVO");
            customerInfo.set_Inactivo(false);
            customerInfo.set_Vendedor(sessionId);
            customerInfo.set_DataCriacao(DateTime.Now);
            customerInfo.set_DataUltimaActualizacao(DateTime.Now);
            customersTable.Actualiza(customerInfo);

            return(generateCustomer(customerInfo));
        }
        public static ContactInfo Insert(string sessionId, Contact jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var contactInfo   = new CrmBEContacto();
            var contactId     = PrimaveraEngine.GenerateName(jsonObject.Nome);
            var contactsTable = PrimaveraEngine.Engine.CRM.Contactos;

            if (contactsTable.Existe(contactId))
            {
                throw new EntityExistsException("contacto", false);
            }

            contactInfo.set_Contacto(contactId);
            contactInfo.set_CriadoPor(sessionId);
            contactInfo.set_DataUltContacto(DateTime.Now);
            contactInfo.set_ID(PrimaveraEngine.generateGUID());
            SetFields(contactInfo, jsonObject);
            contactsTable.Actualiza(contactInfo);

            return(GenerateContact(contactInfo));
        }
        public static LeadListing Insert(string sessionId, Lead jsonObject)
        {
            if (PrimaveraEngine.InitializeCompany() == false)
            {
                throw new DatabaseConnectionException();
            }

            var leadId     = PrimaveraEngine.GenerateName(jsonObject.Nome);
            var leadsTable = PrimaveraEngine.Engine.CRM.EntidadesExternas;
            var leadInfo   = leadsTable.PreencheCamposDefeito(new CrmBEEntidadeExterna());

            if (leadsTable.Existe(leadId))
            {
                throw new EntityExistsException("lead", true);
            }

            var serverTime = DateTime.Now;

            leadInfo.set_Activo(true);
            leadInfo.set_Entidade(leadId);
            leadInfo.set_Vendedor(sessionId);
            leadInfo.set_DataCriacao(serverTime);
            leadInfo.set_DataUltAct(serverTime);
            leadInfo.set_PotencialCliente(true);
            SetFields(leadInfo, jsonObject);
            leadsTable.Actualiza(leadInfo);

            return(new LeadListing()
            {
                Identificador = leadInfo.get_Entidade(),
                Activo = leadInfo.get_Activo(),
                TipoTerceiro = leadInfo.get_TipoTerceiro(),
                Nome = leadInfo.get_Nome(),
                Email = leadInfo.get_Email(),
                DataModificacao = leadInfo.get_DataUltAct(),
                Telefone = leadInfo.get_Telemovel(),
                DataCriacao = leadInfo.get_DataCriacao()
            });
        }