0% found this document useful (0 votes)
13 views4 pages

Bank Class

The document defines a Bank class within the BankApp namespace. The Bank class contains static properties to store accounts and users in dictionaries. Methods are provided to add accounts, users, link users to accounts, and retrieve accounts and users. Upon initialization, sample accounts and users are created and linked together for testing purposes.

Uploaded by

Shemal Grey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Bank Class

The document defines a Bank class within the BankApp namespace. The Bank class contains static properties to store accounts and users in dictionaries. Methods are provided to add accounts, users, link users to accounts, and retrieve accounts and users. Upon initialization, sample accounts and users are created and linked together for testing purposes.

Uploaded by

Shemal Grey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

namespace BankApp

{
static class Bank
{
static public readonly Dictionary<string, Account> ACCOUNTS = new
Dictionary<string, Account>();

static public readonly Dictionary<string, Person> USERS = new Dictionary<string,


Person>();
static Bank()
{
AddPerson("Narendra", "1234-5678"); //0
AddPerson("Ilia", "2345-6789"); //1
AddPerson("Mehrdad", "3456-7890"); //2
AddPerson("Vinay", "4567-8901"); //3
AddPerson("Arben", "5678-9012"); //4
AddPerson("Patrick", "6789-0123"); //5
AddPerson("Yin", "7890-1234"); //6
AddPerson("Hao", "8901-2345"); //7
AddPerson("Jake", "9012-3456"); //8
AddPerson("Mayy", "1224-5678"); //9
AddPerson("Nicoletta", "2344-6789"); //10

AddAccount(new VisaAccount()); //VS-100000


AddAccount(new VisaAccount(150, -500));//VS-100001
AddAccount(new SavingAccount(5000)); //SV-100002
AddAccount(new SavingAccount()); //SV-100003
AddAccount(new CheckingAccount(2000)); //CK-100004
AddAccount(new CheckingAccount(1500, true));//CK-100005

string number = "VS-100000";

AddUserToAccount(number, "Narendra");

AddUserToAccount(number, "Ilia");

AddUserToAccount(number, "Mehrdad");

number = "VS-100001";

AddUserToAccount(number, "Vijay");

AddUserToAccount(number, "Arben");

AddUserToAccount(number, "Patrick");

number = "SV-100002";

AddUserToAccount(number, "Yin");

AddUserToAccount(number, "Hao");

AddUserToAccount(number, "Jake");
number = "SV-100003";

AddUserToAccount(number, "Mayy");

AddUserToAccount(number, "Nicoletta");

number = "CK-100004";

AddUserToAccount(number, "Mehrdad");

AddUserToAccount(number, "Arben");

AddUserToAccount(number, "Yin");

number = "CK-100005";

AddUserToAccount(number, "Jake");

AddUserToAccount(number, "Nicoletta");

number = "VS-100006";

AddUserToAccount(number, "Ilia");

AddUserToAccount(number, "Vijay");

number = "SV-100007";

AddUserToAccount(number, "Patrick");

AddUserToAccount(number, "Hao");

}
}

public static void PrintAccounts()


{

var imp = ACCOUNTS.Select(x => x.Value.ToString()).Distinct().ToString();


Console.WriteLine(imp);
}
public static void PrintPersons()
{

{ var imp = USERS.Select(x => x.Value.ToString()).Distinct().ToString();


Console.WriteLine(imp); }
}
public static Person GetPerson(string name)
{

var result = USER.FirstOrDefault(x => x.Key.Contains(name)).Value;

if (result != null)
{

return result;
}
else
{
throw new

AccountException(ExceptionTypeEnum.ExceptionType.NAME_NOT_ASSOCIATED_WITH_ACCOUNT);
}
}
public static Account GetAccount(string number)
{

var result = ACCOUNTS.FirstOrDefault(x => x.Key.Contains(number)).Value;

if (result != null)
{
return result;
}
else
{
throw new
AccountException(ExceptionTypeEnum.ExceptionType.ACCOUNT_DOES_NOT_EXIST);

}
}

public static void AddPerson(string name, string sin)


{
Person p = new Person(name, sin);

p.OnLogin.Invoke(this, Logger.LoginHandler(name, new EventArgs()));

USERS.Add(name, p);
}

public static void AddAccount(Account account)


{

ACCOUNTS.Add(account.Number, account);

public static void AddUserToAccount(string number, string name)


{

Account account = ACCOUNTS.FirstOrDefault(x => x.Value.Number.Contains(number)).

Value; Person person = USERS.FirstOrDefault(x =>


x.Value.Name.Contains(name)).Value; account.AddUser(person);
}

public static List<Transaction> GetAllTransactions()


{

return (List<Transaction>)ACCOUNTS.Select(x => x.Value.transactions);

}
}

You might also like