Ejemplo n.º 1
0
        public tb_dependencia BuscarDependenciaPorCodigo(int cod_empresa, int cod_depend, IDaoTransacao transacao = null)
        {
            _log.TraceMethodStart();

            var dao = transacao == null?_factory.GetDaoCorporativo <tb_dependencia>() : _factory.GetDaoCorporativo <tb_dependencia>(transacao);

            tb_dependencia retorno = null;

            if (cod_empresa == null || cod_empresa <= 0)
            {
                throw new ApplicationException("Código da empresa inválido");
            }

            if (cod_depend == null || cod_depend <= 0)
            {
                throw new ApplicationException("Código de dependencia inválido");
            }

            string where = $" cod_empresa = {cod_empresa} and cod_depend = {cod_depend} ";

            var listaEntity = dao.Obter(where);

            if (listaEntity != null && listaEntity.Any())
            {
                retorno = listaEntity.FirstOrDefault();
            }

            _log.TraceMethodEnd();
            return(retorno);
        }
        public void ExcluirOperadorDependencia(int emp_cod, int oper_cod, int dep_cod, IDaoTransacao transacao = null)
        {
            _log.TraceMethodStart();

            if (emp_cod == null || emp_cod <= 0)
            {
                throw new ApplicationException("Código da empresa inválido");
            }

            if (oper_cod == null || oper_cod <= 0)
            {
                throw new ApplicationException("Código do operador inválido");
            }

            if (dep_cod == null || dep_cod <= 0)
            {
                throw new ApplicationException("Código da dependencia inválido");
            }

            tb_empresa empresa = _empresaService.BuscarEmpresaPorCodigo(emp_cod, transacao);

            if (empresa == null)
            {
                throw new ApplicationException("Empresa informada não cadastrada");
            }

            tb_operador operador = _operadorService.BuscarOperadorPorCodigo(emp_cod, oper_cod, transacao);

            if (operador == null)
            {
                throw new ApplicationException("Operador informado não cadastrado");
            }

            tb_dependencia dependencia = _dependenciaService.BuscarDependenciaPorCodigo(emp_cod, oper_cod, transacao);

            if (operador == null)
            {
                throw new ApplicationException("Dependência informado não cadastrado");
            }

            var dao = _factory.GetDaoCorporativo <tb_depope>();

            string where = $" emp_cod = {emp_cod} and oper_cod = {oper_cod} and depend_cod = {dep_cod} ";

            var entityBanco = dao.Obter(where);

            if (entityBanco == null || !entityBanco.Any())
            {
                throw new ApplicationException($"Dados informados não estão cadastrados - empresa: {emp_cod}, operador: {oper_cod} e dependencia: {dep_cod}");
            }

            var entity = entityBanco.FirstOrDefault();

            dao.Remover(entity, where);

            _log.TraceMethodEnd();
        }
        public void EditarOperadorDependencia(tb_depope entity, IDaoTransacao transacao = null)
        {
            _log.TraceMethodStart();

            var dao = transacao == null?_factory.GetDaoCorporativo <tb_depope>() : _factory.GetDaoCorporativo <tb_depope>(transacao);

            if (entity.emp_cod == null || entity.emp_cod.Value <= 0)
            {
                throw new ApplicationException("Código da empresa inválido");
            }

            if (entity.oper_cod == null || entity.oper_cod.Value <= 0)
            {
                throw new ApplicationException("Código do operador inválido");
            }

            if (entity.depend_cod == null || entity.depend_cod.Value <= 0)
            {
                throw new ApplicationException("Código de dependencia inválido");
            }

            tb_empresa empresa = _empresaService.BuscarEmpresaPorCodigo(entity.emp_cod.Value, transacao);

            if (empresa == null)
            {
                throw new ApplicationException("Empresa informada não cadastrada");
            }

            tb_dependencia dependencia = _dependenciaService.BuscarDependenciaPorCodigo(entity.emp_cod.Value, entity.depend_cod.Value, transacao);

            if (dependencia == null)
            {
                throw new ApplicationException("Dependencia informada não cadastrada");
            }

            tb_operador operador = _operadorService.BuscarOperadorPorCodigo(entity.emp_cod.Value, entity.oper_cod.Value, transacao);

            if (dependencia == null)
            {
                throw new ApplicationException("Operador informado não cadastrado");
            }

            string where = $" emp_cod = {entity.emp_cod} and oper_cod = {entity.oper_cod} ";

            var entityBanco = dao.Obter(where);

            if (entityBanco == null || !entityBanco.Any())
            {
                throw new ApplicationException($"Dados informados não foram cadastrados - empresa: {entity.emp_cod} e operador dependencia: {entity.oper_cod} ");
            }

            dao.Atualizar(entity, where);

            _log.TraceMethodEnd();
        }
        public void EditarGrupoEmpresarial(tb_grpemp entity, IDaoTransacao transacao = null)
        {
            _log.TraceMethodStart();

            var dao = _factory.GetDaoCorporativo <tb_grpemp>();

            if (entity.cod_empresa == null || entity.cod_empresa.Value <= 0)
            {
                throw new ApplicationException("Código da empresa inválido");
            }

            if (entity.cod_depend == null || entity.cod_depend.Value <= 0)
            {
                throw new ApplicationException("Código de dependencia inválido");
            }

            tb_empresa empresa = _empresaService.BuscarEmpresaPorCodigo(entity.cod_empresa.Value, transacao);

            if (empresa == null)
            {
                throw new ApplicationException("Empresa informada não cadastrada");
            }

            tb_dependencia dependencia = _dependenciaService.BuscarDependenciaPorCodigo(entity.cod_depend.Value, entity.cod_depend.Value, transacao);

            if (dependencia == null)
            {
                throw new ApplicationException("Dependencia informada não cadastrada");
            }

            string where = $" cod_empresa = {entity.cod_empresa} and cod_grpemp = {entity.cod_grpemp} ";

            var listaEntityBanco = dao.Obter(where);

            if (listaEntityBanco == null || !listaEntityBanco.Any())
            {
                throw new ApplicationException($"Dados informados não foram cadastrados - empresa: {entity.cod_empresa} e grupo empresarial: {entity.cod_grpemp} ");
            }

            var entityBanco = listaEntityBanco.First();

            entityBanco.abv_grpemp = entity.abv_grpemp;
            entityBanco.des_grpemp = entity.des_grpemp;
            entityBanco.cod_depend = entity.cod_depend;

            dao.Atualizar(entityBanco, where);

            _log.TraceMethodEnd();
        }
        public tb_grpemp GravarGrupoEmpresarial(tb_grpemp entity, IDaoTransacao transacao = null)
        {
            _log.TraceMethodStart();

            var dao = _factory.GetDaoCorporativo <tb_grpemp>();

            if (entity.cod_empresa == null || entity.cod_empresa.Value <= 0)
            {
                throw new ApplicationException("Código da empresa inválido");
            }

            if (entity.cod_depend == null || entity.cod_depend.Value <= 0)
            {
                throw new ApplicationException("Código de dependencia inválido");
            }

            tb_empresa empresa = _empresaService.BuscarEmpresaPorCodigo(entity.cod_empresa.Value, transacao);

            if (empresa == null)
            {
                throw new ApplicationException("Empresa informada não cadastrada");
            }

            tb_dependencia dependencia = _dependenciaService.BuscarDependenciaPorCodigo(entity.cod_depend.Value, entity.cod_depend.Value, transacao);

            if (dependencia == null)
            {
                throw new ApplicationException("Dependencia informada não cadastrada");
            }

            string where = $" cod_empresa = {entity.cod_empresa} and cod_grpemp = {entity.cod_grpemp} ";

            var entityBanco = dao.Obter(where);

            if (entityBanco != null && entityBanco.Any())
            {
                throw new ApplicationException($"Dados informados já foram cadastrados - empresa: {entity.cod_empresa} e grupo empresarial: {entity.cod_grpemp} ");
            }

            entity = dao.Inserir(entity);

            _log.TraceMethodEnd();

            return(entity);
        }
