Exemplo n.º 1
0
        public bool TransferTo(Transfer transfer)
        {
            //does ID match request?
            int loggedinUserId = GetUserId();
            if (loggedinUserId != transfer.FromUser)
            {
                return false;
            }

            //is there enough money?
            Account sourceAccount = accountDAO.GetAccount(loggedinUserId);
            if (sourceAccount.Balance < transfer.Amount)
            {
                return false;
            }

            //move money
            if (!accountDAO.Withdrawal(transfer))
            {
                return false;
            }
            if (!accountDAO.Deposit(transfer))
            {
                return false;
            }

            //get destination account for logging
            Account targetAccount = accountDAO.GetAccount(transfer.ToUser);

            //update transfer info
            Log log = new Log
            {
                FromId = sourceAccount.AccountId,
                ToId = targetAccount.AccountId,
                Amount = transfer.Amount,
                Type = TransferType.SEND,
                Status = StatusType.APPROVED
            };

            if (!transferDAO.AddTransfer(log))
            {
                return false;
            }

            return true;
        }