Class BankRepository
- Namespace
- BankBackend.Repository
- Assembly
- BankBackend.dll
public class BankRepository : IBankRepository
- Inheritance
-
BankRepository
- Implements
- Inherited Members
Constructors
BankRepository(BankContext)
constructor for dependency injection
public BankRepository(BankContext bankContext)
Parameters
bankContextBankContext
BankRepository(string)
public BankRepository(string connectionString)
Parameters
connectionStringstring
Methods
AddAccountToUser(int, int)
adds account with accountId to the account list of the user with userId
public User? AddAccountToUser(int accountId, int userId)
Parameters
Returns
- User
the updated user with the added account, null if the user does not exist
AddUserToAccount(int, int)
adds user with userId to the account list of the account with accountId
public Account? AddUserToAccount(int userId, int accountId)
Parameters
Returns
- Account
the updated account with the new user, null if account does not exist or if user does not exist
CreateAccount(Account)
uploads the account to database
public Account CreateAccount(Account account)
Parameters
accountAccount
Returns
- Account
the account that was just created
CreateTransaction(Transaction)
uploads the transaction to database
public Transaction CreateTransaction(Transaction transaction)
Parameters
transactionTransaction
Returns
- Transaction
the transaction that was just created
CreateUser(User)
uploads the user to database
public User CreateUser(User user)
Parameters
userUser
Returns
- User
the user that was just created
DeleteAccountById(int)
deletes the account with accountId
public Account? DeleteAccountById(int accountId)
Parameters
accountIdint
Returns
- Account
the account that was just deleted, null if the account does not exist
DeleteAccountUserByUserId(int, int)
deletes the user with userId from the account with accountId
public User? DeleteAccountUserByUserId(int accountId, int userId)
Parameters
Returns
- User
the user that was just deleted, null if the account does not exist, or if the account does not have an user with
userId
DeleteTransactionByTransactionId(int)
deletes the transaction with transactionId
public Transaction? DeleteTransactionByTransactionId(int transactionId)
Parameters
transactionIdint
Returns
- Transaction
the transaction that was just deleted, null if the transaction does not exist
DeleteUserAccountByAccountId(int, int)
deletes the account with accountId from the user with userId
public Account? DeleteUserAccountByAccountId(int userId, int accountId)
Parameters
Returns
- Account
the account that was just deleted, null if user does not exist, or the user does not have an account with
accountId
DeleteUserById(int)
deletes the user with userId
public User? DeleteUserById(int userId)
Parameters
userIdint
Returns
- User
the user that was just deleted, null if the user does not exist
GetAccountByAccountId(int)
find an account with accountId
public Account? GetAccountByAccountId(int accountId)
Parameters
accountIdint
Returns
- Account
the account with
accountId, null if account does not exist
GetAccountsByUserId(int)
find all the accounts of the user with userId
public List<Account>? GetAccountsByUserId(int userId)
Parameters
userIdint
Returns
GetAllAccounts()
find all existing accounts in the database
public List<Account> GetAllAccounts()
Returns
GetAllTransactions()
find all existing transactions in the database
public List<Transaction> GetAllTransactions()
Returns
- List<Transaction>
list containing all existing transactions, empty list if non exists
GetAllUsers()
find all existing users in the database
public List<User> GetAllUsers()
Returns
GetPrimaryAccountsByUserId(int)
find all the accounts that the user with accountId is a primary user
public List<Account>? GetPrimaryAccountsByUserId(int userId)
Parameters
userIdint
Returns
GetTransactionByTransactionId(int)
find a transaction with transactionId
public Transaction? GetTransactionByTransactionId(int transactionId)
Parameters
transactionIdint
Returns
- Transaction
the transaction with
transactionId, null if transaction does not exist
GetTransactionsByFromAccountId(int)
public List<Transaction> GetTransactionsByFromAccountId(int fromAccountId)
Parameters
fromAccountIdint
Returns
GetTransactionsByToAccountId(int)
public List<Transaction> GetTransactionsByToAccountId(int toAccountId)
Parameters
toAccountIdint
Returns
GetUserByUserId(int)
find a user with userId
public User? GetUserByUserId(int userId)
Parameters
userIdint
Returns
- User
the user with the Id, null if user does not exist
GetUserByUsername(string)
find a user with username
public User? GetUserByUsername(string username)
Parameters
usernamestring
Returns
- User
the user with the username, null if user does not exist
GetUsersByAccountId(int)
find all the users of the account with accountId
public List<User>? GetUsersByAccountId(int accountId)
Parameters
accountIdint
Returns
UpdateBalance(int, double)
updates the balance of the account with accountId to balance
public Account? UpdateBalance(int accountId, double balance)
Parameters
Returns
- Account
the updated account with the new balance, null if the account does not exist
UpdatePassword(int, string)
updates the password of user with userId to password
public User? UpdatePassword(int userId, string password)
Parameters
Returns
- User
the updated user with the new password, null if the user does not exist
UpdatePrimaryUser(int, int)
replaces the primary user of the account with accountId with userId
public Account? UpdatePrimaryUser(int accountId, int userId)
Parameters
Returns
- Account
the updated account with the new primary user, null if account doesnot exist or if user does not exist
UpdateUsername(int, string)
updates the name of the user with userId to name
public User? UpdateUsername(int userId, string username)
Parameters
Returns
- User
the updated user with the new username, null if the user does not exist