예제 #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"));
        }
예제 #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}"));
        }
예제 #3
0
        public async Task <bool> DeleteCheckingAccount(int IdCheckingAccount)
        {
            EfModels.Models.ProductosFinancieros.CuentaCorriente ch =
                _db.CuentaCorrientes.FirstOrDefault(ch => ch.Id == IdCheckingAccount);
            _db.CuentaCorrientes.Attach(ch);
            _db.Entry(ch).State = EntityState.Deleted;
            await _db.SaveChangesAsync();

            return(true);
        }
예제 #4
0
        public async Task <bool> CreditMoney(int IdCheckingAccount, double Amount)
        {
            EfModels.Models.ProductosFinancieros.CuentaCorriente checkingAccount =
                _db.CuentaCorrientes.FirstOrDefault(ch => ch.Id == IdCheckingAccount);
            checkingAccount.Saldo += Amount;
            _db.CuentaCorrientes.Attach(checkingAccount);
            _db.Entry(checkingAccount).State = EntityState.Modified;
            await _db.SaveChangesAsync();

            return(true);
        }
예제 #5
0
        public async Task <CuentaCorriente> CreateNewCheckingAccount(CuentaCorriente cuentaCorriente)
        {
            EfModels.Models.ProductosFinancieros.CuentaCorriente newCheckingAccount =
                _mapper.Map <EfModels.Models.ProductosFinancieros.CuentaCorriente>(cuentaCorriente);
            newCheckingAccount.IsActive = true;
            await _db.CuentaCorrientes.AddAsync(newCheckingAccount);

            await _db.SaveChangesAsync();

            return(_mapper.Map <CuentaCorriente>(newCheckingAccount));
        }
예제 #6
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);
            }
        }
예제 #7
0
 public async Task <bool> WithDrawMoney(int IdCheckingAccount, double Amount)
 {
     EfModels.Models.ProductosFinancieros.CuentaCorriente checkingAccount =
         _db.CuentaCorrientes.FirstOrDefault(ch => ch.Id == IdCheckingAccount);
     if (Amount <= 400.00 && checkingAccount.Dialy <= 1000.00)
     {
         checkingAccount.Saldo -= Amount;
         if (checkingAccount.Saldo <= 1.0)
         {
             checkingAccount.IsActive = false;
         }
         _db.Update(checkingAccount);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #8
0
        public async Task <IActionResult> ShowAccounts(int IdAccount, String account)
        {
            AccountDTO act = new AccountDTO();

            switch (account)
            {
            case "Saving":
                EfModels.Models.ProductosFinancieros.CuentaAhorro ct         = _db.CuentaAhorros.FirstOrDefault(x => x.Id == IdAccount);
                List <lab2.Domain.DTOs.TransactionsDTO>           savingList = await _mediator.Send(new GetSavingAccountTransactions.Query(IdAccount));

                double SaldoSaving = savingList[savingList.Count - 1].Saldo;
                act = new AccountDTO()
                {
                    Amount = SaldoSaving
                };
                ViewBag.Transactions = savingList;
                break;

            case "Checking":
                CuentaCorriente s = _db.CuentaCorrientes.FirstOrDefault(x => x.Id == IdAccount);
                List <lab2.Domain.DTOs.TransactionsDTO> checkingList = await _mediator.Send(new GetAllCheckingAccountTransactions.Query(IdAccount));

                double SaldoChecking = checkingList[checkingList.Count - 1].Saldo;
                act = new AccountDTO()
                {
                    Amount = SaldoChecking
                };

                ViewBag.Transactions = checkingList;
                break;
            }

            ViewData["Title"] = "ATM";
            ViewBag.Account   = account;
            ViewBag.IdAccount = IdAccount;

            return(View(act));
        }
예제 #9
0
 public async Task <CuentaCorriente> GetCheckingAccountById(int IdCheckingAccount)
 {
     EfModels.Models.ProductosFinancieros.CuentaCorriente checkingAccountFound =
         _db.CuentaCorrientes.FirstOrDefault(ch => ch.Id == IdCheckingAccount);
     return(_mapper.Map <CuentaCorriente>(checkingAccountFound));
 }
예제 #10
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" }
            });
        }