-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMSystem.cs
146 lines (130 loc) · 3.89 KB
/
IMSystem.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using InventoryManagementSystem.Members;
using InventoryManagementSystem.Products;
using InventoryManagementSystem.Transactions;
namespace InventoryManagementSystem
{
public class IMSystem
{
private List<IMember> members = new List<IMember>();
private List<IProduct> products = new List<IProduct>();
private List<Transaction> transactions = new List<Transaction>();
public void AddMember(IMember member)
{
if (member == null)
{
Console.WriteLine("Member is null");
return;
}
if (!members.Contains(member))
members.Add(member);
else
UpdateMember(member);
}
public void UpdateMember(IMember member)
{
if (member != null && members.Contains(member))
{
members.Remove(member);
members.Add(member);
}
else
Console.WriteLine("Member not found");
}
public void DeleteMember(IMember member)
{
if (member != null)
members.Remove(member);
}
public void DisplayMembers()
{
foreach (var member in members)
{
Console.WriteLine(member);
}
}
public void AddProduct(IProduct product)
{
if (product == null)
{
Console.WriteLine("Product is null");
return;
}
if (!products.Contains(product))
products.Add(product);
else
UpdateProduct(product);
}
public void UpdateProduct(IProduct product)
{
if (product != null && products.Contains(product))
{
int index = products.IndexOf(product);
products.Remove(product);
products.Add(product);
Console.WriteLine($"Product #{product.ID} {product.Name} updated");
}
else
Console.WriteLine("Product not found");
}
public void DeleteProduct(IProduct product)
{
if (product != null)
products.Remove(product);
}
public void DisplayProducts()
{
DisplayProducts<IProduct>();
}
public void DisplayProducts<T>()
{
foreach (var product in products)
{
if (product is T)
{
Console.WriteLine(product);
}
}
}
public void AddTransaction(Transaction transaction)
{
if (transaction == null)
{
Console.WriteLine("Transaction is null");
return;
}
if (!transactions.Contains(transaction))
transactions.Add(transaction);
else
UpdateTransaction(transaction);
}
public void UpdateTransaction(Transaction transaction)
{
if (transaction != null && transactions.Contains(transaction))
{
transactions.Remove(transaction);
transactions.Add(transaction);
}
else
Console.WriteLine("Transaction not found");
}
public void DeleteTransaction(Transaction transaction)
{
if (transaction != null)
transactions.Remove(transaction);
}
public void DisplayTransactions()
{
DisplayTransactions<IProduct>();
}
public void DisplayTransactions<T>()
{
foreach (var transaction in transactions)
{
if (transaction.Product is T)
{
transaction.Display();
}
}
}
}
}