Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("NotasId,Nota,Valor,Qtde,ImgNota")] Notas notas)
        {
            if (ModelState.IsValid)
            {
                db.Add(notas);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(notas));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("id,Valor")] Saque saque)
        {
            int cem = 0, ciq = 0, vin = 0, dez = 0, cin = 0, doi = 0;
            var notas = db.Notas.AsQueryable();

            foreach (var nt in notas)
            {
                if (nt.Valor == 100)
                {
                    cem = nt.Qtde;
                }
                if (nt.Valor == 50)
                {
                    ciq = nt.Qtde;
                }
                if (nt.Valor == 20)
                {
                    vin = nt.Qtde;
                }
                if (nt.Valor == 10)
                {
                    dez = nt.Qtde;
                }
                if (nt.Valor == 5)
                {
                    cin = nt.Qtde;
                }
                if (nt.Valor == 2)
                {
                    doi = nt.Qtde;
                }
            }
            int resto  = (int)saque.Valor;
            int cedula = doi + cin + dez + vin + ciq + cem;



            if (ModelState.IsValid)
            {
                if (cem > 0)
                {
                    while (resto >= 100 && cem > 0)
                    {
                        resto = resto - 100; cem -= 1;
                    }
                }
                if (ciq > 0)
                {
                    while (resto >= 50 && ciq > 0)
                    {
                        resto = resto - 50; ciq -= 1;
                    }
                }
                if (vin > 0)
                {
                    while (resto >= 20 && vin > 0)
                    {
                        resto = resto - 20; vin -= 1;
                    }
                }
                if (dez > 0)
                {
                    while (resto >= 10 && dez > 0)
                    {
                        resto = resto - 10; dez -= 1;
                    }
                }
                if (cin > 0)
                {
                    while (resto >= 5 && cin > 0)
                    {
                        resto = resto - 5; cin -= 1;
                    }
                }
                if (doi > 0)
                {
                    while (resto >= 2 && doi > 0)
                    {
                        resto = resto - 2; doi -= 1;
                    }
                }



                var resultnotas = cedula;

                if (resto > 0)
                {
                    var disponivel = saque.Valor - resto;
                    ViewBag.ValorSaque = $"Valor solicitado de {saque.Valor.ToString("C2")} é Maior que o Disponivel Saque";
                    ViewBag.Disponivel = $"Valor Disponível para Saque é de {disponivel.ToString("C2")}";
                }


                if (resto == 0)

                {
                    db.Add(saque);
                    saque.DataSaque = DateTime.Parse(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
                    await db.SaveChangesAsync();

                    foreach (var nt in notas)
                    {
                        if (nt.Valor == 100)
                        {
                            nt.Qtde = cem; db.SaveChanges();
                        }
                        if (nt.Valor == 50)
                        {
                            nt.Qtde = ciq; db.SaveChanges();
                        }
                        if (nt.Valor == 20)
                        {
                            nt.Qtde = vin; db.SaveChanges();
                        }
                        if (nt.Valor == 10)
                        {
                            nt.Qtde = dez; db.SaveChanges();
                        }
                        if (nt.Valor == 5)
                        {
                            nt.Qtde = cin; db.SaveChanges();
                        }
                        if (nt.Valor == 2)
                        {
                            nt.Qtde = doi; db.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Op", resultnotas));
                }
            }
            return(View(saque));
        }