コード例 #1
0
        public ActionResult <Transfer> CreateTransfer(Transfer newTransfer)
        {
            Transfer transfer           = TransferDAO.CreateTransfer(newTransfer);
            decimal  fromAccountBalance = AccountDAO.GetBalance(newTransfer.AccountFrom);
            decimal  toAccountBalance   = AccountDAO.GetBalance(newTransfer.AccountTo);
            bool     transferSuccessful = AccountDAO.SendMoney(transfer, fromAccountBalance, toAccountBalance);

            return(Created($"/transfers/{transfer.TransferId}", transfer));
        }
コード例 #2
0
        public ActionResult <Transfer> CreateTransfer(Transfer newTransfer)
        {
            // get userId from the token
            int currentUserId = int.Parse(User.FindFirst("sub").Value);

            if (newTransfer.AccountFrom == currentUserId || (newTransfer.AccountTo == currentUserId && newTransfer.TransferTypeId == 1))
            {
                Transfer transfer = TransferDAO.CreateTransfer(newTransfer);

                // if the transfer was a send and was auto accepted
                if (transfer.TransferTypeId == 2)
                {
                    //update balances
                    bool transferSuccessful = AccountDAO.SendMoney(transfer);
                }
                return(Created($"/transfers/{transfer.TransferId}", transfer));
            }
            else
            {
                return(Forbid());
            }
        }