Ejemplo n.º 6
0
        public MsgRegistroDependencia tb_depndenciaToMsgDependencia(tb_dependencia tb_dependencia)
        {
            _log.TraceMethodStart();

            MsgRegistroDependencia msg = new MsgRegistroDependencia();

            if (tb_dependencia.cod_empresa != null && tb_dependencia.cod_empresa.Value > 0)
            {
                msg.codigoEmpresa = tb_dependencia.cod_empresa;
            }

            if (tb_dependencia.cod_depend != null && tb_dependencia.cod_depend.Value > 0)
            {
                msg.codigoDependencia = tb_dependencia.cod_depend;
            }

            if (tb_dependencia.cod_municipio != null && tb_dependencia.cod_municipio.Value > 0)
            {
                msg.codigoMunicipio = tb_dependencia.cod_municipio;
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.nom_abv_depend))
            {
                msg.nomeAbreviado = tb_dependencia.nom_abv_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.nom_depend))
            {
                msg.nomeCompleto = tb_dependencia.nom_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.bas_cgc_depend))
            {
                msg.cgcBase = tb_dependencia.bas_cgc_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.fil_cgc_depend))
            {
                msg.cgcFilial = tb_dependencia.fil_cgc_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.dig_cgc_depend))
            {
                msg.cgccDigito = tb_dependencia.dig_cgc_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.tip_log_depend))
            {
                msg.tipoLogradouro = tb_dependencia.tip_log_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.end_depend))
            {
                msg.logradouro = tb_dependencia.end_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.cpl_log_depend))
            {
                msg.complementoLogradouro = tb_dependencia.cpl_log_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.bai_depend))
            {
                msg.descricaoBairro = tb_dependencia.bai_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.cep_depend))
            {
                msg.cep = tb_dependencia.cep_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ddd_fone_depend))
            {
                msg.dddTelefone = tb_dependencia.ddd_fone_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ddd_fone2_depend))
            {
                msg.dddTelefone2 = tb_dependencia.ddd_fone2_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ddd_fone3_depend))
            {
                msg.dddTelefone3 = tb_dependencia.ddd_fone3_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ddd_fone4_depend))
            {
                msg.dddTelefone4 = tb_dependencia.ddd_fone4_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.tel_depend))
            {
                msg.numeroTelefone = tb_dependencia.tel_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.tel_2_depend))
            {
                msg.numeroTelefone2 = tb_dependencia.tel_2_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.tel_3_depend))
            {
                msg.numeroTelefone3 = tb_dependencia.tel_3_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.tel_4_depend))
            {
                msg.numeroTelefone4 = tb_dependencia.tel_4_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ram_depend))
            {
                msg.numeroRamal = tb_dependencia.ram_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ram_2_depend))
            {
                msg.numeroRamal2 = tb_dependencia.ram_2_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ram_3_depend))
            {
                msg.numeroRamal3 = tb_dependencia.ram_3_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ram_4_depend))
            {
                msg.numeroRamal4 = tb_dependencia.ram_4_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ddd_fax_depend))
            {
                msg.dddFax = tb_dependencia.ddd_fax_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ddd_fax2_depend))
            {
                msg.dddFax2 = tb_dependencia.ddd_fax2_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ddd_fax3_depend))
            {
                msg.dddFax3 = tb_dependencia.ddd_fax3_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.fax_depend))
            {
                msg.numeroFax = tb_dependencia.fax_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.fax_2_depend))
            {
                msg.numeroFax2 = tb_dependencia.fax_2_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.fax_3_depend))
            {
                msg.numeroFax3 = tb_dependencia.fax_3_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.eml_depend))
            {
                msg.email = tb_dependencia.eml_depend.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ins_estadual))
            {
                msg.inscricaoEstadual = tb_dependencia.ins_estadual.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.ins_municipal))
            {
                msg.inscricaoMunicipal = tb_dependencia.ins_municipal.TrimEnd();
            }

            if (tb_dependencia.nvl_sup_depend != null && tb_dependencia.nvl_sup_depend.Value > 0)
            {
                msg.nivelHierarquico = tb_dependencia.nvl_sup_depend;
            }

            if (tb_dependencia.nvl_1_depend != null && tb_dependencia.nvl_1_depend.Value > 0)
            {
                msg.nivelHierarquico1 = tb_dependencia.nvl_1_depend;
            }

            if (tb_dependencia.nvl_2_depend != null && tb_dependencia.nvl_2_depend.Value > 0)
            {
                msg.nivelHierarquico2 = tb_dependencia.nvl_2_depend;
            }

            if (tb_dependencia.nvl_3_depend != null && tb_dependencia.nvl_3_depend.Value > 0)
            {
                msg.nivelHierarquico3 = tb_dependencia.nvl_3_depend;
            }

            if (tb_dependencia.nvl_4_depend != null && tb_dependencia.nvl_4_depend.Value > 0)
            {
                msg.nivelHierarquico4 = tb_dependencia.nvl_4_depend;
            }

            if (tb_dependencia.nvl_5_depend != null && tb_dependencia.nvl_5_depend.Value > 0)
            {
                msg.nivelHierarquico5 = tb_dependencia.nvl_5_depend;
            }

            if (tb_dependencia.nvl_6_depend != null && tb_dependencia.nvl_6_depend.Value > 0)
            {
                msg.nivelHierarquico6 = tb_dependencia.nvl_6_depend;
            }

            if (tb_dependencia.nvl_7_depend != null && tb_dependencia.nvl_7_depend.Value > 0)
            {
                msg.nivelHierarquico7 = tb_dependencia.nvl_7_depend;
            }

            if (tb_dependencia.nvl_8_depend != null && tb_dependencia.nvl_8_depend.Value > 0)
            {
                msg.nivelHierarquico8 = tb_dependencia.nvl_8_depend;
            }

            if (tb_dependencia.nvl_9_depend != null && tb_dependencia.nvl_9_depend.Value > 0)
            {
                msg.nivelHierarquico9 = tb_dependencia.nvl_9_depend;
            }

            if (tb_dependencia.nvl_10_depend != null && tb_dependencia.nvl_10_depend.Value > 0)
            {
                msg.nivelHierarquico10 = tb_dependencia.nvl_10_depend;
            }

            if (tb_dependencia.dat_ini_depend != null && tb_dependencia.dat_ini_depend.Value != DateTime.MinValue)
            {
                msg.dataInicioOperacao = tb_dependencia.dat_ini_depend;
            }

            if (tb_dependencia.dat_fim_depend != null && tb_dependencia.dat_fim_depend.Value != DateTime.MinValue)
            {
                msg.dataFimOperacao = tb_dependencia.dat_fim_depend;
            }

            if (tb_dependencia.dat_cad != null && tb_dependencia.dat_cad.Value != DateTime.MinValue)
            {
                msg.dataCadastro = tb_dependencia.dat_cad;
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.usu_atu))
            {
                msg.usuarioUltimaAtualizacao = tb_dependencia.usu_atu.TrimEnd();
            }

            if (tb_dependencia.dat_atu != null && tb_dependencia.dat_atu.Value != DateTime.MinValue)
            {
                msg.dataAtualizacao = tb_dependencia.dat_atu;
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.idc_sit))
            {
                msg.indicadorSituacao = tb_dependencia.idc_sit.TrimEnd();
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.tip_tpdepend))
            {
                msg.tipoDependencia = tb_dependencia.tip_tpdepend.TrimEnd();
            }

            if (tb_dependencia.cod_camara != null && tb_dependencia.cod_camara.Value > 0)
            {
                msg.codigoCamaraCompensacao = tb_dependencia.cod_camara;
            }

            if (!string.IsNullOrWhiteSpace(tb_dependencia.num_log_depend))
            {
                msg.numeroLogradouro = tb_dependencia.num_log_depend.TrimEnd();
            }

            if (tb_dependencia.dat_rollout != null && tb_dependencia.dat_rollout.Value != DateTime.MinValue)
            {
                msg.dataRollOut = tb_dependencia.dat_rollout;
            }

            if (tb_dependencia.dat_sit != null && tb_dependencia.dat_sit.Value != DateTime.MinValue)
            {
                msg.dataSituacao = tb_dependencia.dat_sit;
            }

            _log.TraceMethodEnd();

            return(msg);
        }
