예제 #1
0
        public void Save(Proposta proposta)
        {
            //SALVANDO Segurado
            CondutorDAO condutorDao = new CondutorDAO();
            condutorDao.Editar(proposta.Segurado);

            //SALVANDO telefones do segurado
            List<Telefone> telefonesCorretos = new List<Telefone>();
            TelefoneDAO telefoneDao = new TelefoneDAO();
            if (proposta.Segurado.Telefones != null)
            {
                foreach (Telefone telefone in proposta.Segurado.Telefones)
                {
                    if (telefone.NumeroTelefone != null)
                    {
                        telefone.CodigoCondutor = proposta.Segurado.Id;
                        telefonesCorretos.Add(telefone);
                        telefoneDao.Editar(telefone);
                    }

                }
            }

            //SALVANDO Proprietario
            if (proposta.Proprietario.CodigoCpf != null)
            {
                proposta.Proprietario.IEProprietarioVeiculo = Enumerations.IEProprietarioVeiculo.SIM;
                proposta.Proprietario.codigoSegurado = proposta.Segurado.Id;
                condutorDao.Editar(proposta.Proprietario);
            }

            //SALVANDO Outro Condutor
            if (proposta.OutroCondutor.CodigoCpf != null)
            {
                proposta.OutroCondutor.IECondutorPrincipal = Enumerations.IECondutorPrincipal.OUTRAPESSOA;
                proposta.OutroCondutor.codigoSegurado = proposta.Segurado.Id;
                condutorDao.Editar(proposta.OutroCondutor);
            }

            db.SaveChanges();
            proposta.codigoSegurado = proposta.Segurado.Id;
            Editar(proposta);
            //Insert(proposta);
            //Delete(proposta);
        }
예제 #2
0
        public int InsertForEndosso(Proposta proposta)
        {
            //Adicionando Segurado
            CondutorDAO condutorDao = new CondutorDAO();
            condutorDao.Editar(proposta.Segurado);
            //db.Condutor.Add(proposta.Segurado);
            //db.SaveChanges();

            //Adicionando telefones do segurado
            //SALVANDO telefones do segurado
            List<Telefone> telefonesCorretos = new List<Telefone>();
            TelefoneDAO telefoneDao = new TelefoneDAO();
            if (null != proposta.Segurado && proposta.Segurado.Telefones != null)
            {
                foreach (Telefone telefone in proposta.Segurado.Telefones)
                {
                    if (telefone.NumeroTelefone != null)
                    {
                        telefone.CodigoCondutor = proposta.Segurado.Id;
                        telefonesCorretos.Add(telefone);
                        telefoneDao.Editar(telefone);
                    }

                }
            }

            //Adicionando Proprietario
            if (proposta.Proprietario.CodigoCpf != null)
            {
                proposta.Proprietario.IEProprietarioVeiculo = Enumerations.IEProprietarioVeiculo.SIM;
                condutorDao.Editar(proposta.Proprietario);
                //proposta.Proprietario.codigoSegurado = proposta.Segurado.Id;
                //db.Condutor.Add(proposta.Proprietario);
            }

            //Adicionando Outro Condutor
            if (proposta.OutroCondutor.CodigoCpf != null)
            {
                proposta.OutroCondutor.IECondutorPrincipal = Enumerations.IECondutorPrincipal.OUTRAPESSOA;
                condutorDao.Editar(proposta.OutroCondutor);
                //proposta.OutroCondutor.codigoSegurado = proposta.Segurado.Id;
                //db.Condutor.Add(proposta.OutroCondutor);
            }

            //Adicionando Proposta
            //proposta.codigoSegurado = proposta.Segurado.Id;
            int novoIdProposta = db.Proposta.Add(proposta).Id;

            db.SaveChanges();

            ////correção provisoria
            //if(proposta.CodigoCobertura == 0)
            //{
            //    proposta.CodigoCobertura = 1;
            //}
            //db.SaveChanges();
            db.Dispose();
            return novoIdProposta;
        }