Beispiel #1
0
        public HttpResponseMessage ManterInvestimentoUsuario(InvestimentoModel investimentoModel)
        {
            string retorno  = "";
            var    response = new HttpResponseMessage();

            if (investimentoModel != null)
            {
                retorno = _investRepo.ManterInvestimentoUsuario(investimentoModel);

                if (retorno == "OK")
                {
                    response         = new HttpResponseMessage(HttpStatusCode.OK);
                    response.Content = new StringContent("OK");
                }
                else
                {
                    response         = new HttpResponseMessage(HttpStatusCode.BadRequest);
                    response.Content = new StringContent(retorno);
                }
            }
            else
            {
                response         = new HttpResponseMessage(HttpStatusCode.BadRequest);
                response.Content = new StringContent("Campos obrigatórios inválidos");
            }

            return(response);
        }
Beispiel #2
0
        public List <InvestimentoModel> ListarInstitFinancByIdUsuario(int idUsuario)
        {
            SqlDataReader            reader = null;
            List <InvestimentoModel> listaInstituicaoFinanceiraModel = new List <InvestimentoModel>();

            var query = @"SELECT * FROM Investimento
                            WHERE usuCodi = " + idUsuario;

            using (SqlConnection con = new SqlConnection(strConn.ToString()))
            {
                SqlCommand com = new SqlCommand(query, con);
                con.Open();
                try
                {
                    reader = com.ExecuteReader();
                    if (reader != null && reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var ret = new InvestimentoModel()
                            {
                                invCodi   = int.Parse(reader[0].ToString()),
                                usuCodi   = int.Parse(reader[1].ToString()),
                                ifuCodi   = int.Parse(reader[2].ToString()),
                                invDesc   = reader[3].ToString(),
                                invDtIni  = Convert.ToDateTime(reader[4].ToString()),
                                invDtFin  = reader[5].ToString().Length > 0 ? Convert.ToDateTime(reader[5].ToString()) : Convert.ToDateTime("01/01/0001"),
                                invVlrIni = decimal.Parse(reader[6].ToString()),
                                invTxJur  = decimal.Parse(reader[7].ToString()),
                                invObse   = reader[8].ToString(),
                                invFlAt   = bool.Parse(reader[9].ToString())
                            };

                            listaInstituicaoFinanceiraModel.Add(ret);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    con.Close();
                }
            }

            return(listaInstituicaoFinanceiraModel);
        }
Beispiel #3
0
        private async Task ValidateMapObject(RendaFixaModel rendaFixa, InvestimentoModel investimento)
        {
            if (rendaFixa is null)
            {
                investimento.Should().BeNull();
            }

            else if (investimento is null)
            {
                investimento.Should().BeNull();
            }

            else
            {
                investimento.Nome.Should().Be(rendaFixa.Nome);
                investimento.ValorInvestido.Should().Be(rendaFixa.CapitalInvestido);
                investimento.ValorTotal.Should().Be(rendaFixa.CapitalAtual);
                investimento.Vencimento.Should().Be(rendaFixa.Vencimento);
                investimento.Ir.Should().Be(rendaFixa.Ir);
                investimento.ValorResgate.Should().Be(rendaFixa.ValorResgate);
            }
        }
Beispiel #4
0
        private async Task ValidateMapObject(FundoModel fundo, InvestimentoModel investimento)
        {
            if (fundo is null)
            {
                investimento.Should().BeNull();
            }

            else if (investimento is null)
            {
                investimento.Should().BeNull();
            }

            else
            {
                investimento.Nome.Should().Be(fundo.Nome);
                investimento.ValorInvestido.Should().Be(fundo.CapitalInvestido);
                investimento.ValorTotal.Should().Be(fundo.ValorAtual);
                investimento.Vencimento.Should().Be(fundo.DataResgate);
                investimento.Ir.Should().Be(fundo.Ir);
                investimento.ValorResgate.Should().Be(fundo.ValorResgate);
            }
        }
Beispiel #5
0
        private async Task ValidateMapObject(TesouroDiretoModel tesouroDireto, InvestimentoModel investimento)
        {
            if (tesouroDireto is null)
            {
                investimento.Should().BeNull();
            }

            else if (investimento is null)
            {
                investimento.Should().BeNull();
            }

            else
            {
                investimento.Nome.Should().Be(tesouroDireto.Nome);
                investimento.ValorInvestido.Should().Be(tesouroDireto.ValorInvestido);
                investimento.ValorTotal.Should().Be(tesouroDireto.ValorTotal);
                investimento.Vencimento.Should().Be(tesouroDireto.Vencimento);
                investimento.Ir.Should().Be(tesouroDireto.Ir);
                investimento.ValorResgate.Should().Be(tesouroDireto.ValorResgate);
            }
        }
Beispiel #6
0
        public string ManterInvestimentoUsuario(InvestimentoModel investimentoModel)
        {
            string resp = "";

            using (SqlConnection connection = new SqlConnection(strConn))
            {
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                command.Connection = connection;

                try
                {
                    if (investimentoModel.invCodi > 0) //-> Se vier ID, faz update, senão insere um novo.
                    {
                        command.CommandText =
                            @"UPDATE [dbo].[Investimento] SET " +
                            "[ifuCodi] = " + investimentoModel.ifuCodi +
                            ",[invDesc] = '" + investimentoModel.invDesc +
                            "',[invDtIni] = '" + investimentoModel.invDtIni.ToString("yyyy-MM-dd HH:mm:ss") +
                            "',[invDtFin] = " +
                            (investimentoModel.invDtFin.ToString("yyyy-MM-dd HH:mm:ss") == "0001-01-01 00:00:00"
                                        ? "NULL"
                                        : "'" + investimentoModel.invDtFin.ToString("yyyy-MM-dd HH:mm:ss") + "'") +
                            ",[invVlrIni] = " + investimentoModel.invVlrIni.ToString().Replace(',', '.') +
                            ",[invTXJur] = " + investimentoModel.invTxJur.ToString().Replace(',', '.') +
                            ",[invObse] = '" + investimentoModel.invObse +
                            "',[invFlAt] = " + (investimentoModel.invFlAt ? 1 : 0) +
                            " WHERE [invCodi] = " + investimentoModel.invCodi;
                        command.ExecuteNonQuery();
                    }
                    else
                    {
                        command.CommandText =
                            @"INSERT INTO [dbo].[Investimento]
                                       ([usuCodi],[ifuCodi],[invDesc],[invDtIni],[invDtFin],[invVlrIni],[invTXJur],[invObse],[invFlAt])
                                 VALUES
                                       ( " +
                            investimentoModel.usuCodi + ", " +
                            investimentoModel.ifuCodi + ", '" +
                            investimentoModel.invDesc + "', '" +
                            investimentoModel.invDtIni.ToString("yyyy-MM-dd HH:mm:ss") + "', " +
                            (investimentoModel.invDtFin.ToString("yyyy-MM-dd HH:mm:ss") == "0001-01-01 00:00:00"
                                                ? "NULL, "
                                                : "'" + investimentoModel.invDtFin.ToString("yyyy-MM-dd HH:mm:ss") + "', ") +
                            investimentoModel.invVlrIni.ToString().Replace(',', '.') + ", " +
                            investimentoModel.invTxJur.ToString().Replace(',', '.') + ", '" +
                            investimentoModel.invObse + "', " +
                            (investimentoModel.invFlAt ? 1 : 0) +
                            " )";
                        command.ExecuteNonQuery();
                    }

                    resp = "OK";
                }
                catch (Exception ex)
                {
                    resp = "Erro ao inserir no banco de dados: " + ex.GetType() +
                           " | Mensagem: " + ex.Message;
                }
            }

            return(resp);
        }