Beispiel #1
0
        public bool Deposito(string valor, int quantidade)
        {
            if (!Cedulas.ContainsKey(valor) || quantidade <= 0)
            {
                return(false);
            }

            Cedulas[valor] += quantidade;
            DepositoLog.Add(DateTime.Now);
            return(true);
        }
        public int VerficaSaldo(List <Cedulas> notas)
        {
            var Qtd200 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "200").Single();
            Qtd200       = pegarCedulas.Qtd;

            var Qtd100 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "100").Single();
            Qtd100       = pegarCedulas.Qtd;

            var Qtd50 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "50").Single();
            Qtd50        = pegarCedulas.Qtd;

            var Qtd20 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "20").Single();
            Qtd20        = pegarCedulas.Qtd;

            var Qtd10 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "10").Single();
            Qtd10        = pegarCedulas.Qtd;

            var Qtd5 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "5").Single();
            Qtd5         = pegarCedulas.Qtd;

            var Qtd2 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "2").Single();
            Qtd2         = pegarCedulas.Qtd;

            var saldoCaixa = (200 * Qtd200) + (100 * Qtd100) + (50 * Qtd50) + (20 * Qtd20) + (10 * Qtd10) + (5 * Qtd5) + (2 * Qtd2);

            return(saldoCaixa);
        }
        public ActionResult Create(Saque saque, Cedulas cedulas)
        {
            var notas    = _context.Cedulas.Where <Cedulas>(a => a.Nota != "");
            var response = _interfaces.VerificaSaque(saque, cedulas, notas, _context);

            if (response == "Sucesso")
            {
                ViewBag.Mensagem = "Saque de " + saque.Valor.ToString() + " reais realizado com sucesso!!! Deseja realizar um novo Saque ou voltar para o Inicio?";
                return(View("Redirecionador"));
            }
            else if (response == "Erro1")
            {
                ViewBag.Mensagem = "Erro ao tentar sacar " + saque.Valor.ToString() + " reais. O valor deve ser menor que 1000 reais!!! Deseja realizar um novo Saque ou voltar para o Inicio?";
                return(View("Redirecionador"));
            }
            else if (response == "Erro2")
            {
                ViewBag.Mensagem = "Erro ao tentar sacar " + saque.Valor.ToString() + " reais. O valor do saque deve ser maior que 2 reais!!! Deseja realizar um novo saque ou voltar para o Inicio?";
                return(View("Redirecionador"));
            }
            else if (response == "Erro3")
            {
                ViewBag.Mensagem = "Saldo do caixa insuficiente para realizar o saque com o valor solicitado!!! Deseja realizar um novo Saque ou voltar para o Inicio?";
                return(View("Redirecionador"));
            }
            else if (response == "Erro4")
            {
                ViewBag.Mensagem = "Erro no sistema!!! O saque não foi realizado, tente novamente. Se o erro persistir contate o Suporte. Deseja realizar um novo Saque ou voltar para o Inicio?";
                return(View("Redirecionador"));
            }
            else
            {
                ViewBag.Mensagem = "Notas insuficientes para realizar o saque de " + saque.Valor.ToString() + " reais, faltou " + response.FirstOrDefault() + " reais, para poder efutar o saque tente novamente subtraindo " + response.FirstOrDefault() + " real ou cancele a operacao. Deseja Tentar Novamente ou voltar para o Inicio?";
                return(View("Redirecionador"));
            }
        }
