-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankRepository.cs
55 lines (48 loc) · 1.45 KB
/
BankRepository.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using ALM.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ALM.Web
{
public class BankRepository
{
public List<Customer> Customers { get; set; } = new List<Customer>();
public List<Account> Accounts { get; set; } = new List<Account>();
public BankRepository()
{
this.Initialize();
}
public Customer AddCustomer(string firstName, string lastName)
{
var customer = new Customer
{
CustomerId = Customers.Any() ? Customers.Max(a => a.CustomerId) + 1 : 0,
FirstName = firstName,
LastName = lastName
};
Customers.Add(customer);
return customer;
}
public Account AddAccount(Customer owner)
{
var account = new Account
{
AccountId = Accounts.Any() ? Accounts.Max(a => a.AccountId) + 1 : 0,
Owner = owner
};
owner.Accounts.Add(account);
Accounts.Add(account);
return account;
}
public Account GetAccount(int accountId)
{
var account = Accounts.FirstOrDefault(a => a.AccountId == accountId);
if (account == null)
{
throw new AccountNotFoundException(accountId);
}
return account;
}
}
}