Ejemplo n.º 1
0
        public IActionResult CreateTransfer(NewTransfer transfer)
        {
            IActionResult result = BadRequest();

            int?userId = GetCurrentUserId();

            if (!userId.HasValue)
            {
                return(BadRequest());
            }

            Account fromAcct = accountDAO.GetAccountByUserId(transfer.UserFrom);
            Account toAcct   = accountDAO.GetAccountByUserId(transfer.UserTo);

            if (fromAcct == null || toAcct == null)
            {
                return(NotFound());
            }
            if (fromAcct.Balance < transfer.Amount)
            {
                return(StatusCode(402)); //402 = Payment Required, could be BadRequest
            }

            Transfer newTransfer = transferDAO.AddTransfer(transfer, fromAcct.AccountId, toAcct.AccountId);

            if (newTransfer != null)
            {
                result = Created("transfers/" + newTransfer.TransferId, newTransfer);
            }

            return(result);
        }
Ejemplo n.º 2
0
        private MenuOptionResult ViewBalance()
        {
            Account account = accountDAO.GetAccountByUserId(UserService.GetUserId());

            Console.WriteLine($"Your current balance is: {account.Balance:c}");

            return(MenuOptionResult.WaitAfterMenuSelection);
        }
Ejemplo n.º 3
0
        public ActionResult <Account> GetAccountById(int id)
        {
            Account account = accountDAO.GetAccountByUserId(id);

            if (account == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(account));
            }
        }
Ejemplo n.º 4
0
        public IActionResult GetBalance()
        {
            int?userId = GetCurrentUserId();

            if (!userId.HasValue)
            {
                return(BadRequest());
            }

            Account a = accountDAO.GetAccountByUserId(userId.Value);

            if (a == null)
            {
                return(NotFound());
            }
            return(Ok(a.Balance));
        }