Esempio n. 1
0
        public async Task <IActionResult> Create([FromBody] Investimento investimento)
        {
            try
            {
                bool usuarioExists = await context.Usuario.AnyAsync(u => u.Id.Equals(investimento.UsuarioId));

                if (usuarioExists)
                {
                    investimento.UltimaAtualizacao = investimento.DataInicio;
                    context.Investimento.Add(investimento);
                    await context.SaveChangesAsync();

                    return(CreatedAtAction("Create", investimento));
                }
                else
                {
                    ModelState.AddModelError("Usuario", "Usuário não cadastrado no sistema.");
                    return(NotFound(ModelState.Values.SelectMany(e => e.Errors)));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Atualiza o valor atual de um investimento
        /// </summary>
        private Decimal AtualizarValor(Investimento investimento, DateTime data)
        {
            int tempo = TempoEmDias(investimento.UltimaAtualizacao, data);

            switch (investimento.EscalaTempo)
            {
            case EscalaTempo.Semanal:
                tempo = (int)(tempo / 7);
                break;

            case EscalaTempo.Quinzenal:
                tempo = (int)(tempo / 15);
                break;

            case EscalaTempo.Mensal:
                tempo = (int)(tempo / 30);
                break;

            case EscalaTempo.Anual:
                tempo = (int)(tempo / 360);
                break;
            }

            if (tempo > 0)
            {
                investimento.UltimaAtualizacao = DateTime.Now;
                return(CalcularValorFuturo(investimento, tempo));
            }
            else
            {
                return(investimento.ValorAtual);
            }
        }
Esempio n. 3
0
        public void ReaalizaCalculoInvestimento(Conta conta, Investimento investimento)
        {
            double resultado = investimento.Calcula(conta);

            conta.Depositar(resultado * 0.75);  //0.75 porque quando a pessoa investe um valor, ela só receve 75 do lucro do investimento. o resto é imposto
            Console.WriteLine($"Novo saldo da conta {conta.Saldo}");
        }
Esempio n. 4
0
        public void RealizaInvestimento(ContaBancaria conta, Investimento investimento)
        {
            double valor = investimento.Calcula(conta);

            conta.Deposita(valor * 0.75);
            Console.WriteLine("Novo saldo: " + conta.Saldo);
        }
Esempio n. 5
0
        public List <Investimento> BuscarTodosInvestimentos()
        {
            MySqlCommand command = Connection.Instance.CreateCommand();

            command.CommandText = "SELECT * FROM investimento";
            var reader = command.ExecuteReader();
            List <Investimento> lInvestimento = new List <Investimento>();

            while (reader.Read())
            {
                Investimento investimento = new Investimento()
                {
                    Id            = int.Parse(reader["Investimento_id"].ToString()),
                    Nome          = reader["Investimento_nome"].ToString(),
                    Rentabilidade = double.Parse(reader["Investimento_rentabilidade"].ToString()),
                    Taxa          = new Taxa()
                    {
                        Id = int.Parse(reader["Taxa_Taxa_id"].ToString())
                    }
                };
                lInvestimento.Add(investimento);
            }
            reader.Close();
            foreach (Investimento investimento in lInvestimento)
            {
                investimento.Taxa = new TaxaDAO().PesquisarPorTaxa(investimento.Taxa.Id);
            }
            return(lInvestimento);
        }
Esempio n. 6
0
        public void Realiza(Conta conta, Investimento investimento)
        {
            double resultado = investimento.Calcula(conta);

            conta.Deposita(resultado * 0.75);
            Console.WriteLine("Novo saldo: " + conta.Saldo);
        }
        public static void Initialize(ControleInvestimentosContext context)
        {
            if (context.Usuarios.Any())
            {
                return;
            }

            var usuarios = new Usuario[]
            {
                new Usuario {
                    Nome = "Guilherme", CPF = "09768255030"
                },
                new Usuario {
                    Nome = "Henrique", CPF = "84302871083"
                }
            };

            context.AddRange(usuarios);

            var investimentos = new Investimento[]
            {
                new Investimento {
                    Tipo = "Ações", Valor = 5.000M, Usuario = usuarios[0]
                },
                new Investimento {
                    Tipo = "CDB", Valor = 10.000M, Usuario = usuarios[0]
                }
            };

            context.AddRange(investimentos);

            context.SaveChanges();
        }
Esempio n. 8
0
        public async Task <IActionResult> Edit([FromRoute] int id, [FromBody] Investimento investimento)
        {
            try
            {
                var investimentoExists = await context.Investimento.AnyAsync(i => i.Id.Equals(id));

                if (investimentoExists)
                {
                    context.Investimento.Update(investimento);

                    await context.SaveChangesAsync();

                    return(Ok(investimento));
                }
                else
                {
                    ModelState.AddModelError("Investimento", "Investimento não encontrado");
                    return(NotFound(ModelState.Values.SelectMany(v => v.Errors)));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 9
0
        public void Calcula(Conta conta, Investimento investimento)
        {
            var valor = investimento.calcula(conta);

            conta.Saldo += valor * 0.75;
            Console.WriteLine(conta.Saldo);
        }
Esempio n. 10
0
        protected void btnSimularRendimento_Click(object sender, EventArgs e)  //Operação Simular Rendimento
        {
            //Carrego a sessão de investimento
            ContaCorrente conta = Session["ContaCorrente"] as ContaCorrente;
            // InvestimentoPoupanca investimentoPoupanca = Session["InvestimentoPoupanca"] as InvestimentoPoupanca;

            Investimento investimento = Session["investimento"] as Investimento;

            // chamo o método render para cálculo

            txtDescricao.Visible  = true;
            lblDescricao.Visible  = true;
            txtRendimento.Visible = true;
            lblRendimento.Visible = true;
            txtValorTotal.Visible = true;
            lblValorTotal.Visible = true;
            btnSimular.Visible    = true;
            btnConfirmar.Visible  = true;

            String texto = txtValorTotal.Text;     //txtValorAplicar.Text recebe como parâmetro o valor digitado pelo usuário e convertemos

            texto = texto.Replace('.', ',');       // de .(ponto) para ,(vírgula), caso o mesmo digite (ponto) para tratativa no saldo
            double valor = Convert.ToDouble(texto);

            if (investimento.Descricao == "Poupança")                        //Silumação para poupança
            {
                double aumento = Math.Round(valor * ((5.15 / 12) / 100), 2); // divide no mês

                txtDescricao.Text  = investimento.Descricao;
                txtRendimento.Text = Convert.ToString(investimento.Rendimento);
                txtValorTotal.Text = Convert.ToString(aumento + valor);
            }
            else if (investimento.Descricao == "CDB") //Simulação para CDB
            {
                txtDescricao.Text  = investimento.Descricao;
                txtRendimento.Text = Convert.ToString(investimento.Rendimento);

                String textoCDB = txtRendimento.Text;
                textoCDB = textoCDB.Replace('.', ',');
                double valorCDB = Math.Round(Convert.ToDouble(textoCDB), 2);

                txtValorTotal.Text = Convert.ToString(valor + valorCDB);
            }
            else if (investimento.Descricao == "Tesouro") //Simulação para Tesouro

            {
                txtDescricao.Text  = investimento.Descricao;
                txtRendimento.Text = Convert.ToString(investimento.Rendimento);

                String textoTesouro = txtRendimento.Text;
                textoTesouro = textoTesouro.Replace('.', ',');
                double valorTesouro = Math.Round(Convert.ToDouble(textoTesouro), 2);

                txtValorTotal.Text = Convert.ToString(valor + valorTesouro);
            }

            gdvResgatarInvestimento.Visible = false;
            btnSimular.Visible = false;
        }
Esempio n. 11
0
        public void calculaInvestimento(Orcamento orcamento, Investimento investimento)
        {
            double lucro = investimento.Investir(orcamento);

            lucro *= 0.75;

            System.Console.WriteLine("O lucro é de: " + lucro);
        }
Esempio n. 12
0
        public string Realiza(Conta conta, Investimento investimento)
        {
            double resultado = investimento.Calcula(conta);

            conta.Deposita(resultado * 0.75);

            return("Novo Saldo: " + conta.Saldo);
        }
Esempio n. 13
0
        /// <summary>
        /// Calcula o valor do investimento para uma data especifica (é usado na previsão e na atualização dos valores do investimento)
        /// </summary>
        private Decimal CalcularValorFuturo(Investimento investimento, int tempo, bool isGet = false)
        {
            double tempoD = (double)tempo;
            double valorD;

            valorD = (double)investimento.ValorAtual * Math.Pow(1 + investimento.TipoInvestimento.Taxa, tempoD);
            return(GarantirPrecisao(valorD));
        }
Esempio n. 14
0
        public ActionResult DeleteConfirmed(int id)
        {
            Investimento investimento = db.Investimentos.Find(id);

            db.Investimentos.Remove(investimento);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
        public void Investir(Conta conta, Investimento investimento)
        {
            var lucro = investimento.Investir(conta);

            var valor = lucro * 0.75;

            Console.WriteLine(valor);
        }
Esempio n. 16
0
 /// <summary>
 /// Verifica o saldo de um investimento
 /// </summary>
 public bool VerificarSaldo(Investimento investimento, decimal valor)
 {
     if ((investimento.ValorAtual - valor) < 0)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 17
0
    public static void Main()
    {
        int flag = 1;
        int x    = 0;
        int y    = 0;

        Poupanca[]    poup = new Poupanca[100];
        RendaFixa[]   inv  = new RendaFixa[100];
        AcumulaRendas cum  = new AcumulaRendas();

        while (flag != 1)
        {
            System.Console.WriteLine("Digite o tipo da conta");
            System.Console.WriteLine("1 - Poupança");
            System.Console.WriteLine("2 - Renda Fixa");
            int tipo = Convert.ToInt32(System.Console.ReadLine());
            System.Console.WriteLine("CPF?");
            string cpf = System.Console.ReadLine();
            System.Console.WriteLine("Nome?");
            string nome = System.Console.ReadLine();
            System.Console.WriteLine("Saldo?");
            double saldo = Convert.ToDouble(System.Console.ReadLine());

            System.Console.WriteLine("Rendimento desta conta em 1 ano!");

            if (tipo == 1)
            {
                poup[x] = new Poupanca(cpf, nome, saldo);
                poup[x].rendimento();
                cum.acumula(poup[x]);
                x++;
            }
            else
            {
                inv[y] = new RendaFixa(cpf, nome, saldo);
                inv[y].rendimento();
                cum.acumula(inv[y]);
                y++;
            }

            System.Console.WriteLine("Contas abertas:");
            if (tipo == 1)
            {
                Investimento.returnNumInvest();
            }
            else
            {
                Investimento.returnNumInvest();
            }

            System.Console.WriteLine("Rendimento total, 1 ano:");
            System.Console.WriteLine(cum.Total);
            System.Console.WriteLine("Para mais alguma conta, digite 1");
            flag = Convert.ToInt32(System.Console.ReadLine());
        }
    }
Esempio n. 18
0
        public static void cadastrar(Investimento investimento)
        {
            using (var ctx = new InvestimentoContext())
            {
                investimento.CotasRestantes = investimento.QtdCotas;
                ctx.Investimento.Add(investimento);

                ctx.SaveChanges();
            }
        }
Esempio n. 19
0
 public ActionResult Edit([Bind(Include = "Id,Name,Descricao,Valor,Quantidade")] Investimento investimento)
 {
     if (ModelState.IsValid)
     {
         db.Entry(investimento).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(investimento));
 }
 public ActionResult Edit([Bind(Include = "Id,tipoTaxa,valor,dataEntrada,dataResgate")] Investimento investimento)
 {
     if (ModelState.IsValid)
     {
         db.Entry(investimento).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(investimento));
 }
Esempio n. 21
0
        public void CadastroInvestimento()
        {
            Investimento investimento = new Investimento()
            {
                Nome          = "Teste",
                Rentabilidade = 5,
                Taxa          = new TaxaDAO().PesquisarPorTaxa(1)
            };

            Assert.IsNotNull(new InvestimentoDAO().CadastrarInvestimento(investimento));
        }
Esempio n. 22
0
        public ActionResult Create([Bind(Include = "Id,Name,Descricao,Valor,Quantidade")] Investimento investimento)
        {
            if (ModelState.IsValid)
            {
                db.Investimentos.Add(investimento);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(investimento));
        }
        public ActionResult Create([Bind(Include = "Id,tipoTaxa,valor,dataEntrada,dataResgate")] Investimento investimento)
        {
            if (ModelState.IsValid)
            {
                db.Investimentoes.Add(investimento);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(investimento));
        }
        public async Task <double> CalcularIr(Investimento investimento)
        {
            if (investimento.Rentabilidade < 0)
            {
                return(0); //não faz sentido um imposto negativo?
            }

            var taxa = await _taxaIrRepository.GetTaxaIrByTipoInvestimento(investimento.Tipo);

            return(investimento.Rentabilidade * taxa);
        }
        public void RealizaInvestimento(ContaBancaria conta, Investimento investimento)
        {
            Console.WriteLine("Saldo da conta antes do investimento: " + conta.Saldo);

            var resgateInvestimento = investimento.Investir(conta) * 0.75; //apenas 75%

            conta.Depositar(resgateInvestimento);

            Console.WriteLine("Valor do resgate: " + resgateInvestimento);

            Console.WriteLine("Saldo da conta depois do investimento: " + conta.Saldo);
        }
        public async Task <double> CalcularValorResgate(Investimento investimento)
        {
            double taxaCustodia = 0;

            //Se não está resgatando antecipado, o valor é total
            if (investimento.DataReferenciaResgate < investimento.Vencimento)
            {
                taxaCustodia = await GetTaxaCustodia(investimento);
            }

            return(investimento.ValorTotal - taxaCustodia - investimento.Ir - investimento.Iof);
        }
Esempio n. 27
0
 public static void editar(int id, Investimento investimento)
 {
     using (var ctx = new InvestimentoContext())
     {
         ctx.Investimento.Find(id).Nome           = investimento.Nome;
         ctx.Investimento.Find(id).Descricao      = investimento.Descricao;
         ctx.Investimento.Find(id).Valor          = investimento.Valor;
         ctx.Investimento.Find(id).Beneficio      = investimento.Beneficio;
         ctx.Investimento.Find(id).QtdCotas       = investimento.QtdCotas;
         ctx.Investimento.Find(id).CotasRestantes = investimento.CotasRestantes;
         ctx.SaveChanges();
     }
 }
Esempio n. 28
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         var          valor                 = Convert.ToDouble(textValorAInvestir.Text);
         Investimento tipoInvestimento      = (Investimento)comboTipoInvestimento.SelectedItem;
         var          valorAposInvestimento = CalculadorDeInvestimentos.CalculaInvestimento(tipoInvestimento, valor);
         textValorTotal.Text = Convert.ToString(valorAposInvestimento);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Valor à investir deve ser um valor válido");
     }
 }
        public void DeveRetornarValorDescontandoTrintaPorCento_ParaDemaisCasos()
        {
            var investimento = new Investimento
            {
                ValorTotal     = (decimal)100.00,
                Vencimento     = DateTime.Today.AddMonths(20),
                InicioCustodia = DateTime.Today.AddMonths(-15),
                ValorResgate   = decimal.Zero
            };

            _investimentoConsolidado.CalcularValorResgate(investimento);

            investimento.ValorResgate.Should().Be((decimal)70);
        }
Esempio n. 30
0
        // GET: Investimento/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Investimento investimento = db.Investimentos.Find(id);

            if (investimento == null)
            {
                return(HttpNotFound());
            }
            return(View(investimento));
        }
 public void Realiza(Conta conta, Investimento investimento)
 {
     double resultado = investimento.Calcula(conta);
     conta.Deposita(resultado * 0.75);
     Console.WriteLine("Novo saldo: " + conta.Saldo);
 }