Example #1
0
        public void AddTransfer(int currentUserId, int sendToUserId, decimal moneyAmount)
        {
            Transfer temp        = new Transfer();
            Account  fromAccount = accountAPI.GetAccount(currentUserId);
            Account  toAccount   = accountAPI.GetAccount(sendToUserId);

            List <Users> allUsers = userAPI.GetUsers();
            Users        sentUser = new Users();

            foreach (Users user in allUsers)
            {
                if (user.UserId == sendToUserId)
                {
                    sentUser = user;
                }
                else
                {
                }
            }
            if (moneyAmount <= fromAccount.Balance)
            {
                temp.TransferTypeId   = 1001; //send
                temp.TransferStatusId = 2001; //approved
                temp.AccountFrom      = fromAccount.AccountId;
                temp.AccountTo        = toAccount.AccountId;
                temp.DollarAmount     = moneyAmount;
                bool result = transferAPI.AddTransfer(temp);
                accountAPI.UpdateAccountFromBalance(currentUserId, (moneyAmount * -1));
                accountAPI.UpdateAccountFromBalance(sendToUserId, moneyAmount);
                if (result)
                {
                    Console.WriteLine($"Success! You sent {sentUser.Username} ${moneyAmount}");
                }
                else
                {
                    Console.WriteLine("Error: unable to add.");
                }
            }
            else
            {
                Console.WriteLine("You cannot send more money than you have!");
            }
        }