public async Task <ActionResult> Close(int id) { _logger?.LogInformation(string.Format("Attempting to Close account with id: {0}", id.ToString())); try { Account acctFound = null; acctFound = await _repoAccount.GetAccountDetailsByAccountID(id); if (acctFound == null) //check if account exist { _logger?.LogWarning(string.Format("DELETE request failed, No Account found with ID: {0}", id.ToString())); return(NotFound(id)); } if (acctFound.Balance != 0) //make sure account has no funds and also has no overdraft { _logger?.LogWarning(string.Format("DELETE request failed, Balance is not 0. Account with ID: {0}", id.ToString())); return(StatusCode(400)); } await _repoAccount.CloseAccount(acctFound.Id); //close the account _logger?.LogInformation("DELETE Success Closed account with ID: {0}", id.ToString()); await _repoAccount.SaveChanges(); return(Ok()); } catch (Exception e) { _logger?.LogError(e, "Unexpected Error in Delete account with ID: {0}", id.ToString()); return(StatusCode(500)); } }
public async Task <ActionResult> CloseLoan(int id) { try { Account acct = await _repo.GetAccountDetailsByAccountID(id); if (acct == null) { _logger?.LogWarning(string.Format("LoanAccountController DELETE request failed, Account not found. Account with ID: {0}", id)); return(NotFound(id)); } else { if (acct.Balance > 0) { _logger?.LogWarning(string.Format("LoanAccountController DELETE request failed, Account not empty. Account with ID: {0}", id)); return(StatusCode(400)); } else { await _repo.CloseAccount(id); await _repo.SaveChanges(); return(NoContent()); } } } catch (Exception e) { _logger.LogError(e, "Unexpected Error in LoanAccountController!"); return(StatusCode(500)); } }