Exemplo n.º 1
0
        public async Task <IActionResult> ActiveSolicitud(String tipo, int IdAccount)
        {
            switch (tipo)
            {
            case "Saving":
                CuentaAhorro ca = _db.CuentaAhorros.FirstOrDefault(x => x.Id == IdAccount);
                ca.RequestActive = true;
                _db.CuentaAhorros.Attach(ca);
                _db.Entry(ca).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                break;

            case "Checking":
                CuentaCorriente cc = _db.CuentaCorrientes.FirstOrDefault(x => x.Id == IdAccount);
                cc.RequestActive = true;
                _db.CuentaCorrientes.Attach(cc);
                _db.Entry(cc).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                break;
            }

            TempData["mesage"] = "La solitud se ha enviado, para que puedan reactivar su cuenta";
            TempData["status"] = "success";
            return(new RedirectResult("/ATM/0"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ActiveAccount(int IdAccount, String tipo)
        {
            switch (tipo)
            {
            case "Saving":
                CuentaAhorro ca = _db.CuentaAhorros.FirstOrDefault(x => x.Id == IdAccount);
                ca.RequestActive = false;
                ca.IsActive      = true;
                _db.CuentaAhorros.Attach(ca);
                _db.Entry(ca).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                break;

            case "Checking":
                CuentaCorriente cc = _db.CuentaCorrientes.FirstOrDefault(x => x.Id == IdAccount);
                cc.RequestActive = false;
                cc.IsActive      = true;
                _db.CuentaCorrientes.Attach(cc);
                _db.Entry(cc).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                break;
            }

            TempData["mesage"] = "La solitud se ha enviado, para que puedan reactivar su cuenta";
            TempData["status"] = "success";
            var IdBankAccount = Int16.Parse(Request.Cookies["IdBankAccount"]);

            return(new RedirectResult($"/bankaccount/GetAccountProducts/{IdAccount}"));
        }
Exemplo n.º 3
0
        public async Task <bool> DesactivarCuenta(int IdCheckingAccount)
        {
            EfModels.Models.ProductosFinancieros.CuentaAhorro checkingAccount =
                _db.CuentaAhorros.FirstOrDefault(ch => ch.Id == IdCheckingAccount);
            checkingAccount.IsActive = false;
            _db.CuentaAhorros.Attach(checkingAccount);
            _db.Entry(checkingAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _db.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 4
0
        public async Task <CuentaAhorro> CreateSavingAccount(CuentaAhorro cuentaAhorro)
        {
            cuentaAhorro.IsActive = true;
            EfModels.Models.ProductosFinancieros.CuentaAhorro savingAccount = _mapper
                                                                              .Map <EfModels.Models.ProductosFinancieros.CuentaAhorro>(cuentaAhorro);
            await _db.CuentaAhorros.AddAsync(savingAccount);

            await _db.SaveChangesAsync();

            return(_mapper.Map <CuentaAhorro>(savingAccount));
        }
Exemplo n.º 5
0
        public async Task <Dictionary <string, string> > RegisterTransaction(Transaccion transaccion)
        {
            if (transaccion.Tipo == 1)
            {
                transaccion.Saldo = Math.Round(transaccion.Saldo, 2);
                EfModels.Models.Transaccion trsn = _mapper.Map <EfModels.Models.Transaccion>(transaccion);
                await _repository.Transacciones.AddAsync(trsn);

                await _repository.SaveChangesAsync();

                return(new Dictionary <string, string>()
                {
                    { "res", "success" },
                    { "msg", "" }
                });
            }
            else
            {
                transaccion.Saldo = Math.Round(transaccion.Saldo, 2);
                Dictionary <string, string> response = await EvaluarCantidadRetiro(transaccion);

                if (response["res"] == "success")
                {
                    EfModels.Models.Transaccion trsn = _mapper.Map <EfModels.Models.Transaccion>(transaccion);
                    await _repository.Transacciones.AddAsync(trsn);

                    await _repository.SaveChangesAsync();

                    if (transaccion.IdCuentaAhorro > 0)
                    {
                        EfModels.Models.ProductosFinancieros.CuentaAhorro savingAccount =
                            _repository.CuentaAhorros.FirstOrDefault(ch => ch.Id == transaccion.IdCuentaAhorro);
                        savingAccount.Saldo = transaccion.Saldo;
                        _repository.CuentaAhorros.Attach(savingAccount);
                        _repository.Entry(savingAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        await _repository.SaveChangesAsync();
                    }
                    else
                    {
                        EfModels.Models.ProductosFinancieros.CuentaCorriente checkingAccount =
                            _repository.CuentaCorrientes.FirstOrDefault(ch => ch.Id == transaccion.IdCuentaCorriente);
                        checkingAccount.Saldo = transaccion.Saldo;
                        _repository.CuentaCorrientes.Attach(checkingAccount);
                        _repository.Entry(checkingAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        await _repository.SaveChangesAsync();
                    }
                }

                return(response);
            }
        }
Exemplo n.º 6
0
 public async Task <CuentaAhorro> FindSavingAccount(int IdSavingAccount)
 {
     EfModels.Models.ProductosFinancieros.CuentaAhorro cuentaAhorro =
         _db.CuentaAhorros.FirstOrDefault(c => c.Id == IdSavingAccount);
     return(_mapper.Map <CuentaAhorro>(cuentaAhorro));
 }
Exemplo n.º 7
0
        private async Task <Dictionary <string, string> > EvaluarCantidadRetiro(Transaccion t)
        {
            if (t.Cantidad > 400)
            {
                return(new Dictionary <string, string>()
                {
                    { "res", "error" },
                    { "msg", "La cantidad es mayor a $400" }
                });
            }

            Double sumaDiaria = 0;

            if (t.IdCuentaAhorro > 0)
            {
                sumaDiaria = await SumSavingAccountTodayTransactions(t.IdCuentaAhorro);
            }
            else
            {
                sumaDiaria = await SumCheckingAccountTodayTransactions(t.IdCuentaCorriente);
            }

            if ((sumaDiaria + t.Cantidad) > 1000)
            {
                return(new Dictionary <string, string>()
                {
                    { "res", "error" },
                    { "msg", "La cantidad supera al maximo de retiro por dia ($1000)" }
                });
            }

            if (t.Saldo < 0)
            {
                return(new Dictionary <string, string>()
                {
                    { "res", "error" },
                    { "msg", "La cantidad es mayor al saldo actual" }
                });
            }

            if (t.Saldo >= 0 && t.Saldo < 1)
            {
                if (t.IdCuentaAhorro > 0)
                {
                    EfModels.Models.ProductosFinancieros.CuentaAhorro savingAccount =
                        _repository.CuentaAhorros.FirstOrDefault(ch => ch.Id == t.IdCuentaAhorro);
                    savingAccount.IsActive = false;
                    _repository.CuentaAhorros.Attach(savingAccount);
                    _repository.Entry(savingAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    await _repository.SaveChangesAsync();
                }
                else
                {
                    EfModels.Models.ProductosFinancieros.CuentaCorriente checkingAccount =
                        _repository.CuentaCorrientes.FirstOrDefault(ch => ch.Id == t.IdCuentaCorriente);
                    checkingAccount.IsActive = false;
                    _repository.CuentaCorrientes.Attach(checkingAccount);
                    _repository.Entry(checkingAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    await _repository.SaveChangesAsync();
                }
            }

            return(new Dictionary <string, string>()
            {
                { "res", "success" },
                { "msg", "La cantidad es correcta" }
            });
        }