Ejemplo n.º 7
0
        public tb_dependencia AdaptarMsgDependenciaTotb_dependencia(MsgRegistroDependencia msg, string modo)
        {
            _log.TraceMethodStart();

            tb_dependencia tb_dependencia = new tb_dependencia();

            if (msg.codigoEmpresa != null && msg.codigoEmpresa.Value > 0)
            {
                tb_dependencia.cod_empresa = msg.codigoEmpresa;
            }

            if (msg.codigoDependencia != null && msg.codigoDependencia.Value > 0)
            {
                tb_dependencia.cod_depend = msg.codigoDependencia;
            }

            if (msg.codigoMunicipio != null && msg.codigoMunicipio.Value > 0)
            {
                tb_dependencia.cod_municipio = msg.codigoMunicipio;
            }

            if (!string.IsNullOrWhiteSpace(msg.nomeAbreviado))
            {
                tb_dependencia.nom_abv_depend = msg.nomeAbreviado;
            }

            if (!string.IsNullOrWhiteSpace(msg.nomeCompleto))
            {
                tb_dependencia.nom_depend = msg.nomeCompleto;
            }

            if (!string.IsNullOrWhiteSpace(msg.cgcBase))
            {
                tb_dependencia.bas_cgc_depend = msg.cgcBase;
            }

            if (!string.IsNullOrWhiteSpace(msg.cgcFilial))
            {
                tb_dependencia.fil_cgc_depend = msg.cgcFilial;
            }

            if (!string.IsNullOrWhiteSpace(msg.cgccDigito))
            {
                tb_dependencia.dig_cgc_depend = msg.cgccDigito;
            }

            if (!string.IsNullOrWhiteSpace(msg.tipoLogradouro))
            {
                tb_dependencia.tip_log_depend = msg.tipoLogradouro;
            }

            if (!string.IsNullOrWhiteSpace(msg.logradouro))
            {
                tb_dependencia.end_depend = msg.logradouro;
            }

            if (!string.IsNullOrWhiteSpace(msg.complementoLogradouro))
            {
                tb_dependencia.cpl_log_depend = msg.complementoLogradouro;
            }

            if (!string.IsNullOrWhiteSpace(msg.descricaoBairro))
            {
                tb_dependencia.bai_depend = msg.descricaoBairro;
            }

            if (!string.IsNullOrWhiteSpace(msg.cep))
            {
                tb_dependencia.cep_depend = msg.cep;
            }

            if (!string.IsNullOrWhiteSpace(msg.dddTelefone))
            {
                tb_dependencia.ddd_fone_depend = msg.dddTelefone;
            }

            if (!string.IsNullOrWhiteSpace(msg.dddTelefone2))
            {
                tb_dependencia.ddd_fone2_depend = msg.dddTelefone2;
            }

            if (!string.IsNullOrWhiteSpace(msg.dddTelefone3))
            {
                tb_dependencia.ddd_fone3_depend = msg.dddTelefone3;
            }

            if (!string.IsNullOrWhiteSpace(msg.dddTelefone4))
            {
                tb_dependencia.ddd_fone4_depend = msg.dddTelefone4;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroTelefone))
            {
                tb_dependencia.tel_depend = msg.numeroTelefone;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroTelefone2))
            {
                tb_dependencia.tel_2_depend = msg.numeroTelefone2;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroTelefone3))
            {
                tb_dependencia.tel_3_depend = msg.numeroTelefone3;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroTelefone4))
            {
                tb_dependencia.tel_4_depend = msg.numeroTelefone4;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroRamal))
            {
                tb_dependencia.ram_depend = msg.numeroRamal;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroRamal2))
            {
                tb_dependencia.ram_2_depend = msg.numeroRamal2;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroRamal3))
            {
                tb_dependencia.ram_3_depend = msg.numeroRamal3;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroRamal4))
            {
                tb_dependencia.ram_4_depend = msg.numeroRamal4;
            }

            if (!string.IsNullOrWhiteSpace(msg.dddFax))
            {
                tb_dependencia.ddd_fax_depend = msg.dddFax;
            }

            if (!string.IsNullOrWhiteSpace(msg.dddFax2))
            {
                tb_dependencia.ddd_fax2_depend = msg.dddFax2;
            }

            if (!string.IsNullOrWhiteSpace(msg.dddFax3))
            {
                tb_dependencia.ddd_fax3_depend = msg.dddFax3;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroFax))
            {
                tb_dependencia.fax_depend = msg.numeroFax;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroFax2))
            {
                tb_dependencia.fax_2_depend = msg.numeroFax2;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroFax3))
            {
                tb_dependencia.fax_3_depend = msg.numeroFax3;
            }

            if (!string.IsNullOrWhiteSpace(msg.email))
            {
                tb_dependencia.eml_depend = msg.email;
            }

            if (!string.IsNullOrWhiteSpace(msg.inscricaoEstadual))
            {
                tb_dependencia.ins_estadual = msg.inscricaoEstadual;
            }

            if (!string.IsNullOrWhiteSpace(msg.inscricaoMunicipal))
            {
                tb_dependencia.ins_municipal = msg.inscricaoMunicipal;
            }

            if (msg.nivelHierarquico != null && msg.nivelHierarquico.Value > 0)
            {
                tb_dependencia.nvl_sup_depend = msg.nivelHierarquico;
            }

            if (msg.nivelHierarquico1 != null && msg.nivelHierarquico1.Value > 0)
            {
                tb_dependencia.nvl_1_depend = msg.nivelHierarquico1;
            }

            if (msg.nivelHierarquico2 != null && msg.nivelHierarquico2.Value > 0)
            {
                tb_dependencia.nvl_2_depend = msg.nivelHierarquico2;
            }

            if (msg.nivelHierarquico3 != null && msg.nivelHierarquico3.Value > 0)
            {
                tb_dependencia.nvl_3_depend = msg.nivelHierarquico3;
            }

            if (msg.nivelHierarquico4 != null && msg.nivelHierarquico4.Value > 0)
            {
                tb_dependencia.nvl_4_depend = msg.nivelHierarquico4;
            }

            if (msg.nivelHierarquico5 != null && msg.nivelHierarquico5.Value > 0)
            {
                tb_dependencia.nvl_5_depend = msg.nivelHierarquico5;
            }

            if (msg.nivelHierarquico6 != null && msg.nivelHierarquico6.Value > 0)
            {
                tb_dependencia.nvl_6_depend = msg.nivelHierarquico6;
            }

            if (msg.nivelHierarquico7 != null && msg.nivelHierarquico7.Value > 0)
            {
                tb_dependencia.nvl_7_depend = msg.nivelHierarquico7;
            }

            if (msg.nivelHierarquico8 != null && msg.nivelHierarquico8.Value > 0)
            {
                tb_dependencia.nvl_8_depend = msg.nivelHierarquico8;
            }

            if (msg.nivelHierarquico9 != null && msg.nivelHierarquico9.Value > 0)
            {
                tb_dependencia.nvl_9_depend = msg.nivelHierarquico9;
            }

            if (msg.nivelHierarquico10 != null && msg.nivelHierarquico10.Value > 0)
            {
                tb_dependencia.nvl_10_depend = msg.nivelHierarquico10;
            }

            if (msg.dataInicioOperacao != null && msg.dataInicioOperacao.Value != DateTime.MinValue)
            {
                tb_dependencia.dat_ini_depend = msg.dataInicioOperacao;
            }

            if (msg.dataFimOperacao != null && msg.dataFimOperacao.Value != DateTime.MinValue)
            {
                tb_dependencia.dat_fim_depend = msg.dataFimOperacao;
            }

            if (msg.dataCadastro != null && msg.dataCadastro.Value != DateTime.MinValue)
            {
                tb_dependencia.dat_cad = msg.dataCadastro;
            }

            if (!string.IsNullOrWhiteSpace(msg.usuarioUltimaAtualizacao))
            {
                tb_dependencia.usu_atu = msg.usuarioUltimaAtualizacao;
            }

            if (msg.dataAtualizacao != null && msg.dataAtualizacao.Value != DateTime.MinValue)
            {
                tb_dependencia.dat_atu = msg.dataAtualizacao;
            }

            if (!string.IsNullOrWhiteSpace(msg.indicadorSituacao))
            {
                tb_dependencia.idc_sit = msg.indicadorSituacao;
            }

            if (!string.IsNullOrWhiteSpace(msg.tipoDependencia))
            {
                tb_dependencia.tip_tpdepend = msg.tipoDependencia.ToUpper();
            }

            if (msg.codigoCamaraCompensacao != null && msg.codigoCamaraCompensacao.Value > 0)
            {
                tb_dependencia.cod_camara = msg.codigoCamaraCompensacao;
            }

            if (!string.IsNullOrWhiteSpace(msg.numeroLogradouro))
            {
                tb_dependencia.num_log_depend = msg.numeroLogradouro;
            }

            if (msg.dataRollOut != null && msg.dataRollOut.Value != DateTime.MinValue)
            {
                tb_dependencia.dat_rollout = msg.dataRollOut;
            }

            if (msg.dataSituacao != null && msg.dataSituacao.Value != DateTime.MinValue)
            {
                tb_dependencia.dat_sit = msg.dataSituacao;
            }

            _log.TraceMethodEnd();

            return(tb_dependencia);
        }