Beispiel #4
0
 public int CalculaTotal()
 {
     return(Cedulas.Sum(x => x.Value * Convert.ToInt32(x.Key)));
 }
        public string VerificaSaque(Saque saque, Cedulas cedulas, IQueryable <Cedulas> notas, EFContext context)
        {
            var Qtd200 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "200").Single();
            Qtd200       = pegarCedulas.Qtd;

            var Qtd100 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "100").Single();
            Qtd100       = pegarCedulas.Qtd;

            var Qtd50 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "50").Single();
            Qtd50        = pegarCedulas.Qtd;

            var Qtd20 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "20").Single();
            Qtd20        = pegarCedulas.Qtd;

            var Qtd10 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "10").Single();
            Qtd10        = pegarCedulas.Qtd;

            var Qtd5 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "5").Single();
            Qtd5         = pegarCedulas.Qtd;

            var Qtd2 = 0;

            pegarCedulas = notas.Where(a => a.Nota == "2").Single();
            Qtd2         = pegarCedulas.Qtd;

            var saldoCaixa = (200 * Qtd200) + (100 * Qtd100) + (50 * Qtd50) + (20 * Qtd20) + (10 * Qtd10) + (5 * Qtd5) + (2 * Qtd2);
            var valorSaque = saque.Valor;

            if (valorSaque < 1000 && valorSaque >= 2 && valorSaque < saldoCaixa)
            {
                // 200
                if (valorSaque >= 200)
                {
                    var QtdNotas = valorSaque / 200;

                    if (Qtd200 >= QtdNotas)
                    {
                        valorSaque   = valorSaque % 200;
                        Qtd200      -= QtdNotas;
                        saque.Notas += "Notas 200: " + QtdNotas + " - ";
                    }
                    else if (Qtd200 > 0)
                    {
                        valorSaque  -= Qtd200 * 200;
                        saque.Notas += "Notas 200: " + Qtd200 + " - ";
                        Qtd200      -= Qtd200;
                    }
                }
                // 100
                if (valorSaque >= 100)
                {
                    var QtdNotas = valorSaque / 100;

                    if (Qtd100 >= QtdNotas)
                    {
                        valorSaque   = valorSaque % 100;
                        Qtd100      -= QtdNotas;
                        saque.Notas += "Notas 100: " + QtdNotas + " - ";
                    }
                    else if (Qtd100 > 0)
                    {
                        valorSaque  -= Qtd100 * 100;
                        saque.Notas += "Notas 100: " + Qtd100 + " - ";
                        Qtd100      -= Qtd100;
                    }
                }
                // 50
                if (valorSaque >= 50)
                {
                    var QtdNotas = valorSaque / 50;

                    if (Qtd50 >= QtdNotas)
                    {
                        valorSaque   = valorSaque % 50;
                        Qtd50       -= QtdNotas;
                        saque.Notas += "Notas 50: " + QtdNotas + " - ";
                    }
                    else if (Qtd50 > 0)
                    {
                        valorSaque  -= Qtd50 * 50;
                        saque.Notas += "Notas 50: " + Qtd50 + " - ";
                        Qtd50       -= Qtd50;
                    }
                }
                // 20
                if (valorSaque >= 20)
                {
                    var QtdNotas = valorSaque / 20;

                    if (Qtd20 >= QtdNotas)
                    {
                        valorSaque   = valorSaque % 20;
                        Qtd20       -= QtdNotas;
                        saque.Notas += "Notas 20: " + QtdNotas + " - ";
                    }
                    else if (Qtd20 > 0)
                    {
                        valorSaque  -= Qtd20 * 20;
                        saque.Notas += "Notas 20: " + Qtd20 + " - ";
                        Qtd20       -= Qtd20;
                    }
                }
                // 10
                if (valorSaque >= 10)
                {
                    var QtdNotas = valorSaque / 10;

                    if (Qtd10 >= QtdNotas)
                    {
                        valorSaque   = valorSaque % 10;
                        Qtd10       -= QtdNotas;
                        saque.Notas += "Notas 10: " + QtdNotas + " - ";
                    }
                    else if (Qtd10 > 0)
                    {
                        valorSaque  -= Qtd10 * 10;
                        saque.Notas += "Notas 10: " + Qtd10 + " - ";
                        Qtd10       -= Qtd10;
                    }
                }
                // 5
                if (valorSaque >= 5)
                {
                    var QtdNotas = valorSaque / 5;

                    if (Qtd5 >= QtdNotas)
                    {
                        valorSaque   = valorSaque % 5;
                        Qtd5        -= QtdNotas;
                        saque.Notas += "Notas 5: " + QtdNotas + " - ";
                    }
                    else
                    {
                        valorSaque  -= Qtd5 * 5;
                        saque.Notas += "Notas 5: " + Qtd5 + " - ";
                        Qtd5        -= Qtd5;
                    }
                }
                // 2
                if (valorSaque >= 2)
                {
                    var QtdNotas = valorSaque / 2;

                    if (Qtd2 >= QtdNotas)
                    {
                        valorSaque   = valorSaque % 2;
                        Qtd2        -= QtdNotas;
                        saque.Notas += "Notas 2: " + QtdNotas + " - ";
                    }
                    else
                    {
                        valorSaque  -= Qtd2 * 2;
                        saque.Notas += "Notas 2: " + Qtd2 + " - ";
                        Qtd2        -= Qtd2;
                    }
                }
            }
            else
            {
                if (valorSaque > 1000)
                {
                    var resultado = "Erro1";

                    return(resultado);
                }
                else if (valorSaque < 2)
                {
                    var resultado = "Erro2";

                    return(resultado);
                }
                else if (valorSaque > saldoCaixa)
                {
                    var resultado = "Erro3";

                    return(resultado);
                }
            }

            if (valorSaque == 0)
            {
                // 200
                var cedulas200 = notas.Where(a => a.Nota == "200").Single();
                cedulas200.Qtd = Qtd200;
                context.Update(cedulas200);
                // 100
                var cedulas100 = notas.Where(a => a.Nota == "100").Single();
                cedulas100.Qtd = Qtd100;
                context.Update(cedulas100);
                // 50
                var cedulas50 = notas.Where(a => a.Nota == "50").Single();
                cedulas50.Qtd = Qtd50;
                context.Update(cedulas50);
                // 20
                var cedulas20 = notas.Where(a => a.Nota == "20").Single();
                cedulas20.Qtd = Qtd20;
                context.Update(cedulas20);
                // 10
                var cedulas10 = notas.Where(a => a.Nota == "10").Single();
                cedulas10.Qtd = Qtd10;
                context.Update(cedulas10);
                // 5
                var cedulas5 = notas.Where(a => a.Nota == "5").Single();
                cedulas5.Qtd = Qtd5;
                context.Update(cedulas5);
                // 2
                var cedulas2 = notas.Where(a => a.Nota == "2").Single();
                cedulas2.Qtd = Qtd2;
                context.Update(cedulas2);

                string resultado;
                if (saque.Notas != null && saque.Hora != null)
                {
                    context.Update(saque);
                    context.SaveChanges();
                    resultado = "Sucesso";
                }
                else
                {
                    resultado = "Erro4";
                }

                return(resultado);
            }
            else
            {
                return(valorSaque.ToString());
            }
        }
