internal Guid ListaPreco(string nomeLista, ref Pollux.Entities.Resultado resultadoPersistencia) { Model.ListaPreco listaPreco = new Intelbras.CRM2013.Domain.Servicos.ListaPrecoService(this.Organizacao, this.IsOffline).BuscaListaPreco(nomeLista); if (listaPreco != null && listaPreco.ID.HasValue) { return((Guid)listaPreco.ID); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Lista de Preços não encontrada!"; return(Guid.Empty); } }
public Fatura DefinirPropriedades(Intelbras.Message.Helper.MSG0094 xml) { Fatura crm = new Fatura(this.Organizacao, this.IsOffline); if (!String.IsNullOrEmpty(xml.NumeroNotaFiscal)) { crm.NumeroNF = xml.NumeroNotaFiscal; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "NumeroNotaFiscal não enviado."; return(crm); } crm.Serie = xml.NumeroSerie; crm.ClienteId = new Lookup(new Guid(xml.CodigoClienteCRM), xml.TipoObjetoCliente); crm.ChaveIntegracao = xml.ChaveIntegracao; //NumeroPedido.ToString(); if (xml.NumeroPedido != null) { Pedido pedido = new Servicos.PedidoService(this.Organizacao, this.IsOffline).BuscaPedidoEMS(xml.NumeroPedido.ToString()); if (pedido != null) { crm.PedidoCRM = new Lookup(pedido.ID.Value, ""); Fatura fatura = new Servicos.FaturaService(this.Organizacao, this.IsOffline).ObterFaturaPorPedidoEMS(xml.NumeroPedido.ToString()); if (fatura != null) { crm.ID = fatura.ID.Value; } } } if (!String.IsNullOrEmpty(xml.NumeroPedidoCliente)) { crm.PedidoCliente = xml.NumeroPedidoCliente; } else { crm.AddNullProperty("PedidoCliente"); } if (!String.IsNullOrEmpty(xml.Descricao)) { crm.Descricao = xml.Descricao; } else { crm.AddNullProperty("Descricao"); } //Service Estabelecimento Estabelecimento ObjEstabelecimento = new Intelbras.CRM2013.Domain.Servicos.EstabelecimentoService(this.Organizacao, this.IsOffline).BuscaEstabelecimentoPorCodigo(xml.Estabelecimento.Value); if (ObjEstabelecimento != null) { crm.Estabelecimento = new Lookup((Guid)ObjEstabelecimento.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador do Estabelecimento não encontrado."; return(crm); } //Service Condição Pagamento CondicaoPagamento ObjCondicaoPagamento = null; if (xml.CondicaoPagamento.HasValue) { ObjCondicaoPagamento = new Intelbras.CRM2013.Domain.Servicos.CondicaoPagamentoService(this.Organizacao, this.IsOffline).BuscaCondicaoPagamentoPorCodigo(xml.CondicaoPagamento.Value); if (ObjCondicaoPagamento != null) { crm.CondicaoPagamento = new Lookup((Guid)ObjCondicaoPagamento.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Condição de Pagamento não encontrado."; return(crm); } } else { crm.AddNullProperty("CondicaoPagamento"); } crm.NomeAbreviado = xml.NomeAbreviadoCliente; //Service Natureza Operação NaturezaOperacao ObjNaturezaOperacao = new Intelbras.CRM2013.Domain.Servicos.NaturezaOperacaoService(this.Organizacao, this.IsOffline).BuscaNaturezaOperacaoPorCodigo(xml.NaturezaOperacao); if (ObjNaturezaOperacao != null) { crm.NaturezaOperacao = new Lookup((Guid)ObjNaturezaOperacao.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Natureza de Operação não encontrado."; return(crm); } //Service Moeda Moeda ObjMoeda = new Intelbras.CRM2013.Domain.Servicos.MoedaService(this.Organizacao, this.IsOffline).BuscaMoedaPorCodigo(xml.Moeda); if (ObjMoeda != null) { crm.Moeda = new Lookup((Guid)ObjMoeda.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Moeda não encontrado."; return(crm); } //Service para resolver o status if (System.Enum.IsDefined(typeof(Enum.Fatura.Status), xml.SituacaoNota)) { crm.Status = xml.SituacaoNota; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Situação da nota não encontrado."; return(crm); } if (System.Enum.IsDefined(typeof(Enum.Fatura.RazaoStatus), xml.SituacaoEntrega)) { crm.RazaoStatus = xml.SituacaoEntrega; } crm.DataEmissao = xml.DataEmissao; if (xml.DataSaida.HasValue) { crm.DataSaida = xml.DataSaida; } else { crm.AddNullProperty("DataSaida"); } if (xml.DataEntrega.HasValue) { crm.DataEntrega = xml.DataEntrega; } else { crm.AddNullProperty("DataEntrega"); } if (xml.DataConfirmacao != null) { crm.DataConfirmacao = xml.DataConfirmacao; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "DataConfirmacao não enviada."; return(crm); } if (xml.DataCancelamento.HasValue) { crm.DataCancelamento = xml.DataCancelamento; } else { crm.AddNullProperty("DataCancelamento"); } if (xml.DataConclusao.HasValue) { crm.DataConclusao = xml.DataConclusao; } else { crm.AddNullProperty("DataConclusao"); } crm.ValorFrete = xml.ValorFrete; crm.PesoLiquido = xml.PesoLiquido; crm.PesoBruto = xml.PesoBruto; if (!String.IsNullOrEmpty(xml.Observacao)) { crm.Observacao = xml.Observacao; } else { crm.AddNullProperty("Observacao"); } crm.Volume = xml.Volume.ToString(); crm.BaseICMS = xml.ValorBaseICMS; crm.ValorICMS = xml.ValorICMS; crm.ValorIPI = xml.ValorIPI; crm.BaseSubstTributaria = xml.ValorBaseSubstituicaoTributaria; crm.ValorSubstituicao = xml.ValorSubstituicaoTributaria; crm.ClienteRetira = xml.RetiraNoLocal; if (xml.MetodoEntrega.HasValue) { crm.MetodoEntrega = xml.MetodoEntrega; } else { crm.AddNullProperty("MetodoEntrega"); } //Service Transportadora Transportadora ObjTransportadora = new Intelbras.CRM2013.Domain.Servicos.TransportadoraService(this.Organizacao, this.IsOffline).ObterPorCodigoTransportadora(xml.Transportadora.Value); if (ObjTransportadora != null) { crm.Transportadora = new Lookup((Guid)ObjTransportadora.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Transportadora não encontrado."; return(crm); } crm.Frete = xml.Frete; //crm.CondicoesFrete = xml.tipo; if (!String.IsNullOrEmpty(xml.TelefoneCobranca)) { crm.TelefoneCobranca = xml.TelefoneCobranca; } else { crm.AddNullProperty("TelefoneCobranca"); } if (!String.IsNullOrEmpty(xml.FaxCobranca)) { crm.FaxCobranca = xml.FaxCobranca; } else { crm.AddNullProperty("FaxCobranca"); } //Removido essa validação para que as NF de clientes estrangeiros sejam integrados no CRM //if (!String.IsNullOrEmpty(xml.CNPJ)) // crm.CpfCnpj = Intelbras.CRM2013.Domain.Servicos.Helper.FormatarCnpj(xml.CNPJ); //else if (!String.IsNullOrEmpty(xml.CPF)) // crm.CpfCnpj = Intelbras.CRM2013.Domain.Servicos.Helper.FormatarCpf(xml.CPF); //else //{ // resultadoPersistencia.Sucesso = false; // resultadoPersistencia.Mensagem = "CNPJ/CPF não enviado."; // return crm; //} if (!String.IsNullOrEmpty(xml.InscricaoEstadual)) { crm.InscricaoEstadual = xml.InscricaoEstadual; } else { crm.AddNullProperty("InscricaoEstadual"); } if (!string.IsNullOrEmpty(xml.Oportunidade)) { crm.Oportunidade = new Lookup(new Guid(xml.Oportunidade), ""); } xml.PrecoBloqueado = xml.PrecoBloqueado; if (xml.ValorDesconto.HasValue) { crm.ValorDescontoFatura = xml.ValorDesconto; } else { crm.AddNullProperty("ValorDescontoFatura"); } if (xml.PercentualDesconto.HasValue) { crm.DescontoGlobalTotal = xml.PercentualDesconto; } else { crm.AddNullProperty("DescontoGlobalTotal"); } //Service Lista Preço ListaPreco ObjListaPreco = new Intelbras.CRM2013.Domain.Servicos.ListaPrecoService(this.Organizacao, this.IsOffline).BuscaListaPreco(xml.ListaPreco); if (ObjListaPreco != null) { crm.ListaPrecos = new Lookup((Guid)ObjListaPreco.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Lista de Preço não encontrado."; return(crm); } crm.Prioridade = xml.Prioridade; if (xml.ValorTotal.HasValue) { crm.ValorTotal = xml.ValorTotal; } else { crm.AddNullProperty("ValorTotal"); } if (xml.ValorTotalImpostos.HasValue) { crm.TotalImpostos = xml.ValorTotalImpostos; } else { crm.AddNullProperty("TotalImpostos"); } //if (xml.ValorTotalProdutosSemImposto.HasValue) // crm.ValorTotalProdutosSemIPIST = xml.ValorTotalProdutosSemImposto; if (xml.ValorTotalSemFrete.HasValue) { crm.ValorTotalSemFrete = xml.ValorTotalSemFrete; } else { crm.AddNullProperty("ValorTotalSemFrete"); } if (xml.ValorTotalDesconto.HasValue) { crm.DescontoTotal = xml.ValorTotalDesconto; } else { crm.AddNullProperty("DescontoTotal"); } if (xml.ValorTotalProdutos.HasValue) { crm.TotalProdutosComIPIST = xml.ValorTotalProdutos; } else { crm.AddNullProperty("TotalProdutosComIPIST"); } if (xml.ValorTotalProdutosSemImposto.HasValue) { crm.ValorTotalProdutosSemIPIST = xml.ValorTotalProdutosSemImposto; } else { crm.AddNullProperty("ValorTotalProdutosSemIPIST"); } //Service Endereco Entrega if (!string.IsNullOrEmpty(xml.EnderecoEntrega.CaixaPostal)) { crm.EnderecoEntregaCaixaPostal = xml.EnderecoEntrega.CaixaPostal; } else { crm.AddNullProperty("EnderecoEntregaCaixaPostal"); } if (!string.IsNullOrEmpty(xml.EnderecoEntrega.NomeEndereco)) { crm.NomeEntrega = xml.EnderecoEntrega.NomeEndereco; } else { crm.AddNullProperty("NomeEntrega"); } crm.CEPEntrega = xml.EnderecoEntrega.CEP; crm.EnderecoEntregaRua = xml.EnderecoEntrega.Logradouro; crm.EnderecoEntregaNumero = xml.EnderecoEntrega.Numero; crm.BairroEntrega = xml.EnderecoEntrega.Bairro; crm.ComplementoEntrega = xml.EnderecoEntrega.Complemento; crm.TipoNotaFiscal = xml.TipoNotaFiscal; crm.NotaDevolucao = xml.NotaDevolucao; crm.IdentificadorUnicoNfe = xml.IdentificadorUnicoNFE; if (!string.IsNullOrEmpty(xml.EnderecoEntrega.Complemento)) { crm.ComplementoEntrega = xml.EnderecoEntrega.Complemento; } else { crm.AddNullProperty("ComplementoEntrega"); } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Cidade)) { Model.Municipio cidade = new Model.Municipio(this.Organizacao, this.IsOffline); cidade = new Intelbras.CRM2013.Domain.Servicos.EnderecoServices(this.Organizacao, this.IsOffline).BuscaMunicipio(xml.EnderecoEntrega.Cidade); if (cidade != null && cidade.ID.HasValue) { crm.EnderecoEntregaCidade = new Lookup(cidade.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Cidade não encontrado!"; return(crm); } } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Estado)) { Model.Estado estado = new Model.Estado(this.Organizacao, this.IsOffline); estado = new Intelbras.CRM2013.Domain.Servicos.EnderecoServices(this.Organizacao, this.IsOffline).BuscaEstado(xml.EnderecoEntrega.Estado); if (estado != null && estado.ID.HasValue) { crm.EnderecoEntregaEstado = new Lookup(estado.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador do Estado não encontrado!"; return(crm); } } ///Service Pais if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Pais)) { Model.Pais pais = new Model.Pais(this.Organizacao, this.IsOffline); pais = new Intelbras.CRM2013.Domain.Servicos.EnderecoServices(this.Organizacao, this.IsOffline).BuscaPais(xml.EnderecoEntrega.Pais); if (pais != null && pais.ID.HasValue) { crm.EnderecoEntregaPais = new Lookup(pais.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador do País não encontrado."; return(crm); } } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.NomeContato)) { crm.NomeEntrega = xml.EnderecoEntrega.NomeContato; } else { crm.AddNullProperty("NomeEntrega"); } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Telefone)) { crm.TelefoneEntrega = xml.EnderecoEntrega.Telefone; } else { crm.AddNullProperty("TelefoneEntrega"); } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Fax)) { crm.FaxEntrega = xml.EnderecoEntrega.Fax; } else { crm.AddNullProperty("FaxEntrega"); } #region Representante crm.IntegradoRepresentanteComErro = false; crm.IntegradoComErros = false; crm.RepresentanteOriginal = xml.Representante.ToString(); Contato ObjRepresentante = new Intelbras.CRM2013.Domain.Servicos.ContatoService(this.Organizacao, this.IsOffline) .BuscaContatoPorCodigoRepresentante(xml.Representante.ToString()); if (ObjRepresentante != null) { crm.KARepresentante = new Lookup(ObjRepresentante.ID.Value, ""); } else { crm.IntegradoRepresentanteComErro = true; crm.IntegradoComErros = true; crm.KARepresentante = new Lookup(ObterRepresentatePadrao(), ""); } #endregion return(crm); }
public ItemListaPreco DefinirPropriedades(Intelbras.Message.Helper.MSG0082 xml) { var crm = new ItemListaPreco(this.Organizacao, this.IsOffline); #region Propriedades Crm->Xml if (!String.IsNullOrEmpty(xml.CodigoItemListaPreco)) { crm.ID = new Guid(xml.CodigoItemListaPreco); } if (!String.IsNullOrEmpty(xml.Produto)) { Product produto = new Product(this.Organizacao, this.IsOffline); produto = new Intelbras.CRM2013.Domain.Servicos.ProdutoService(this.Organizacao, this.IsOffline).BuscaPorCodigo(xml.Produto); if (produto != null) { crm.ProdutoID = new Lookup(produto.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Produto não encontrado."; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Produto não enviado."; return(crm); } if (!String.IsNullOrEmpty(xml.ListaPreco)) { Model.ListaPreco listaPreco = new Model.ListaPreco(this.Organizacao, this.IsOffline); listaPreco = new Intelbras.CRM2013.Domain.Servicos.ListaPrecoService(this.Organizacao, this.IsOffline).BuscaListaPreco(xml.ListaPreco); if (listaPreco != null && listaPreco.ID.HasValue) { crm.ListaPrecos = new Lookup(listaPreco.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "ListaPreco não encontrado."; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "ListaPreco não enviada."; return(crm); } crm.Valor = xml.Valor; crm.Porcentual = xml.Porcentagem; if (!String.IsNullOrEmpty(xml.ListaDesconto)) { ListaDesconto listaDesconto = new ListaDesconto(this.Organizacao, this.IsOffline); listaDesconto = new Intelbras.CRM2013.Domain.Servicos.ListaDescontoService(this.Organizacao, this.IsOffline).BuscaListaDesconto(xml.ListaDesconto); if (listaDesconto != null) { crm.ListaDesconto = new Lookup(listaDesconto.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Lista Desconto não encontrada."; return(crm); } } else { crm.AddNullProperty("ListaDesconto"); } crm.MetodoPrecificacao = xml.MetodoPrecificacao; crm.OpcaoVendaParcial = xml.OpcaoVendaParcial; crm.ValorArredondamento = xml.ValorArredondamento; crm.OpcaoArredondamento = xml.OpcaoArredondamento; crm.PoliticaArredondamento = xml.PoliticaArredondamento; if (!String.IsNullOrEmpty(xml.Moeda)) { Model.Moeda moeda = new Model.Moeda(this.Organizacao, this.IsOffline); moeda = new Intelbras.CRM2013.Domain.Servicos.MoedaService(this.Organizacao, this.IsOffline).BuscaMoedaPorNome(xml.Moeda); if (moeda != null && moeda.ID.HasValue) { crm.Moeda = new Lookup(moeda.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Moeda não encontrada!"; return(crm); } } if (!String.IsNullOrEmpty(xml.UnidadeMedida)) { Unidade unidade = new Unidade(this.Organizacao, this.IsOffline); unidade = new Intelbras.CRM2013.Domain.Servicos.UnidadeService(this.Organizacao, this.IsOffline).BuscaUnidadePorNome(xml.UnidadeMedida); if (unidade != null) { crm.Unidade = new Lookup(unidade.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "UnidadeMedida não encontrada."; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "UnidadeMedida não enviada."; return(crm); } //Entidade não tem ownerid //crm.Proprietario = new SDKore.DomainModel.Lookup((Guid)usuarioIntegracao.ID, "systemuser"); //crm.IntegradoEm = DateTime.Now; //crm.IntegradoPor = usuarioIntegracao.NomeCompleto; //crm.UsuarioIntegracao = xml.LoginUsuario; #endregion return(crm); }
public void Execute(IServiceProvider serviceProvider) { var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(null); try { switch (Util.Utilitario.ConverterEnum <Domain.Enum.Plugin.MessageName>(context.MessageName)) { case Domain.Enum.Plugin.MessageName.Associate: if ((context.InputParameters.Contains("Relationship")) && (context.InputParameters.Contains("RelatedEntities") && context.InputParameters["RelatedEntities"] is EntityReferenceCollection)) { var targetEntity = (EntityReference)context.InputParameters["Target"]; var relatedEntities = context.InputParameters["RelatedEntities"] as EntityReferenceCollection; switch (((Relationship)context.InputParameters["Relationship"]).SchemaName.ToString()) { case "itbc_itbc_psdid_itbc_estado": List <Guid> lstEstados = new List <Guid>(); Domain.Model.ListaPrecoPSDPPPSCF lstPSD = new Intelbras.CRM2013.Domain.Servicos.ListaPSDService(context.OrganizationName, context.IsExecutingOffline, service).ObterPor(targetEntity.Id); if (lstPSD == null) { throw new ArgumentException("Lista PSD não encontrada!"); } foreach (EntityReference entidade in relatedEntities) { lstEstados.Add(entidade.Id); } if (new Intelbras.CRM2013.Domain.Servicos.ListaPSDService(context.OrganizationName, context.IsExecutingOffline, service).ValidarExistencia(lstPSD, lstEstados)) { throw new ArgumentException("Registro duplicado!Operação cancelada."); } break; //Caso Lista PMA x Estado case "itbc_pricelevel_itbc_estado": List <Guid> lstEstadosPMA = new List <Guid>(); Domain.Model.ListaPreco listaPMA = new Intelbras.CRM2013.Domain.Servicos.ListaPrecoService(context.OrganizationName, context.IsExecutingOffline, service).ObterPor(targetEntity.Id); if (listaPMA == null) { throw new ArgumentException("Lista PMA não encontrada!"); } foreach (EntityReference entidade in relatedEntities) { lstEstadosPMA.Add(entidade.Id); } if (new Intelbras.CRM2013.Domain.Servicos.ListaPrecoService(context.OrganizationName, context.IsExecutingOffline, service).ValidarExistencia(listaPMA, lstEstadosPMA)) { throw new ArgumentException("Registro duplicado!Operação cancelada."); } break; //Ligar conta com politica comercial case "itbc_itbc_politicacomercial_account": List <Guid> lstCanais = new List <Guid>(); //Impedir duplicidade politica comercial- conta Domain.Model.PoliticaComercial politicaComercial = new Intelbras.CRM2013.Domain.Servicos.PoliticaComercialService(context.OrganizationName, context.IsExecutingOffline, service).ObterPor(targetEntity.Id); //Só pode vincular quando for Aplicar politica para != perfil de canais if (politicaComercial.AplicarPoliticaPara.HasValue && politicaComercial.AplicarPoliticaPara.Value == (int)Domain.Enum.PoliticaComercial.AplicarPolíticaPara.PerfilDeCanais) { throw new ArgumentException("(CRM)Não é possível realizar a operação: A política comercial é para perfis de canais.Não é possível vincular um canal"); } //Só pode vincular quando Tipo da politica for diferente de cross-selling if (politicaComercial.TipoDePolitica.HasValue && politicaComercial.TipoDePolitica.Value == (int)Domain.Enum.PoliticaComercial.TipoDePolitica.CrossSelling) { throw new ArgumentException("(CRM)Não é possível realizar a operação: A política comercial é para cross selling.Não é possível vincular um canal"); } //Só verifica duplicidade se o registro estiver ativo if (politicaComercial.Status.HasValue && politicaComercial.Status.Value == (int)Domain.Enum.PoliticaComercial.Status.Ativo) { foreach (EntityReference entidade in relatedEntities) { lstCanais.Add(entidade.Id); } if (true == new Intelbras.CRM2013.Domain.Servicos.PoliticaComercialService(context.OrganizationName, context.IsExecutingOffline, service).VerificarDuplicidadePoliticaRegistros(politicaComercial, lstCanais, "conta", true)) { throw new ArgumentException("(CRM)Não é possível realizar a operação: O canal informado já está vinculado à outra política comercial com o mesmo tipo, aplicação, estabelecimento, unidade de negócio e data de vigência"); } } break; //Ligar Estado com politica comercial case "itbc_itbc_politicacomercial_itbc_estado": List <Guid> lstEstadosPoliticaComercial = new List <Guid>(); //Impedir duplicidade politica comercial- Estado Domain.Model.PoliticaComercial _mPoliticaComercial = new Intelbras.CRM2013.Domain.Servicos.PoliticaComercialService(context.OrganizationName, context.IsExecutingOffline, service).ObterPor(targetEntity.Id); //Só verifica duplicidade se o registro estiver ativo if (_mPoliticaComercial.Status.HasValue && _mPoliticaComercial.Status.Value == (int)Domain.Enum.PoliticaComercial.Status.Ativo) { foreach (EntityReference entidade in relatedEntities) { lstEstadosPoliticaComercial.Add(entidade.Id); } if (true == new Intelbras.CRM2013.Domain.Servicos.PoliticaComercialService(context.OrganizationName, context.IsExecutingOffline, service).VerificarDuplicidadePoliticaRegistros(_mPoliticaComercial, lstEstadosPoliticaComercial, "estado", false)) { throw new ArgumentException("(CRM)Não é possível realizar a operação: O estado informado já está vinculado à outra política comercial com o mesmo tipo, aplicação, estabelecimento, unidade de negócio e data de vigência"); } } break; } } break; } } catch (Exception ex) { trace.Trace(String.Format("EXCEPTION PLUGIN {0} {1} [{2}]", context.MessageName.ToLower(), "AssociateEvent", DateTime.Now)); trace.Trace(SDKore.Helper.Error.GetMessageError(ex)); throw new InvalidPluginExecutionException(ex.Message); } }