Ejemplo n.º 8
0
        public tb_dependencia GravarDependencia(tb_dependencia entity, IDaoTransacao transacao = null)
        {
            _log.TraceMethodStart();

            var dao = transacao == null?_factory.GetDaoCorporativo <tb_dependencia>() : _factory.GetDaoCorporativo <tb_dependencia>(transacao);

            if (entity.cod_empresa == null || entity.cod_empresa.Value <= 0)
            {
                throw new ApplicationException("Código da empresa inválido");
            }

            tb_empresa empresa = _empresaService.BuscarEmpresaPorCodigo(entity.cod_empresa.Value, transacao);

            if (empresa == null)
            {
                throw new ApplicationException("Empresa informada não cadastrada");
            }

            var entityBanco = dao.ObterPrimeiro($" cod_empresa = {entity.cod_empresa} and cod_depend = {entity.cod_depend} ");

            if (entityBanco != null)
            {
                throw new ApplicationException($"Dados informados já foram cadastrados - empresa: {entity.cod_empresa} e dependência: {entity.cod_depend} ");
            }

            if (entity.cod_municipio != null)
            {
                var daoMunicipio = _factory.GetDaoCorporativo <tb_municipio>(transacao);
                var municipio    = daoMunicipio.ObterPrimeiro($" cod_municipio = {entity.cod_municipio} ");
                if (municipio == null)
                {
                    throw new ApplicationException("Município não encontrado na base de dados");
                }
            }
            else
            {
                throw new ApplicationException("Município obrigatório");
            }

            if (entity.tip_tpdepend != null)
            {
                var daoTpDepend = _factory.GetDaoCorporativo <tb_tpdepend>(transacao);
                var tipoDepend  = daoTpDepend.ObterPrimeiro($" tip_tpdepend  = '{entity.tip_tpdepend}' ");
                if (tipoDepend == null)
                {
                    throw new ApplicationException("Tipo de dependência inválido");
                }
            }
            else
            {
                throw new ApplicationException("Tipo de dependência obrigatório");
            }

            if (entity.idc_sit != null)
            {
                if (!entity.idc_sit.ToUpper().Equals(tb_dependencia.situacaoAtivo) &&
                    !entity.idc_sit.ToUpper().Equals(tb_dependencia.situacaoInativo))
                {
                    throw new ApplicationException("Campo indicador de situação inválido");
                }
            }
            else
            {
                throw new ApplicationException("Campo indicador de situação obrigatório");
            }

            if (entity.cod_camara != null)
            {
                var daoCamara = _factory.GetDaoCorporativo <tb_camara>(transacao);
                var camara    = daoCamara.ObterPrimeiro($" cod_camara = {entity.cod_camara} ");
                if (camara == null)
                {
                    throw new ApplicationException("Código de camara de compensação inválido");
                }
            }

            if (entity.dat_cad == null || entity.dat_cad == DateTime.MinValue)
            {
                entity.dat_cad = DateTime.Now;
            }

            if (entity.dat_atu == null || entity.dat_atu == DateTime.MinValue)
            {
                entity.dat_atu = DateTime.Now;
            }

            entity = dao.Inserir(entity);

            _log.TraceMethodEnd();

            return(entity);
        }
