Пример #1
0
        public Segurado Obter(Guid id)
        {
            StringBuilder sql      = new StringBuilder();
            Segurado      segurado = null;

            sql.Append($@"SELECT 
                        Nome,
                        CPF,
                        Idade
                        FROM Segurado 
                        WHERE Id = @Id");

            using (var conn = new SqlConnection(ConnectionString.Conexao))
            {
                try
                {
                    var         parametros = new DynamicParameters(new { id });
                    IDataReader reader     = conn.ExecuteReader(sql.ToString(), parametros);

                    while (reader.Read())
                    {
                        segurado = new Segurado(reader["Nome"].ToString(),
                                                reader["CPF"].ToString(),
                                                int.Parse(reader["Idade"].ToString()));
                    }
                }
                catch (SqlException ex) {  }
            }

            return(segurado);
        }
Пример #2
0
        public Pessoa CerregaModeloPessoa(int id_pessoa)
        {
            Segurado     modelo = new Segurado();
            MySqlCommand com    = new MySqlCommand();

            com.Connection  = conexao.Conexao;
            com.CommandText = "select * from pessoa where id_pessoa = @id_pessoa;";
            com.Parameters.AddWithValue("@id_pessoa", id_pessoa);
            conexao.Conectar();
            MySqlDataReader registro = com.ExecuteReader();

            if (registro.HasRows)
            {
                registro.Read();
                modelo.Id_pessoa       = Convert.ToInt32(registro["id_pessoa"]);
                modelo.Nome            = Convert.ToString(registro["nome"]);
                modelo.Data_nascimento = Convert.ToDateTime(registro["data_nascimento"]);
                modelo.Sexo            = Convert.ToString(registro["sexo"]);
                modelo.Estado_civil    = Convert.ToString(registro["estado_civil"]);
                modelo.Fone            = Convert.ToString(registro["fone"]);
                modelo.Celular         = Convert.ToString(registro["celular"]);
                modelo.End.Cep         = Convert.ToString(registro["cep"]);
                modelo.End.Logradouro  = Convert.ToString(registro["logradouro"]);
                modelo.End.Bairro      = Convert.ToString(registro["bairro"]);
                modelo.End.Localidade  = Convert.ToString(registro["localidade"]);
                modelo.End.Uf          = Convert.ToString(registro["uf"]);
            }
            conexao.Desconectar();
            return(modelo);
        }
Пример #3
0
        //[HttpPost]
        public ActionResult Index()
        {
            ViewBag.Title = "Seguro";

            string cpf          = Request.Form["cpf"];
            string marcaModelo  = Request.Form["marcaModelo"];
            double valorVeiculo = Convert.ToDouble(Request.Form["valor"]);

            Segurado segurado = GetSegurado(cpf);

            double valorSeguro = CalculaSeguro(valorVeiculo);

            Seguro seguro = new Seguro()
            {
                IdSegurado   = segurado.Id,
                MarcaModelo  = marcaModelo,
                ValorVeiculo = valorVeiculo,
                ValorSeguro  = Math.Round(valorSeguro, 2)
            };

            GravaSeguro(seguro);

            ViewBag.Segurado = segurado;
            ViewBag.Seguro   = seguro;
            return(View());
        }
Пример #4
0
 public Seguro(Veiculo veiculo,
               Segurado segurado)
     : this()
 {
     Veiculo  = veiculo;
     Segurado = segurado;
 }
Пример #5
0
        private Segurado GetSegurado(string cpf)
        {
            ConsultaSegurado cs       = new ConsultaSegurado();
            Segurado         segurado = Task.Run(() => cs.GetSegurado(cpf)).Result;

            return(segurado);
        }
        public int Inserir(Guid idVeiculo, Guid IdSegurado)
        {
            Veiculo  veiculo  = null;
            Segurado segurado = null;

            Objeto.Seguro seguro    = null;
            int           resultado = 0;

            if (!object.Equals(idVeiculo, null))
            {
                veiculo = _veiculoRep.Obter(idVeiculo);
            }

            if (!object.Equals(IdSegurado, null))
            {
                segurado = _seguradoRep.Obter(IdSegurado);
            }

            if (!object.Equals(idVeiculo, null) && !object.Equals(IdSegurado, null))
            {
                seguro    = new Objeto.Seguro(veiculo, segurado);
                resultado = _seguroRep.Inserir(seguro);
            }

            return(resultado);
        }
Пример #7
0
 public void Update(Segurado segurado)
 {
     using (OracleConnection connection = new OracleConnection(_ConnectionString))
     {
         try
         {
             connection.Open();
             OracleParameter[] prm     = new OracleParameter[4];
             OracleCommand     command = connection.CreateCommand();
             prm[0] = command.Parameters.Add("NOME", OracleDbType.Varchar2, segurado.Nome, ParameterDirection.Input);
             prm[1] = command.Parameters.Add("CPF", OracleDbType.Varchar2, segurado.Cpf, ParameterDirection.Input);
             prm[2] = command.Parameters.Add("IDADE", OracleDbType.Varchar2, segurado.Idade, ParameterDirection.Input);
             prm[3] = command.Parameters.Add("ID", OracleDbType.Decimal, segurado.Id, ParameterDirection.Input);
             command.CommandText = "UPDATE SEGURADO SET NOME = :1 , CPF = :2 , IDADE = :3 WHERE ID = :4";
             command.Connection  = connection;
             command.ExecuteReader();
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             connection.Close();
         }
     }
 }
Пример #8
0
        public Segurado FindById(int id)
        {
            var segurado = new Segurado();

            using (OracleConnection connection = new OracleConnection(_ConnectionString))
            {
                try
                {
                    connection.Open();
                    OracleParameter[] prm     = new OracleParameter[1];
                    OracleCommand     command = connection.CreateCommand();
                    prm[0] = command.Parameters.Add("ID", OracleDbType.Decimal, id, ParameterDirection.Input);
                    command.CommandText = "SELECT * FROM SEGURADO WHERE ID = :1";
                    command.ExecuteNonQuery();
                    OracleDataReader dr = command.ExecuteReader();
                    while (dr.Read())
                    {
                        segurado.Id    = Convert.ToInt32(dr["ID"]);
                        segurado.Nome  = dr["NOME"].ToString();
                        segurado.Cpf   = dr["CPF"].ToString();
                        segurado.Idade = dr["IDADE"].ToString();
                    }
                    dr.Close();
                    return(segurado);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
Пример #9
0
        public SeguroOutput ConsultarSeguro(string CPF)
        {
            Segurado segurado = _ISeguradoRep.Consultar(CPF);

            if (segurado == null)
            {
                return(new SeguroOutput(EStatusCode.NotFound, " Não foi encontrado registros para este CPF."));
            }
            if (segurado.Invalid)
            {
                return(new SeguroOutput(EStatusCode.InternalError, segurado.Notifications));
            }

            var SeguroResult = _ISeguroRep.ConsultarSeguro(CPF);

            if (SeguroResult == null)
            {
                return(new SeguroOutput(EStatusCode.NotFound, " Não foi encontrado registros para este CPF."));
            }
            Veiculo veiculo = new Veiculo((SeguroResult.Value as Seguro).Veiculo.Carro);

            if (veiculo.Invalid)
            {
                return(new SeguroOutput(EStatusCode.InternalError, veiculo.Notifications));
            }

            var seguro = new Seguro(segurado, veiculo);

            return(new SeguroOutput(EStatusCode.OK, seguro));
        }
 public static SeguradoDetalhado FromSegurado(Segurado segurado)
 {
     return(new SeguradoDetalhado(
                segurado.Codigo,
                segurado.Nome.Nome,
                segurado.Nome.Sobrenome,
                segurado.DataNascimento.Data));
 }
Пример #11
0
        public void Incluir(Segurado segurado)
        {
            try
            {
                MySqlCommand com = new MySqlCommand();
                com.Connection  = conexao.Conexao;
                com.CommandText = "insert into pessoa(nome, data_nascimento, sexo, estado_civil, fone, celular," +
                                  "cep, logradouro, bairro, localidade, uf) values (@nome, @data_nascimento, @sexo, @estado_civil," +
                                  "@fone, @celular, @cep, @logradouro, @bairro, @localidade, @uf); select @@IDENTITY;";
                com.Parameters.AddWithValue("@nome", segurado.Nome);
                com.Parameters.AddWithValue("@data_nascimento", segurado.Data_nascimento);
                com.Parameters.AddWithValue("@sexo", segurado.Sexo);
                com.Parameters.AddWithValue("@estado_civil", segurado.Estado_civil);
                com.Parameters.AddWithValue("@fone", segurado.Fone);
                com.Parameters.AddWithValue("@celular", segurado.Celular);
                com.Parameters.AddWithValue("@cep", segurado.End.Cep);
                com.Parameters.AddWithValue("@logradouro", segurado.End.Logradouro);
                com.Parameters.AddWithValue("@bairro", segurado.End.Bairro);
                com.Parameters.AddWithValue("@localidade", segurado.End.Localidade);
                com.Parameters.AddWithValue("@uf", segurado.End.Uf);
                conexao.Conectar();
                segurado.Id_pessoa = Convert.ToInt32(com.ExecuteScalar());
                ID_segurado        = segurado.Id_pessoa;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexao.Desconectar();
            }


            try
            {
                MySqlCommand com = new MySqlCommand();
                com.Connection  = conexao.Conexao;
                com.CommandText = "insert into segurado(escolaridade, estudante, periodo, profissao, nome_banco, id_pessoa)" +
                                  " values(@escolaridade, @estudante, @periodo, @profissao, @nome_banco, @id_pessoa); select @@IDENTITY; ";
                com.Parameters.AddWithValue("@escolaridade", segurado.Escolaridade);
                com.Parameters.AddWithValue("@estudante", segurado.Estudante);
                com.Parameters.AddWithValue("@periodo", segurado.Periodo);
                com.Parameters.AddWithValue("@profissao", segurado.Profissao);
                com.Parameters.AddWithValue("@nome_banco", segurado.Nome_banco);
                com.Parameters.AddWithValue("@id_pessoa", segurado.Id_pessoa);
                conexao.Conectar();
                segurado.Id_segurado = Convert.ToInt32(com.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexao.Desconectar();
            }
        }
 public static SeguradoGetDto ToSeguradoGetDto(Segurado segurado)
 {
     return(new SeguradoGetDto()
     {
         Id = segurado.Id,
         Nome = segurado.Nome,
         CPF = segurado.CPF,
         Idade = segurado.Idade
     });
 }
Пример #13
0
        public void Test_MaiorIdade_Valido()
        {
            Segurado _segurado;

            _segurado = new Segurado("XXXXX", new DateTime(1988, 9, 29), "XXX", "XXXX", "XXXXX", "XXXXX");
            _segurado.Validar();
            var message = _segurado.ValidationResult.Errors.Where(d => d.ErrorMessage == "É Preciso ser Maior de 18!").Select(e => e.ErrorMessage).FirstOrDefault();

            Assert.Null(message);
        }
Пример #14
0
        public static Segurado GetSegurado()
        {
            Segurado seg = new Segurado();

            seg.LimiteFinanceiro = GetLimiteFin();

            seg.NomeSegurado      = "Pedro Pedrosa Pedroso";
            seg.NrCPFCNPJSegurado = 12345678910;

            return(seg);
        }
Пример #15
0
 public ActionResult Put(int id, [FromBody] Segurado segurado)
 {
     try
     {
         repositorioSegurado.Atualizar(id, segurado);
         return(Ok(repositorioSegurado.PesquisarPorId(id)));
     }
     catch (Exception exception)
     {
         return(BadRequest(exception.Message));
     }
 }
Пример #16
0
 public ActionResult Edit(Segurado segurado)
 {
     try
     {
         _seguradoService.Update(segurado);
         return(RedirectToAction(nameof(Index)));
     }
     catch (NotFoundException)
     {
         return(HttpNotFound());
     }
 }
Пример #17
0
 public ActionResult Post([FromBody] Segurado segurado)
 {
     try
     {
         repositorioSegurado.Adicionar(segurado);
         return(Ok(segurado));
     }
     catch (Exception exception)
     {
         return(BadRequest(exception.Message));
     }
 }
 public static SeguroGetDto ToSeguroGetDto(Seguro seguro, Segurado segurado, Veiculo veiculo)
 {
     return(new SeguroGetDto()
     {
         Id = seguro.Id,
         IdSegurado = seguro.IdSegurado,
         IdVeiculo = seguro.IdVeiculo,
         DataCalculo = seguro.DataCalculo,
         Valor = seguro.Valor,
         Segurado = Mapping.ToSeguradoGetDto(segurado),
         Veiculo = Mapping.ToVeiculoGetDto(veiculo),
     });
 }
Пример #19
0
        public void Add()
        {
            var segurado = new Segurado()
            {
                Id    = 20,
                Nome  = "Maria",
                Cpf   = "09876543212",
                Idade = 47
            };

            _seguradoServices.Add(segurado);

            Assert.Pass();
        }
Пример #20
0
        public async Task <Segurado> GetSegurado(string cpf)
        {
            string url = $"http://my-json-server.typicode.com/sloss-k2/json-server-db/segurados/?cpf={cpf}";

            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(url);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            Segurado segurado = JsonConvert.DeserializeObject <List <Segurado> >(responseBody).FirstOrDefault();

            return(segurado);
        }
Пример #21
0
        public void Inserir_Seguro()
        {
            ISeguroRep _rep      = InjecaoDeDependencia.Invocar <ISeguroRep>();
            int        resultado = 0;

            Veiculo  veiculo  = new Veiculo(10000, "Volksvagem", "Gol Mi");
            Segurado segurado = new Segurado("Max", "123456789", 25);

            Objeto.Seguro seguro = new Objeto.Seguro(veiculo, segurado);

            resultado = _rep.Inserir(seguro);

            Assert.IsTrue(resultado.Equals(1));
        }
Пример #22
0
        public ComunicadoXML P()
        {
            ComunicadoXML s = new ComunicadoXML
            {
                Empresa     = Empresa.P(),
                Finalizacao = Finalizacao.P(),
                Id          = Id,
                Reclamante  = Reclamante.P(),
                //Produtos = Produtos.P(),
                Segurado = Segurado.P(),
                Sinistro = Sinistro.P(),
            };

            return(s);
        }
Пример #23
0
        public Segurado RetornaId()
        {
            Segurado     modelo = new Segurado();
            MySqlCommand com    = new MySqlCommand();

            com.Connection  = conexao.Conexao;
            com.CommandText = "select id_segurado from segurado order by id_segurado desc limit 1;";
            conexao.Conectar();
            MySqlDataReader registro = com.ExecuteReader();

            if (registro.HasRows)
            {
                registro.Read();
                modelo.Id_segurado = Convert.ToInt32(registro["id_segurado"]);
            }
            conexao.Desconectar();
            return(modelo);
        }
Пример #24
0
 public void Add(Segurado segurado)
 {
     using (OracleConnection connection = new OracleConnection(_ConnectionString))
     {
         try
         {
             connection.Open();
             OracleParameter[] prm     = new OracleParameter[4];
             OracleCommand     command = connection.CreateCommand();
             command.CommandText = "SELECT MAX(ID) FROM SEGURADO";
             string resp = command.ExecuteScalar().ToString();
             if (resp == "")
             {
                 int maxno = 0;
                 prm[0] = command.Parameters.Add("ID", OracleDbType.Decimal, maxno + 1, ParameterDirection.Input);
                 prm[1] = command.Parameters.Add("NOME", OracleDbType.Varchar2, segurado.Nome, ParameterDirection.Input);
                 prm[2] = command.Parameters.Add("CPF", OracleDbType.Varchar2, segurado.Cpf, ParameterDirection.Input);
                 prm[3] = command.Parameters.Add("IDADE", OracleDbType.Varchar2, segurado.Idade, ParameterDirection.Input);
                 command.CommandText = "INSERT INTO SEGURADO (ID, NOME, CPF, IDADE) values(:1, :2, :3, :4)";
                 command.ExecuteNonQuery();
             }
             else
             {
                 int maxno = Convert.ToInt32(resp);
                 prm[0] = command.Parameters.Add("ID", OracleDbType.Decimal, maxno + 1, ParameterDirection.Input);
                 prm[1] = command.Parameters.Add("NOME", OracleDbType.Varchar2, segurado.Nome, ParameterDirection.Input);
                 prm[2] = command.Parameters.Add("CPF", OracleDbType.Varchar2, segurado.Cpf, ParameterDirection.Input);
                 prm[3] = command.Parameters.Add("IDADE", OracleDbType.Varchar2, segurado.Idade, ParameterDirection.Input);
                 command.CommandText = "INSERT INTO SEGURADO (ID, NOME, CPF, IDADE) values(:1, :2, :3, :4)";
                 command.ExecuteNonQuery();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             connection.Close();
         }
     }
 }
Пример #25
0
        public static string ValidaCampos(Segurado seg, Condutor cond, Uso_veiculo u, Veiculo v)
        {
            if (seg.Nome.Trim().Length == 0) return "Você precisa informar um nome!";
            //else if (seg.Data_nascimento.ToString() == "01/01/2010") return "Informe sua data de nascimento!";
            else if (seg.Sexo.Trim().Length == 0) return "Selecione o sexo!";
            else if (seg.Estado_civil.Trim().Length == 0) return "Informe o estado civil!";
            else if (seg.Celular.Trim().Length == 0) return "Informe um número de celular!";
            else if (seg.End.Cep.Trim().Length != 8) return "Informe um CEP válido (apenas números)!";
            else if (seg.End.Logradouro.Trim().Length == 0) return "Informe um logradouro!";
            else if (seg.End.Bairro.Trim().Length == 0) return "Informe um bairro!";
            else if (seg.End.Localidade.Trim().Length == 0) return "Informe uma localidade (cidade/município ou distrito)!";
            else if (seg.End.Uf.Trim().Length != 2) return "Informe um UF (Estado) Válido (Ex: SP)!";

            else if (seg.Escolaridade.Trim().Length == 0) return "O campo Escolaridade não pode ser nulo!";
            else if (seg.validaEstudante() == false) return "A opção estudante deve ser selecionada!";
            else if (seg.Estudante == true && seg.Periodo.Trim().Length == 0) return "Você deve selecionar o período em que estuda!";
            else if (seg.Profissao.Trim().Length == 0) return "Você deve informar sua profissão!";
            else if (seg.Nome_banco.Trim().Length == 0) return "Você deve selecionar um banco!";

            else if (cond.Cnh_segurado.Trim().Length == 0) return "Informe a CNH do segurado!";

            else if (u.valida_ida_volta_trab() == false) return "Você precisa selecionar uma opção de ida/volta do trabalho!";
            else if (u.valida_gar_est_trab() == false) return "Você precisa selecionar uma opção de garagem!";
            else if (u.valida_ativ_comer() == false) return "Você precisa selecionar uma opção de uso comercial!";
            else if (u.valida_gar_fecha_res() == false) return "Você precisa selecionar um tipo de garagem!";
            else if (u.valida_port_manual() == false) return "Você precisa selecionar um tipo de portão!";

            else if (v.Placa.Trim().Length < 1) return "Informe uma placa válida!";
            else if (v.Cep_pernoite.Trim().Length != 8) return "Informe um CEP pernoite válido!";
            else if (v.Marca.Trim().Length == 0) return "Informe a marca do veículo!";
            else if (v.Modelo.Trim().Length == 0) return "Informe o modelo do veículo!";
            else if (v.Ano_fabricacao < 1900 || v.Ano_fabricacao > 2099) return "Informe o ano de fabricação!";
            else if (v.Ano_modelo < 1900 || v.Ano_modelo > 2099) return "Informe o ano do modelo!";
            else if (v.valida_carro_zero() == false) return "Informe se o veículo é 0 Km!";
            else if (v.Combustivel.Trim().Length == 0) return "Informe o tipo de combustivel!";
            else if (v.Chassi.Trim().Length == 0) return "Informe o Nº do Chassi!";
            else if (v.valida_disp_anti_furto() == false) return "Informe se possui disp. antifurto!";
            else if (v.valida_kit_gas() == false) return "Informe se possui Kit Gás!";
            else if (v.valida_blindagem() == false) return "Informe se o veículo possui blindagem!";

            else return "ok";
        }
Пример #26
0
        public async Task <Unit> Handle(AdicionarSeguradoCommand request, CancellationToken cancellationToken)
        {
            var nomeCompleto     = NomeCompleto.Create(request.Nome, request.Sobrenome);
            var dataNascimento   = DataNascimento.Create(request.DataNascimento);
            var validationResult = Result.Combine(nomeCompleto, dataNascimento);

            if (validationResult.IsFailure)
            {
                await _mediatorHandler.RaiseDomainEvents(this, validationResult.Errors);

                return(Unit.Value);
            }

            var segurado = new Segurado(nomeCompleto.Value, dataNascimento.Value);
            await _seguradoRepository.Adicionar(segurado);

            await _seguradoRepository.Salvar();

            return(Unit.Value);
        }
Пример #27
0
        public HttpResponseMessage ExcluirSegurado(int Id)
        {
            try
            {   // verifica se o segurado não tem seguro, se não tiver exclui
                ISeguroRepository _objSeguroRepository = new SeguroRepository();
                Seguro            objSeguro            = new Seguro()
                {
                    SeguradoRefId = Id
                };
                var exite = _objSeguroRepository.VerificarExisteSeguroParaSegurado(objSeguro);
                if (exite.Count == 0)
                {
                    Segurado objSegurado = new Segurado()
                    {
                        Id = Id
                    };
                    ISeguradoRepository objSeguradoRepository = new SeguradoRepository();
                    var exiteSeg = objSeguradoRepository.VerificarExisteSegurado(objSegurado);
                    if (exiteSeg.Count != 0)
                    {
                        ISeguradoRepository objRepository = new SeguradoRepository();

                        objRepository.Delete(Id);
                        objRepository.Save();
                        return(Request.CreateResponse(HttpStatusCode.OK, "O segurado excluído com sucesso verifique !"));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Segurado não cadastrado, verifique !"));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Esse segurado possui seguro nao pode ser excluído, verifique !"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.NotModified, "Esse segurado não foi excluído, ocorreu algum erro, verifique !"));
            }
        }
Пример #28
0
        public Seguro CalcularSeguro(Veiculo veiculo, Segurado segurado)
        {
            var taxaDeRiso      = CalcularTaxaDeRisco(veiculo.Valor);
            var premioRisco     = CalcularPremioDeRisco(taxaDeRiso, veiculo.Valor);
            var premioPuro      = CalcularPremioPuro(premioRisco);
            var premioComercial = CalcularPremioComercial(premioPuro);

            _seguradoRepositorio.Add(segurado);
            _veiculoRepositorio.Add(veiculo);

            var seguro = new Seguro()
            {
                Segurado    = segurado,
                Veiculo     = veiculo,
                ValorSeguro = premioComercial,
            };

            _seguroRepositorio.Add(seguro);

            return(seguro);
        }
Пример #29
0
        public HttpResponseMessage AlterarSegurado(int id, [FromBody] Segurado segurado)
        {
            try
            {
                Business.SeguradoBo ValidaSegurado = new Business.SeguradoBo();
                if (!ValidaSegurado.ValidaNome(segurado.Nome))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.PaymentRequired, "O nome deve ter no mínimo 6 letras, favor preencher o campo !"));
                }

                if (!ValidaSegurado.ValidaIdade(segurado.Idade))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.PaymentRequired, "A idade mínima para segurado deve ser de 18 a 103 anos, favor preencher o campo !"));
                }

                if (!ValidaSegurado.ValidarCPF(segurado.CPF))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.PaymentRequired, "CPF inválido, verifique !"));
                }


                ISeguradoRepository obj = new SeguradoRepository();
                var exite = obj.VerificarExisteSegurado(segurado);
                if (exite.Count != 0)
                {
                    ISeguradoRepository objRepository = new SeguradoRepository();
                    objRepository.Update(segurado);
                    objRepository.Save();
                    return(Request.CreateResponse(HttpStatusCode.OK, "O segurado " + segurado.Nome + " foi alterado com sucesso verifique !"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Segurado não enccontrado!, verifique !"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.NotModified, "O segurado " + segurado.Nome + " não foi alterado, ocorreu algum erro, verifique !" + ex.InnerException));
            }
        }
Пример #30
0
        public SeguroOutput CalcularSeguro(SeguroInput Input)
        {
            Segurado segurado = _ISeguradoRep.Consultar(Input.CPF);

            if (segurado.Notifications.Count > 0)
            {
                return(new SeguroOutput(EStatusCode.InternalError, segurado.Notifications));
            }

            Veiculo veiculo = new Veiculo(new Carro(Input.Marca, Input.Modelo, Input.ValorVeiculo));
            Seguro  seguro  = new Seguro(segurado, veiculo);


            if (veiculo.Notifications.Count > 0)
            {
                return(new SeguroOutput(EStatusCode.InternalError, veiculo.Notifications));
            }
            seguro.CalcularSeguro();
            _ISeguroRep.IncluirSeguro(seguro);

            return(new SeguroOutput(EStatusCode.OK, seguro));
        }
Пример #31
0
        public Segurado Consultar(string cpf)
        {
            cpf = cpf.ToString()
                  .Replace(".", "")
                  .Replace("-", "")
                  .Replace("/", "");

            DadoJson DadoJson = JsonConvert.DeserializeObject <DadoJson>(Json);
            Segurado Segurado = new Segurado(new Name(DadoJson.Nome, DadoJson.Sobrenome)
                                             , new Documento(DadoJson.CPF.ToString()
                                                             .Replace(".", "")
                                                             .Replace("-", "")
                                                             .Replace("/", ""))
                                             , new Idade(DadoJson.Idade));

            if (cpf.Equals(Segurado.Documento.CPF))
            {
                return(Segurado);
            }

            return(null);
        }
Пример #32
0
 public Segurado RetornaId()
 {
     Segurado modelo = new Segurado();
     MySqlCommand com = new MySqlCommand();
     com.Connection = conexao.Conexao;
     com.CommandText = "select id_segurado from segurado order by id_segurado desc limit 1;";
     conexao.Conectar();
     MySqlDataReader registro = com.ExecuteReader();
     if (registro.HasRows)
     {
         registro.Read();
         modelo.Id_segurado = Convert.ToInt32(registro["id_segurado"]);
     }
     conexao.Desconectar();
     return modelo;
 }
Пример #33
0
        public void Incluir(Segurado segurado)
        {
            try
            {
                MySqlCommand com = new MySqlCommand();
                com.Connection = conexao.Conexao;
                com.CommandText = "insert into pessoa(nome, data_nascimento, sexo, estado_civil, fone, celular," +
                    "cep, logradouro, bairro, localidade, uf) values (@nome, @data_nascimento, @sexo, @estado_civil," +
                    "@fone, @celular, @cep, @logradouro, @bairro, @localidade, @uf); select @@IDENTITY;";
                com.Parameters.AddWithValue("@nome", segurado.Nome);
                com.Parameters.AddWithValue("@data_nascimento", segurado.Data_nascimento);
                com.Parameters.AddWithValue("@sexo", segurado.Sexo);
                com.Parameters.AddWithValue("@estado_civil", segurado.Estado_civil);
                com.Parameters.AddWithValue("@fone", segurado.Fone);
                com.Parameters.AddWithValue("@celular", segurado.Celular);
                com.Parameters.AddWithValue("@cep", segurado.End.Cep);
                com.Parameters.AddWithValue("@logradouro", segurado.End.Logradouro);
                com.Parameters.AddWithValue("@bairro", segurado.End.Bairro);
                com.Parameters.AddWithValue("@localidade", segurado.End.Localidade);
                com.Parameters.AddWithValue("@uf", segurado.End.Uf);
                conexao.Conectar();
                segurado.Id_pessoa = Convert.ToInt32(com.ExecuteScalar());
                ID_segurado = segurado.Id_pessoa;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexao.Desconectar();
            }

            try
            {
                MySqlCommand com = new MySqlCommand();
                com.Connection = conexao.Conexao;
                com.CommandText = "insert into segurado(escolaridade, estudante, periodo, profissao, nome_banco, id_pessoa)" +
                    " values(@escolaridade, @estudante, @periodo, @profissao, @nome_banco, @id_pessoa); select @@IDENTITY; ";
                com.Parameters.AddWithValue("@escolaridade", segurado.Escolaridade);
                com.Parameters.AddWithValue("@estudante", segurado.Estudante);
                com.Parameters.AddWithValue("@periodo", segurado.Periodo);
                com.Parameters.AddWithValue("@profissao", segurado.Profissao);
                com.Parameters.AddWithValue("@nome_banco", segurado.Nome_banco);
                com.Parameters.AddWithValue("@id_pessoa", segurado.Id_pessoa);
                conexao.Conectar();
                segurado.Id_segurado = Convert.ToInt32(com.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexao.Desconectar();
            }
        }
Пример #34
0
 public Segurado CerregaModeloSegurado(int id_segurado)
 {
     Segurado modelo = new Segurado();
     MySqlCommand com = new MySqlCommand();
     com.Connection = conexao.Conexao;
     com.CommandText = "select * from segurado where id_segurado = @id_segurado;";
     com.Parameters.AddWithValue("@id_segurado", id_segurado);
     conexao.Conectar();
     MySqlDataReader registro = com.ExecuteReader();
     if (registro.HasRows)
     {
         registro.Read();
         modelo.Escolaridade = Convert.ToString(registro["escolaridade"]);
         modelo.Estudante = Convert.ToBoolean(registro["estudante"]);
         modelo.Periodo = Convert.ToString(registro["periodo"]);
         modelo.Profissao = Convert.ToString(registro["profissao"]);
         modelo.Nome_banco = Convert.ToString(registro["nome_banco"]);
     }
     conexao.Desconectar();
     return modelo;
 }
Пример #35
0
 public Pessoa CerregaModeloPessoa(int id_pessoa)
 {
     Segurado modelo = new Segurado();
     MySqlCommand com = new MySqlCommand();
     com.Connection = conexao.Conexao;
     com.CommandText = "select * from pessoa where id_pessoa = @id_pessoa;";
     com.Parameters.AddWithValue("@id_pessoa", id_pessoa);
     conexao.Conectar();
     MySqlDataReader registro = com.ExecuteReader();
     if (registro.HasRows)
     {
         registro.Read();
         modelo.Id_pessoa = Convert.ToInt32(registro["id_pessoa"]);
         modelo.Nome = Convert.ToString(registro["nome"]);
         modelo.Data_nascimento = Convert.ToDateTime(registro["data_nascimento"]);
         modelo.Sexo = Convert.ToString(registro["sexo"]);
         modelo.Estado_civil = Convert.ToString(registro["estado_civil"]);
         modelo.Fone = Convert.ToString(registro["fone"]);
         modelo.Celular = Convert.ToString(registro["celular"]);
         modelo.End.Cep = Convert.ToString(registro["cep"]);
         modelo.End.Logradouro = Convert.ToString(registro["logradouro"]);
         modelo.End.Bairro = Convert.ToString(registro["bairro"]);
         modelo.End.Localidade = Convert.ToString(registro["localidade"]);
         modelo.End.Uf = Convert.ToString(registro["uf"]);
     }
     conexao.Desconectar();
     return modelo;
 }
Пример #36
0
        private void Incluir()
        {
            try
            {
                DALGeral DALObj = new DALGeral(cx);
                Segurado s = new Segurado();
                s.Nome = txtNome.Text;
                s.Data_nascimento = Convert.ToDateTime(txtDate.Text);
                if (MaleRadioButton.Checked == true) s.Sexo = "M"; else if (FameleRadioButton.Checked == true) s.Sexo = "F";
                s.Estado_civil = CombEstCivil.SelectedValue;
                s.Fone = txtTelefone.Text;
                s.Celular = txtCelular.Text;
                s.End.Cep = txtCEP.Text;
                s.End.Logradouro = txtLogradouro.Text;
                s.End.Bairro = txtBairro.Text;
                s.End.Localidade = txtLocalidade.Text;
                s.End.Uf = CombUf.SelectedValue;
                s.Escolaridade = CombEscolaridade.SelectedValue;
                if (SimEstudante.Checked == true && NãoEstudante.Checked == false) s._Estudante = "true";
                else if (NãoEstudante.Checked == true && SimEstudante.Checked == false) s._Estudante = "false"; else s._Estudante = "";
                if (DiurnoRadioButton.Checked == true && NoturnoRadioButton.Checked == false) s.Periodo = DiurnoRadioButton.Text;
                else if (NoturnoRadioButton.Checked == true && DiurnoRadioButton.Checked == false) s.Periodo = NoturnoRadioButton.Text; else s.Periodo = "";
                s.Profissao = txtProfissao.Text;
                s.Nome_banco = CombBanco.SelectedValue;

                Condutor c = new Condutor();
                c.Cnh_segurado = txtCNHSegurado.Text;
                c.Cpf_condutor_a = txtCPFCondutor_a.Text;
                c.Cnh_condutor_a = txtCNHCondutor_a.Text;
                c.Parentesco_cond_a = CombParentesco.SelectedValue;

                Veiculo v = new Veiculo();
                v.Marca = txtVeiculo.Text;
                v.Modelo = txtModelo.Text;
                v.Ano_fabricacao = Convert.ToInt32(txtAnofabricacao.Text);
                v.Ano_modelo = Convert.ToInt32(txtAnoModelo.Text);
                v._Carro_zero = "true";
                //if (SimZero.Checked == true && NaoZero.Checked == false) v.Carro_zero = true;
                //else if (NaoZero.Checked == true && SimZero.Checked == false) v._Carro_zero = "false"; else v._Carro_zero = "";
                v.Combustivel = CombCombustivel.SelectedValue;
                v.Chassi = txtChassi.Text;
                v.Placa = txtPlaca.Text;
                if (SimDispositivo.Checked == true && NaoDispositivo.Checked == false) v._Disp_anti_furto = "true";
                else if (NaoDispositivo.Checked == true && SimDispositivo.Checked == false) v._Disp_anti_furto = "false"; else v._Disp_anti_furto = "";
                if (SimGas.Checked == true && NaoGas.Checked == false) v._Kit_gas = "true";
                else if (NaoGas.Checked == true && SimGas.Checked == false) v._Kit_gas = "false"; else v._Kit_gas = "";
                if (SimBlindagem.Checked == true && NaoBlindagem.Checked == false) v._Blindagem = "true";
                else if (NaoBlindagem.Checked == true && SimBlindagem.Checked == false) v._Blindagem = "false"; else v._Blindagem = "";
                v.Cep_pernoite = txtcepPernoite.Text;

                Uso_veiculo u = new Uso_veiculo();
                if (SimTrab.Checked == true && NaoTrab.Checked == false) u._Ida_volta_trab = "true";
                else if (NaoTrab.Checked == true && SimTrab.Checked == false) u._Ida_volta_trab = "false"; else u._Ida_volta_trab = "";
                if (SimEstTrab.Checked == true && NaoEstTrab.Checked == false) u._Gar_est_trab = "true";
                else if (NaoEstTrab.Checked == true && SimEstTrab.Checked == false) u._Gar_est_trab = "false"; else u._Gar_est_trab = "";
                if (SimGarFechaCasa.Checked == true && NaoGarFechaCasa.Checked == false) u._Gar_fecha_res = "true";
                else if (NaoGarFechaCasa.Checked == true && SimGarFechaCasa.Checked == false) u._Gar_fecha_res = "false"; else u._Gar_fecha_res = "";
                if (SimPortManual.Checked == true && NaoPortManual.Checked == false) u._Port_manual = "true";
                else if (NaoPortManual.Checked == true && SimPortManual.Checked == false) u._Port_manual = "false"; else u._Port_manual = "";
                if (SimUsoComercial.Checked == true && NaoUsoComercial.Checked == false) u._Ativ_comer = "true";
                else if (NaoUsoComercial.Checked == true && SimUsoComercial.Checked == false) u._Ativ_comer = "false"; else u._Ativ_comer = "";

                string valida = BLLGeral.ValidaCampos(s, c, u, v);
                if (valida == "ok")
                {
                    DALObj.Incluir(s);
                    DALObj.Incluir(c);
                    DALObj.Incluir(v);
                    DALObj.Incluir(u);
                    ok = 1;
                }
                else
                {
                    Response.Write("<script language='javascript' type='text/javascript'>alert(' " + valida + " ')</script>");
                }
            }
            catch (Exception ex)
            {
                Response.WriteFile(ex.Message);
            }
        }