Exemplo n.º 1
0
        private void preencheDados(Endereco endereco, ref IPluginExecutionContext context, IOrganizationService adminService)
        {
            var target = context.GetContextEntity();

            target.Attributes["new_cnpj"] = endereco.Identificacao.GetOnlyNumbers();
            // Caso de exclusão do registro não busca a mensagem de CEP novamente
            if (endereco.IntegrarNoPlugin && endereco.Cep != null)
            {
                var service = new EnderecoServices(context.OrganizationName, context.IsExecutingOffline, adminService);

                CepViewModel enderecoIntegracao = service.BuscaCep(endereco.Cep.GetOnlyNumbers());
                if (enderecoIntegracao == null)
                {
                    throw new ArgumentException("(CRM) Este CEP não foi encontrado na base do Totvs.");
                }

                target.Attributes["postalcode"] = endereco.Cep.GetOnlyNumbers();
                //target.Attributes["line2"] = enderecoIntegracao.Bairro;
                //target.Attributes["city"] = enderecoIntegracao.NomeCidade;
                target.Attributes["stateorprovince"] = enderecoIntegracao.UF;
                target.Attributes["country"]         = enderecoIntegracao.Pais.Name;
            }
        }
Exemplo n.º 2
0
        public Contato DefinirPropriedades(Pollux.MSG0192 xml)
        {
            var crm = new Contato(this.Organizacao, this.IsOffline);

            #region Propriedades Xml->Crm

            if (xml.EnderecoPrincipal == null)
            {
                resultadoPersistencia.Sucesso  = false;
                resultadoPersistencia.Mensagem = "Endereço Principal não enviado!";
                return(crm);
            }

            crm.IntegrarNoPlugin = true;

            crm.CodigoRepresentante = xml.CodigoRepresentante.ToString();
            crm.NomeCompleto        = xml.NomeRepresentante;
            if (xml.NomeRepresentante.Length >= 40)
            {
                crm.PrimeiroNome = xml.NomeRepresentante.Substring(0, 40);
            }
            else
            {
                crm.PrimeiroNome = xml.NomeRepresentante;
            }
            crm.SegundoNome = xml.NomeAbreviado;
            crm.Natureza    = xml.Natureza;
            crm.Status      = xml.Situacao;
            crm.TipoRelacao = (int)Enum.Contato.TipoRelacao.KeyAccount;
            crm.Email2      = xml.Email;
            if (!String.IsNullOrEmpty(xml.Site))
            {
                crm.WebSite = xml.Site;
            }
            else
            {
                crm.AddNullProperty("WebSite");
            }

            crm.IntegradoEm       = DateTime.Now;
            crm.IntegradoPor      = usuarioIntegracao.NomeCompleto;
            crm.UsuarioIntegracao = xml.LoginUsuario;

            #region Bloco Endereco
            ///Bloco Endereco
            // Cidade
            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Cidade))
            {
                Municipio cidade = new Municipio(this.Organizacao, this.IsOffline);
                cidade = new EnderecoServices(this.Organizacao, this.IsOffline).BuscaMunicipio(xml.EnderecoPrincipal.Cidade);

                if (cidade != null && cidade.ID.HasValue)
                {
                    crm.Endereco1Municipioid = new Lookup(cidade.ID.Value, "");
                }

                else
                {
                    resultadoPersistencia.Sucesso  = false;
                    resultadoPersistencia.Mensagem = "Cidade não encontrada!";
                    return(crm);
                }
            }

            // Estado (UF)
            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Estado))
            {
                Estado estado = new Estado(this.Organizacao, this.IsOffline);
                estado = new EnderecoServices(this.Organizacao, this.IsOffline).BuscaEstado(xml.EnderecoPrincipal.Estado);

                if (estado != null && estado.ID.HasValue)
                {
                    crm.Endereco1Estadoid = new Lookup(estado.ID.Value, "");
                }
                else
                {
                    resultadoPersistencia.Sucesso  = false;
                    resultadoPersistencia.Mensagem = "Estado não encontrado!";
                    return(crm);
                }
            }

            // País
            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Pais))
            {
                Pais pais = new Pais(this.Organizacao, this.IsOffline);
                pais = new EnderecoServices(this.Organizacao, this.IsOffline).BuscaPais(xml.EnderecoPrincipal.Pais);

                if (pais != null && pais.ID.HasValue)
                {
                    crm.Endereco1Pais = new Lookup(pais.ID.Value, "");
                }
                else
                {
                    resultadoPersistencia.Sucesso  = false;
                    resultadoPersistencia.Mensagem = "País não encontrado!";
                    return(crm);
                }
            }

            if (xml.EnderecoPrincipal.TipoEndereco.HasValue)
            {
                crm.Endereco1TipoEndereco = xml.EnderecoPrincipal.TipoEndereco.Value;
            }
            else
            {
                crm.AddNullProperty("Endereco1TipoEndereco");
            }

            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.NomeEndereco))
            {
                crm.Endereco1Nome = xml.EnderecoPrincipal.NomeEndereco;
            }
            else
            {
                crm.AddNullProperty("Endereco1Nome");
            }

            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Logradouro))
            {
                crm.Endereco1Rua = xml.EnderecoPrincipal.Logradouro;
            }
            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Numero))
            {
                crm.Endereco1Numero = xml.EnderecoPrincipal.Numero;
            }
            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Complemento))
            {
                crm.Endereco1Complemento = xml.EnderecoPrincipal.Complemento;
            }
            else
            {
                crm.AddNullProperty("Endereco1Complemento");
            }

            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Bairro))
            {
                crm.Endereco1Bairro = xml.EnderecoPrincipal.Bairro;
            }
            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.CEP))
            {
                crm.Endereco1CEP = Helper.FormatarCep(xml.EnderecoPrincipal.CEP);
            }
            if (!String.IsNullOrEmpty(xml.EnderecoPrincipal.Telefone))
            {
                crm.Endereco1Telefone = xml.EnderecoPrincipal.Telefone;
                // para garantir que só será atualizado caso o usuário não tenha preenchido pelo formulário do CRM
                if (crm.TelefoneComercial == null)
                {
                    crm.TelefoneComercial = xml.EnderecoPrincipal.Telefone;
                }
            }
            else
            {
                crm.AddNullProperty("Endereco1Telefone");
            }

            #endregion

            #endregion

            return(crm);
        }