Ejemplo n.º 9
0
        public void EditarDependencia(tb_dependencia entity, IDaoTransacao transacao = null)
        {
            _log.TraceMethodStart();

            var dao = transacao == null?_factory.GetDaoCorporativo <tb_dependencia>() : _factory.GetDaoCorporativo <tb_dependencia>(transacao);

            if (entity.cod_empresa == null || entity.cod_empresa.Value <= 0)
            {
                throw new ApplicationException("Código da empresa inválido");
            }

            tb_empresa empresa = _empresaService.BuscarEmpresaPorCodigo(entity.cod_empresa.Value, transacao);

            if (empresa == null)
            {
                throw new ApplicationException("Empresa informada não cadastrada");
            }

            if (entity.cod_municipio != null)
            {
                var daoMunicipio = _factory.GetDaoCorporativo <tb_municipio>(transacao);
                var municipio    = daoMunicipio.ObterPrimeiro($" cod_municipio = {entity.cod_municipio} ");
                if (municipio == null)
                {
                    throw new ApplicationException("Município não encontrado na base de dados");
                }
            }
            else
            {
                throw new ApplicationException("Município obrigatório");
            }

            if (entity.tip_tpdepend != null)
            {
                var daoTpDepend = _factory.GetDaoCorporativo <tb_tpdepend>(transacao);
                var tipoDepend  = daoTpDepend.ObterPrimeiro($" tip_tpdepend  = '{entity.tip_tpdepend}' ");
                if (tipoDepend == null)
                {
                    throw new ApplicationException("Tipo de dependência inválido");
                }
            }
            else
            {
                throw new ApplicationException("Tipo de dependência obrigatório");
            }

            if (entity.idc_sit != null)
            {
                if (!entity.idc_sit.ToUpper().Equals(tb_dependencia.situacaoAtivo) &&
                    !entity.idc_sit.ToUpper().Equals(tb_dependencia.situacaoInativo))
                {
                    throw new ApplicationException("Campo indicador de situação inválido");
                }
            }
            else
            {
                throw new ApplicationException("Campo indicador de situação obrigatório");
            }

            string where = $" cod_empresa = {entity.cod_empresa} and cod_depend = {entity.cod_depend} ";

            var listaEntityBanco = dao.Obter(where);

            if (listaEntityBanco == null || !listaEntityBanco.Any())
            {
                throw new ApplicationException($"Dados informados não foram cadastrados - empresa: {entity.cod_empresa} e dependência: {entity.cod_depend} ");
            }

            var entityBanco = listaEntityBanco.First();

            entityBanco.cod_municipio    = entity.cod_municipio;
            entityBanco.nom_abv_depend   = entity.nom_abv_depend;
            entityBanco.nom_depend       = entity.nom_depend;
            entityBanco.bas_cgc_depend   = entity.bas_cgc_depend;
            entityBanco.fil_cgc_depend   = entity.fil_cgc_depend;
            entityBanco.dig_cgc_depend   = entity.dig_cgc_depend;
            entityBanco.tip_log_depend   = entity.tip_log_depend;
            entityBanco.end_depend       = entity.end_depend;
            entityBanco.cpl_log_depend   = entity.cpl_log_depend;
            entityBanco.bai_depend       = entity.bai_depend;
            entityBanco.cep_depend       = entity.cep_depend;
            entityBanco.ddd_fone_depend  = entity.ddd_fone_depend;
            entityBanco.ddd_fone2_depend = entity.ddd_fone2_depend;
            entityBanco.ddd_fone3_depend = entity.ddd_fone3_depend;
            entityBanco.ddd_fone4_depend = entity.ddd_fone4_depend;
            entityBanco.tel_depend       = entity.tel_depend;
            entityBanco.tel_2_depend     = entity.tel_2_depend;
            entityBanco.tel_3_depend     = entity.tel_3_depend;
            entityBanco.tel_4_depend     = entity.tel_4_depend;
            entityBanco.ram_depend       = entity.ram_depend;
            entityBanco.ram_2_depend     = entity.ram_2_depend;
            entityBanco.ram_3_depend     = entity.ram_3_depend;
            entityBanco.ram_4_depend     = entity.ram_4_depend;
            entityBanco.ddd_fax_depend   = entity.ddd_fax_depend;
            entityBanco.ddd_fax2_depend  = entity.ddd_fax2_depend;
            entityBanco.ddd_fax3_depend  = entity.ddd_fax3_depend;
            entityBanco.fax_depend       = entity.fax_depend;
            entityBanco.fax_2_depend     = entity.fax_2_depend;
            entityBanco.fax_3_depend     = entity.fax_3_depend;
            entityBanco.eml_depend       = entity.eml_depend;
            entityBanco.ins_estadual     = entity.ins_estadual;
            entityBanco.ins_municipal    = entity.ins_municipal;
            entityBanco.nvl_sup_depend   = entity.nvl_sup_depend;
            entityBanco.nvl_1_depend     = entity.nvl_1_depend;
            entityBanco.nvl_2_depend     = entity.nvl_2_depend;
            entityBanco.nvl_3_depend     = entity.nvl_3_depend;
            entityBanco.nvl_4_depend     = entity.nvl_4_depend;
            entityBanco.nvl_5_depend     = entity.nvl_5_depend;
            entityBanco.nvl_6_depend     = entity.nvl_6_depend;
            entityBanco.nvl_7_depend     = entity.nvl_7_depend;
            entityBanco.nvl_8_depend     = entity.nvl_8_depend;
            entityBanco.nvl_9_depend     = entity.nvl_9_depend;
            entityBanco.nvl_10_depend    = entity.nvl_10_depend;
            entityBanco.dat_ini_depend   = entity.dat_ini_depend;
            entityBanco.dat_fim_depend   = entity.dat_fim_depend;

            entityBanco.usu_atu = entity.usu_atu;
            if (entity.dat_atu == null || entity.dat_atu == DateTime.MinValue)
            {
                entityBanco.dat_atu = DateTime.Now;
            }

            entityBanco.idc_sit        = entity.idc_sit;
            entityBanco.tip_tpdepend   = entity.tip_tpdepend;
            entityBanco.cod_camara     = entity.cod_camara;
            entityBanco.num_log_depend = entity.num_log_depend;
            entityBanco.dat_rollout    = entity.dat_rollout;
            entityBanco.dat_sit        = entity.dat_sit;

            dao.Atualizar(entity, where);

            _log.TraceMethodEnd();
        }
