public string Executar(string mensagem, string numeroMensagem, Domain.Model.Usuario usuario) { //Trace.Add("Mensagem " + numeroMensagem + " XML: {0}", mensagem); usuarioIntegracao = usuario; var xml = this.CarregarMensagem <Pollux.MSG0129>(mensagem); if (!String.IsNullOrEmpty(xml.CodigoUnidadeNegocio)) {//Retorna registros com base no estabelecimento //Pegamos a Unidade de negócio com base no codigo do erp dele UnidadeNegocio objUnidadeNegocio = new Intelbras.CRM2013.Domain.Servicos.UnidadeNegocioService(this.Organizacao, this.IsOffline).BuscaUnidadeNegocioPorChaveIntegracao(xml.CodigoUnidadeNegocio); if (objUnidadeNegocio == null) { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Unidade de Negócio não encontrada."; retorno.Add("Resultado", resultadoPersistencia); return(CriarMensagemRetorno <Pollux.MSG0129R1>(numeroMensagem, retorno)); } List <Segmento> lstSegmento = new Intelbras.CRM2013.Domain.Servicos.SegmentoService(this.Organizacao, this.IsOffline).ListarPorUnidadeNegocio((Guid)objUnidadeNegocio.ID); if (lstSegmento.Any <Segmento>()) { //para nao precisar refazer a service codigoUnidadeNegocio = xml.CodigoUnidadeNegocio; List <Pollux.Entities.Segmento> SegmentoItens = this.ConverteLista(lstSegmento); resultadoPersistencia.Sucesso = true; retorno.Add("SegmentosItens", SegmentoItens); } else { resultadoPersistencia.Sucesso = true; resultadoPersistencia.Mensagem = "Segmento não encontrado."; } } else {//Retorna todos registros List <Segmento> lstSegmento = new Intelbras.CRM2013.Domain.Servicos.SegmentoService(this.Organizacao, this.IsOffline).ListarTodos(); List <Pollux.Entities.Segmento> lstRetorno = this.ConverteLista(lstSegmento); if (lstSegmento != null) { resultadoPersistencia.Sucesso = true; resultadoPersistencia.Mensagem = ""; retorno.Add("SegmentosItens", lstRetorno); } else { resultadoPersistencia.Sucesso = true; resultadoPersistencia.Mensagem = "Registros não encontrados."; } } retorno.Add("Resultado", resultadoPersistencia); return(CriarMensagemRetorno <Pollux.MSG0129R1>(numeroMensagem, retorno)); }
public Guid Segmento(string codigoSegmento, ref Pollux.Entities.Resultado resultadoPersistencia) { Model.Segmento segmento = new Intelbras.CRM2013.Domain.Servicos.SegmentoService(this.Organizacao, this.IsOffline).BuscaSegmento(codigoSegmento); if (segmento != null && segmento.ID.HasValue) { //crm.Segmento = new Lookup(segmento.ID.Value, ""); return((Guid)segmento.ID); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Segmento não encontrado!"; return(Guid.Empty); } }
public FamiliaComercial DefinirPropriedades(Intelbras.Message.Helper.MSG0036 xml) { var crm = new FamiliaComercial(this.Organizacao, this.IsOffline); #region Propriedades Crm->Xml if (!String.IsNullOrEmpty(xml.Nome)) { crm.Nome = xml.Nome; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Nome não enviado."; return(crm); } if (!String.IsNullOrEmpty(xml.CodigoFamiliaComercial)) { crm.Codigo = xml.CodigoFamiliaComercial; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Código Familia Comercial não enviado."; return(crm); } #region Services //Segmento if (!String.IsNullOrEmpty(xml.Segmento)) { Model.Segmento segmento = new Model.Segmento(this.Organizacao, this.IsOffline); segmento = new Intelbras.CRM2013.Domain.Servicos.SegmentoService(this.Organizacao, this.IsOffline).BuscaSegmento(xml.Segmento); if (segmento != null && segmento.ID.HasValue) { crm.Segmento = new Lookup(segmento.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Segmento não encontrado!"; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Segmento não enviado."; return(crm); } //Familia if (!String.IsNullOrEmpty(xml.Familia)) { Model.FamiliaProduto familia = new Model.FamiliaProduto(this.Organizacao, this.IsOffline); familia = new Intelbras.CRM2013.Domain.Servicos.FamiliaProdutoService(this.Organizacao, this.IsOffline).BuscaFamiliaProduto(xml.Familia); if (familia != null && familia.ID.HasValue) { crm.Familia = new Lookup(familia.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "FamiliaProduto não encontrado!"; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "FamiliaProduto não enviado."; return(crm); } //SubfamiliaProduto if (!String.IsNullOrEmpty(xml.SubFamilia)) { Model.SubfamiliaProduto subFamilia = new Model.SubfamiliaProduto(this.Organizacao, this.IsOffline); subFamilia = new Intelbras.CRM2013.Domain.Servicos.SubFamiliaProdutoService(this.Organizacao, this.IsOffline).BuscaSubfamiliaProduto(xml.SubFamilia); if (subFamilia != null && subFamilia.ID.HasValue) { crm.Subfamilia = new Lookup(subFamilia.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "SubfamiliaProduto não encontrado!"; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "SubfamiliaProduto não enviado."; return(crm); } //Origem if (!String.IsNullOrEmpty(xml.Origem)) { Model.Origem origem = new Model.Origem(this.Organizacao, this.IsOffline); origem = new Intelbras.CRM2013.Domain.Servicos.OrigemService(this.Organizacao, this.IsOffline).BuscaOrigem(xml.Origem); if (origem != null && origem.ID.HasValue) { crm.Origem = new Lookup(origem.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Origem não encontrado!"; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Origem não enviado."; return(crm); } crm.Status = xml.Situacao; crm.IntegradoEm = DateTime.Now; crm.IntegradoPor = usuarioIntegracao.NomeCompleto; crm.UsuarioIntegracao = xml.LoginUsuario; #endregion #endregion return(crm); }
public FamiliaProduto DefinirPropriedades(Intelbras.Message.Helper.MSG0028 xml) { var crm = new FamiliaProduto(this.Organizacao, this.IsOffline); FamiliaProduto familiaProduto = new Intelbras.CRM2013.Domain.Servicos.RepositoryService(this.Organizacao, this.IsOffline).FamiliaProduto.ObterPor(xml.CodigoFamilia); if (familiaProduto != null) { crm.DescontoVerdeHabilitado = familiaProduto.DescontoVerdeHabilitado; } #region Propriedades Crm->Xml if (!String.IsNullOrEmpty(xml.Nome)) { crm.Nome = xml.Nome; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "(Nome não enviado."; return(crm); } if (!String.IsNullOrEmpty(xml.CodigoFamilia)) { crm.Codigo = xml.CodigoFamilia; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "(Código Família não enviado."; return(crm); } crm.Status = xml.Situacao; //Segmento if (!String.IsNullOrEmpty(xml.Segmento)) { Model.Segmento segmento = new Model.Segmento(this.Organizacao, this.IsOffline); segmento = new Intelbras.CRM2013.Domain.Servicos.SegmentoService(this.Organizacao, this.IsOffline).BuscaSegmento(xml.Segmento); if (segmento != null && segmento.ID.HasValue) { crm.Segmento = new Lookup(segmento.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Segmento não encontrado!"; return(crm); } } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Segmento não enviado."; return(crm); } crm.IntegradoEm = DateTime.Now; crm.IntegradoPor = usuarioIntegracao.NomeCompleto; crm.UsuarioIntegracao = xml.LoginUsuario; #endregion return(crm); }
public void ProdutoSolicitacaoShowRoom(ProdutosdaSolicitacao objProdutoSolicitacao) { #region Verificações de valores if (objProdutoSolicitacao == null) { throw new ArgumentException("(CRM) Produto Solicitação Vazio"); } if (objProdutoSolicitacao.BeneficioPrograma == null) { throw new ArgumentException("(CRM) Campo Benefício de Programa obrigatório"); } if (objProdutoSolicitacao.SolicitacaoBeneficio == null) { throw new ArgumentException("(CRM) Campo Solicitação de Benefício obrigatória"); } #endregion Beneficio benefPrograma = new Intelbras.CRM2013.Domain.Servicos.BeneficioService(RepositoryService).ObterPor(objProdutoSolicitacao.BeneficioPrograma.Id); #region Verificações de valores if (benefPrograma == null) { throw new ArgumentException("(CRM) Benefício do Programa não encontrado"); } #endregion if (benefPrograma.Codigo == (int)Domain.Enum.BeneficiodoPrograma.Codigos.Showroom) { #region Verificações de valores if (objProdutoSolicitacao.Produto == null) { throw new ArgumentException("(CRM) Campo Produto obrigatório"); } #endregion Product produto = new Intelbras.CRM2013.Domain.Servicos.ProdutoService(RepositoryService).ObterPor(objProdutoSolicitacao.Produto.Id); #region Verificações de valores if (produto == null) { throw new ArgumentException("(CRM) Produto " + objProdutoSolicitacao.Produto.Name.ToString() + " não encontrado"); } if (produto.Segmento == null) { throw new ArgumentException("(CRM) Campo segmento do Produto não preenchido,operação cancelada"); } #endregion Segmento objSegmento = new Intelbras.CRM2013.Domain.Servicos.SegmentoService(RepositoryService).ObterPor(produto.Segmento.Id); #region Verificações de valores if (objSegmento == null) { throw new ArgumentException("(CRM) Segmento do Produto não encontrado"); } #endregion ParametroGlobal paramIntervalo = new Intelbras.CRM2013.Domain.Servicos.ParametroGlobalService(RepositoryService).ObterPor((int)Domain.Enum.TipoParametroGlobal.PrazoPermitidoNovaCompraShowroom, null, null, null, null, null, null, null); #region Verificações de valores if (paramIntervalo == null) { throw new ArgumentException("(CRM) Parâmetro Global não encontrado para 'Prazo permitido para nova compra de showroom'.Operação Cancelada"); } #endregion SolicitacaoBeneficio objSolicBenef = new Intelbras.CRM2013.Domain.Servicos.SolicitacaoBeneficioService(RepositoryService).ObterPor(objProdutoSolicitacao.SolicitacaoBeneficio.Id); #region Verificação de valores if (objSolicBenef == null) { throw new ArgumentException("(CRM) Solicitação Benefício não encontrada"); } if (objSolicBenef.BeneficioCanal == null) { throw new ArgumentException("(CRM) Benefício do Canal não encontrado"); } #endregion List <SolicitacaoBeneficio> solicBenef = new Intelbras.CRM2013.Domain.Servicos.SolicitacaoBeneficioService(RepositoryService).ListarPorBeneficioCanalEStatus(objSolicBenef.BeneficioCanal.Id, objSolicBenef.BeneficioPrograma.Id, (int)Enum.SolicitacaoBeneficio.StatusSolicitacaoBeneficio.PagamentoEfetuado); if (solicBenef.Count > 0) { List <SolicitacaoBeneficio> tmpSolicBenef = new List <SolicitacaoBeneficio>(); foreach (SolicitacaoBeneficio item in solicBenef) { //DateTime.Compare(item.DataCriacao, objSolicBenef.DataCriacao); int diferencaDias = Math.Abs(item.DataCriacao.Value.Subtract(objSolicBenef.DataCriacao.Value).Days); if ((diferencaDias >= Convert.ToInt32(paramIntervalo.Valor))) { //Lista com os beneficios que serão verificados tmpSolicBenef.Add(item); } } int qtdMaxima; if (objSegmento.QtdMaximaShowRoom.HasValue) { qtdMaxima = objSegmento.QtdMaximaShowRoom.Value; } else { //Fluxo alternativo 2 ParametroGlobal paramGlobal = new Intelbras.CRM2013.Domain.Servicos.ParametroGlobalService(RepositoryService).ObterPor((int)Domain.Enum.TipoParametroGlobal.QuantidadeKitsShowroomPorSegmento, null, null, null, null, null, null, null); if (paramGlobal == null) { throw new ArgumentException("(CRM) Parâmetro Global não encontrado para Quantidade de Kits para Showroom.Operação Cancelada"); } qtdMaxima = Convert.ToInt32(paramGlobal.Valor); } #region Agrupa Produtos por Segmento do Produto decimal qtdProdutosSegmento = 0; if (tmpSolicBenef.Count > 0) { foreach (var item in tmpSolicBenef) { List <ProdutosdaSolicitacao> produtosSolic = new Intelbras.CRM2013.Domain.Servicos.ProdutosdaSolicitacaoService(RepositoryService).ListarPorSolicitacao(item.ID.Value); if (produtosSolic.Count > 0) { foreach (var produtoSolic in produtosSolic) { if (produtoSolic.Produto == null) { throw new ArgumentException("Produto da Solicitação não cadastrado."); } Product _produto = new Intelbras.CRM2013.Domain.Servicos.ProdutoService(RepositoryService).ObterPor(produtoSolic.Produto.Id); if (_produto == null) { throw new ArgumentException("Produto não encontrado"); } if (_produto.Segmento == null) { throw new ArgumentException("Segmento do Produto " + _produto.Nome + " não preenchido"); } if (_produto.Segmento.Id == objSegmento.ID.Value) { qtdProdutosSegmento += produtoSolic.QuantidadeAprovada.Value; } } } } } #endregion if (qtdProdutosSegmento > qtdMaxima) { throw new ArgumentException("(CRM) Limite de compras de showroom atingido para este segmento.Operação bloqueada."); } } } }