コード例 #1
0
ファイル: TransferDAO.cs プロジェクト: tmarshaus/tenmo
        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);
            }
        }
コード例 #2
0
        public ActionResult <decimal> GetBalance()
        {
            int     userId      = int.Parse(User.FindFirst("sub")?.Value);
            Account userAccount = accountDAO.GetAccount(userId);

            return(Ok(userAccount.Balance));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
ファイル: UserController.cs プロジェクト: CeKirby/CityScape
        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());
            }
        }
コード例 #7
0
        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());
            }
        }
コード例 #8
0
ファイル: MainMenu.cs プロジェクト: ADorscheid/Bootcamp
        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);
        }
コード例 #9
0
        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());
        }
コード例 #10
0
ファイル: MainMenu.cs プロジェクト: dejancancar/TE_TEnmo_app
        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);
        }
コード例 #11
0
        public ActionResult <Account> GetUserAccount(int userId)
        {
            Account acct = accountDAO.GetAccount(userId);

            if (acct == null)
            {
                return(NotFound());
            }

            return(Ok(acct));
        }
コード例 #12
0
        //[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);
        }
コード例 #13
0
        public ActionResult <Account> GetAccount(int accountId)
        {
            Account account = null;

            account = AccountDAO.GetAccount(User.Identity.Name, accountId);

            if (account == null)
            {
                return(NotFound());
            }

            return(Ok(account));
        }
コード例 #14
0
        public ActionResult <Account> GetAccount(int id)
        {
            Account account = accountDAO.GetAccount(id);

            if (account != null)
            {
                return(Ok(account));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
        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());
            }
        }
コード例 #17
0
        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("------------------------------------------");
        }
コード例 #18
0
ファイル: UserController.cs プロジェクト: Beth-Hart/TEnmoApp
        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));
        }
コード例 #19
0
        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());
            }
        }
コード例 #20
0
        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));
        }
コード例 #21
0
 public ActionResult GetBalance()
 {
     Account account = accountDAO.GetAccount(GetUserId());
     decimal balance = account.Balance;
     return StatusCode(200, balance);
 }
コード例 #22
0
 public ActionResult <Account> GetAccount(int userId)
 {
     return(Ok(accountDAO.GetAccount(userId)));
 }
コード例 #23
0
 public Account GetAccount(int userId)
 {
     return(accountDAO.GetAccount(userId));
 }
コード例 #24
0
        public ActionResult <Decimal> GetAccountBalance(int id)
        {
            Account account = AccountDAO.GetAccount(id);

            return(account.Balance);
        }
コード例 #25
0
 public Account GetAccount(int id)
 {
     return(accountDAO.GetAccount(id));
 }