Ejemplo n.º 10
0
        public ActionResult postDependencia([FromBody] MsgDependencia msg)
        {
            List <string> listaErros = new List <string>();
            MsgRetorno    retorno;

            try
            {
                _log.TraceMethodStart();

                if (msg == null)
                {
                    throw new ApplicationException("Mensagem inválida");
                }
                if (msg.header == null)
                {
                    throw new ApplicationException("Mensagem inválida - chave header não informada");
                }
                if (msg.body == null)
                {
                    throw new ApplicationException("Mensagem inválida - chave body não informada");
                }
                if (msg.body.RegistroDependencia == null)
                {
                    throw new ApplicationException("Mensagem inválida - corpo da mensagem não informado");
                }

                if (string.IsNullOrWhiteSpace(msg.header.identificadorEnvio))
                {
                    msg.header.identificadorEnvio = Util.GerarIdentificadorUnico();
                }

                _log.Information($"Iniciando o processamento da mensagem [post] com o identificador {msg.header.identificadorEnvio}");
                _log.SetIdentificador(msg.header.identificadorEnvio);

                if (!Util.ValidarApiKey(Request, _configuracaoBaseAPI))
                {
                    return(StatusCode((int)HttpStatusCode.Unauthorized));
                }

                listaErros = Util.ValidarModel(ModelState);
                if (listaErros.Any())
                {
                    retorno = _adaptador.AdaptarMsgRetorno(msg, listaErros);

                    _log.TraceMethodEnd();
                    return(StatusCode((int)HttpStatusCode.BadRequest, retorno));
                }

                tb_dependencia tb_dependencia = _adaptador.AdaptarMsgDependenciaTotb_dependencia(msg.body.RegistroDependencia, ConstantesIntegracao.ModoIntegracao.ModoInclusao);

                _ServiceDependencia.GravarDependencia(tb_dependencia);

                retorno = _adaptador.AdaptarMsgRetorno(msg, listaErros);

                _log.TraceMethodEnd();
                return(StatusCode((int)HttpStatusCode.OK, retorno));
            }
            catch (LogErrorException LogEx)
            {
                listaErros.Add(LogEx.Message);
                retorno = _adaptador.AdaptarMsgRetorno(msg, listaErros);
                return(StatusCode((int)HttpStatusCode.InternalServerError, retorno));
            }
            catch (ApplicationException appEx)
            {
                listaErros.Add(appEx.Message);
                retorno = _adaptador.AdaptarMsgRetorno(msg, listaErros);

                _log.Error(appEx);
                _log.TraceMethodEnd();
                return(StatusCode((int)HttpStatusCode.BadRequest, retorno));
            }
            catch (Exception ex)
            {
                listaErros.Add(ex.Message);
                retorno = _adaptador.AdaptarMsgRetorno(msg, listaErros);

                _log.Error(ex);
                _log.TraceMethodEnd();
                return(StatusCode((int)HttpStatusCode.InternalServerError, retorno));
            }
        }