Beispiel #6
0
 //Construtor para ATM com valor maximo no cofre
 public ATM()
 {
     cofre = new Cofre();
     cedulaSacadas = new Cedulas();
     saque = new Saque();
 }
Beispiel #7
-1
 internal static int ValorDasNotas(Cedulas notas)
 {
     int total;
     total = notas[Notas.Cem] * 100;
     total = notas[Notas.Cinquenta] * 50;
     total = notas[Notas.Vinte] * 20;
     total = notas[Notas.Dez] * 10;
     total = notas[Notas.Cinco] * 5;
     total = notas[Notas.Dois] * 2;
     return total;
 }
Beispiel #8
-1
        internal static Cedulas ValorDoDinheiro(int dinheiro)
        {
            var cedulas = new Cedulas();

            cedulas.Add(Notas.Cem, dinheiro / 100);
            dinheiro -= (int)Notas.Cem * 100;
            cedulas.Add(Notas.Cinquenta, dinheiro / 100);
            dinheiro -= (int)Notas.Cinquenta * 50;
            cedulas.Add(Notas.Vinte, dinheiro / 100);
            dinheiro -= (int)Notas.Vinte * 20;
            cedulas.Add(Notas.Dez, dinheiro / 100);
            dinheiro -= (int)Notas.Dez * 10;
            cedulas.Add(Notas.Cinco, dinheiro / 100);
            dinheiro -= (int)Notas.Cinco * 5;
            cedulas.Add(Notas.Dois, dinheiro / 100);

            return cedulas;
        }
Beispiel #9
-1
        public Cedulas sacar(int saque)
        {
            var cedulaSacadas = new Cedulas();
            valorSacado = saque;

            if((saque % 2 == 0 || saque % 5 == 0) && saque > 0)
            {
                cedulaSacadas[Notas.Cem] = saque / 100;
                saque -= cedulaSacadas[Notas.Cem] * 100;
                cedulaSacadas[Notas.Cinquenta] = saque / 50;
                saque -= cedulaSacadas[Notas.Cinquenta] * 50;
                cedulaSacadas[Notas.Vinte] = saque / 20;
                saque -= cedulaSacadas[Notas.Vinte] * 20;
                cedulaSacadas[Notas.Dez] = saque / 10;
                saque -= cedulaSacadas[Notas.Dez] * 10;
                cedulaSacadas[Notas.Cinco] = saque / 5;
                saque -= cedulaSacadas[Notas.Cinco] * 5;
                cedulaSacadas[Notas.Dois] = saque / 2;

            }else {
                throw new ArgumentException("Valor Invalido Para Saque");
            }
            return cedulaSacadas;
        }
Beispiel #10
-1
 public void Adicionar(int valor)
 {
     cedulas = Utilitarios.ValorDoDinheiro(valor);
 }