public Transfer TransferApprovedRequest(Transfer transfer) { //Get current User id balance decimal currentUserBalance = accountDAO.GetAccount(transfer.AccountFrom).Balance; //Get toUserid balance decimal toUserBalance = accountDAO.GetAccount(transfer.AccountTo).Balance; //Check balance of current user against sentMoney if (currentUserBalance >= transfer.Amount) { //Updated balance for user decimal newCurrentUserBalance = currentUserBalance - transfer.Amount; //Updated balance for toUserId decimal newToUserBalance = toUserBalance + transfer.Amount; //Update transfer status transfer.TransferStatusId = 2; //Update balance for current user UpdateBalance(transfer.AccountFrom, newCurrentUserBalance); //Update balance for toUser UpdateBalance(transfer.AccountTo, newToUserBalance); return(transfer); } else { transfer.TransferStatusId = 3; return(transfer); } }
public ActionResult <decimal> GetBalance() { int userId = int.Parse(User.FindFirst("sub")?.Value); Account userAccount = accountDAO.GetAccount(userId); return(Ok(userAccount.Balance)); }
public ActionResult <TransferDetails> Transfer(Transfer transfer) { decimal toAccountBalance = accountDAO.GetAccount(transfer.AccountTo).Balance; decimal fromAccountBalance = accountDAO.GetAccount(transfer.AccountFrom).Balance; ActionResult result; if (fromAccountBalance < transfer.Amount) { result = BadRequest(new { message = "Aw, shucks. You've not enough bucks! Transfer failed. Next time better lucks!" }); } else { decimal newToBalance = toAccountBalance + transfer.Amount; bool updateSuccessful = transferDAO.UpdateBalance(transfer.AccountTo, newToBalance); decimal newFromBalance = fromAccountBalance - transfer.Amount; updateSuccessful = transferDAO.UpdateBalance(transfer.AccountFrom, newFromBalance); if (updateSuccessful) { TransferDetails added = transferDAO.CreateTransfer(transfer); result = Created($"/transfer/{added.ID}", added); } else { result = BadRequest(new { message = "Sorry, something didn't work. The transfer didn't work." }); } } return(result); }
public ActionResult <Transfer> SendTEBucks(Transfer transfer) { //Make sure from account is owned by current user Account currentUserAccount = accountDAO.GetAccount(GetUserId()); transfer.AccountFrom = currentUserAccount.AccountId; transferDAO.SendMoneyTo(transfer); return(Ok(transfer)); }
public ActionResult <Account> GetAccountById(int userId) { Account account = accountDAO.GetAccount(userId); if (account != null) { return(account); } else { return(NotFound()); } }
public ActionResult <decimal> GetBalance(int userId) { Account account = accountDAO.GetAccount(userId); if (account.Balance != 0) { return(Ok(account.Balance)); } else { return(NotFound()); } }
public ActionResult <AccountWithTypes> GetAccount() { var userId = Convert.ToInt32(User.FindFirst("sub")?.Value); AccountWithTypes account = accountDAO.GetAccount(userId); if (account != null) { return(Ok(account)); } else { return(NotFound()); } }
private MenuOptionResult ViewBalance() { try { //int accountId = MainMenu.GetInteger("Please enter your account Id: "); Account account = accountDao.GetAccount(UserService.GetUserId()); Console.WriteLine($"Your account {account.AccountId} has the balance of: {account.Balance:C2}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(MenuOptionResult.WaitAfterMenuSelection); }
public ActionResult <bool> AddTransferRequest(Transfer transfer) { Account fromAccount, toAccount; if (transfer.TransferType == TransferType.Send) { toAccount = accountDAO.GetAccount(transfer.ToUserName); if (toAccount == null) { return(NotFound()); } fromAccount = accountDAO.GetAccount(User.Identity.Name); if (fromAccount.Balance < transfer.TransferAmount) { return(BadRequest()); } else { transfer.TransferStatus = TransferStatus.Approved; transfer.FromUserID = fromAccount.UserId; } } else { fromAccount = accountDAO.GetAccount(transfer.FromUserName); if (fromAccount == null) { return(NotFound()); } toAccount = accountDAO.GetAccount(User.Identity.Name); transfer.TransferStatus = TransferStatus.Pending; transfer.ToUserID = toAccount.UserId; } bool requestSucceeded = transferDAO.AddTransferRequest(transfer); if (!requestSucceeded) { return(StatusCode(500)); } CompleteTransferIfApproved(transfer); return(Ok()); }
private MenuOptionResult ViewBalance() { try { // create a rest request to the /users/username/account# url, get back a balance int accountId = MainMenu.GetInteger("Please enter your account Id: "); // TODO: THIS WILL CALL THE ACCOUNTDAO AND IT WILL RETURN AN ACCOUNT (GETACCOUNT METHOD). WE WILL USE THAT ACCOUNT TO REFERENCE THE BALANCE BY ACCOUNT.BALANCE // UserService.GetUserName Account account = accountDao.GetAccount(accountId); //Account account1 = accountDao.GetAccount(UserService.GetUserName(), accountId); Console.WriteLine($"Your account {accountId} has the balance of: {account.Balance}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(MenuOptionResult.WaitAfterMenuSelection); }
public ActionResult <Account> GetUserAccount(int userId) { Account acct = accountDAO.GetAccount(userId); if (acct == null) { return(NotFound()); } return(Ok(acct)); }
//[Authorize] public ActionResult <Account> GetAccount(int accountId) { Account account = null; if (User.IsInRole("Admin")) { account = AccountDAO.GetAccount(accountId); } else { account = AccountDAO.GetAccount(User.Identity.Name, accountId); } if (account == null) { return(NotFound()); } return(account); }
public ActionResult <Account> GetAccount(int accountId) { Account account = null; account = AccountDAO.GetAccount(User.Identity.Name, accountId); if (account == null) { return(NotFound()); } return(Ok(account)); }
public ActionResult <Account> GetAccount(int id) { Account account = accountDAO.GetAccount(id); if (account != null) { return(Ok(account)); } else { return(NotFound()); } }
public ActionResult <Account> GetAccount() { int userId = Convert.ToInt32(User.FindFirst("sub")?.Value); Account account = accountDAO.GetAccount(userId); if (account == null) { return(NotFound()); } else { return(account); } }
public ActionResult <Account> GetAccount() { int userId = GetId(); //Calling GetId() and assigning the result to userId Account account = accountDAO.GetAccount(userId); //assigning the account with userId to account object if (account != null) { return(Ok(account)); } else { return(NotFound()); } }
protected override void OnBeforeShow() { SetColor(ConsoleColor.Green); Console.WriteLine("------------------------------------------"); Console.WriteLine($"TE Account Menu for User: {UserService.GetUserName()}"); int userID = UserService.GetUserId(); Account account = accountDAO.GetAccount(userID); Console.WriteLine($"Balance for {UserService.GetUserName()}: {account.Balance:C}"); Console.WriteLine("------------------------------------------"); }
public ActionResult <List <User> > GetOtherUsers() { Account account = accountDAO.GetAccount(User.Identity.Name); if (account == null) { return(NotFound()); } List <User> users = userDAO.GetOtherUsers(account.UserId); if (users == null) { NotFound(); } return(Ok(users)); }
public ActionResult <TransferWithDetails> SendMoney(NewTransfer nt) { int userId = GetId(); Account accountFrom = accountDAO.GetAccount(userId); if (accountFrom == null) { return(NotFound("Account does not exist")); } if (accountFrom.Balance >= nt.Amount) { TransferWithDetails result = transferDAO.SendMoney(userId, nt.ReceiverAccount, nt.Amount); return(Ok(result)); } else { return(NotFound()); } }
public Transfer SendTransfer(SendTransfer st) { //TODO validate data? int id = int.Parse(User.FindFirst("sub").Value); // call account dao get balance for current user Account account = accountDAO.GetAccount(id); decimal balance = account.Balance; Transfer transfer = new Transfer(); transfer.Amount = st.Amount; transfer.TransferStatus = TransferStatus.Approved; transfer.TransferType = TransferType.Send; transfer.AccountTo = st.ToUser; transfer.AccountFrom = id; return(transferSqlDAO.SendTransfer(transfer)); }
public ActionResult GetBalance() { Account account = accountDAO.GetAccount(GetUserId()); decimal balance = account.Balance; return StatusCode(200, balance); }
public ActionResult <Account> GetAccount(int userId) { return(Ok(accountDAO.GetAccount(userId))); }
public Account GetAccount(int userId) { return(accountDAO.GetAccount(userId)); }
public ActionResult <Decimal> GetAccountBalance(int id) { Account account = AccountDAO.GetAccount(id); return(account.Balance); }
public Account GetAccount(int id) { return(accountDAO.GetAccount(id)); }