public async Task <ActionResult <AccountType> > GetAccountTypeById(int id)
        {
            AccountType accType = await _context.GetAccountTypeById(id);

            if (accType is null)
            {
                _logger.LogError("Account type not found with Id: {0}", id);
                return(NotFound());
            }
            else
            {
                _logger.LogInformation("Account type with Id: {0} Successfully returned.", id);
                return(accType);
            }
        }
        public async Task <ActionResult> Withdraw(int id, decimal amount)
        {
            try
            {
                Account acctFound = null;
                if (amount < 0) //make sure withdraw amount is positive
                {
                    _logger?.LogWarning(string.Format("PUT request failed, Amount passed is less than 0.  Account with ID: {0}", id.ToString()));
                    return(StatusCode(400));
                }

                acctFound = await _repoAccount.GetAccountDetailsByAccountID(id); //retrieve the account

                if (acctFound == null)                                           //make sure that account exist or the account is closed for it to return null
                {
                    _logger?.LogWarning(string.Format("PUT request failed, No Account found with ID: {0} or Account is already closed", id.ToString()));
                    return(NotFound(id));
                }

                //check if withdraw causes overdraft, different actions based on account type
                if ((acctFound.Balance - amount) < 0)
                {
                    //check if it is checking account return an error
                    if (acctFound.AccountTypeId == 1) // 1 hard coded to represent checking account replace with actual AccountType check
                    {
                        _logger?.LogWarning(string.Format("PUT request failed, Withdraw would overdraft Checking Account with ID: {0}", id.ToString()));
                        return(StatusCode(400));
                    }
                    else//if business account do penalty calculation
                    {
                        decimal     overdraft = 0;
                        AccountType acctType  = await _repoAccountType.GetAccountTypeById(acctFound.AccountTypeId); //need account type for interset rate

                        //calculates the penalty for overdrafting on a business account  returns total amount to withdraw
                        decimal totalAmount = CalculatePenalty(acctFound.Balance, amount, acctType.InterestRate, ref overdraft);

                        //returns true if account is closed
                        if (!await _repoAccount.Withdraw(acctFound.Id, totalAmount)) //Warning: possible problem pass in totalAmount = amount + overdraftPenalty
                        {
                            _logger?.LogWarning(string.Format("PUT, withdraw failed, Account is already closed", id.ToString()));
                            return(NotFound(id));
                        }
                        await _repoAccount.Overdraft(id, overdraft); //record the overdraft in transactions table

                        _logger?.LogInformation("PUT Success withdrew from account but with overdraft, account ID: {0} totalAmount: {1}", id.ToString(), totalAmount.ToString());
                        await _repoAccount.SaveChanges();

                        return(NoContent());
                    }
                }

                //no overdraft, so normal withdraw returns true if account is closed
                if (!await _repoAccount.Withdraw(acctFound.Id, amount))
                {
                    _logger?.LogWarning(string.Format("PUT, withdraw failed, Account is already closed", id.ToString()));
                    return(NotFound(id));
                }
                _logger?.LogInformation("PUT Success withdrew from account with ID: {0}", id.ToString());
                await _repoAccount.SaveChanges();

                return(NoContent());
            }
            catch (Exception e)
            {
                _logger?.LogError(e, "Unexpected Error in withdraw of account with ID: {0}", id.ToString());
                return(StatusCode(500));
            }
        }