forked from ISS-UBB-2024/StockApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepository.cs
More file actions
185 lines (153 loc) · 7.67 KB
/
Copy pathRepository.cs
File metadata and controls
185 lines (153 loc) · 7.67 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using StockApp.Model;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StockApp
{
class Repository
{
private static Repository _instance;
private List<Stock> stocks = new List<Stock>();
private List<Stock> history = new List<Stock>();
// Tuple<string cnp, UserStock>
private List<Tuple<string, UserStock>> userStocks = new List<Tuple<string, UserStock>>();
private List<User> users = new List<User>();
private List<Transaction> transactions = new List<Transaction>();
// Tuple<string cnp, string stockName>
private List<Tuple<string, string>> favorites = new List<Tuple<string, string>>();
private List<GemDeal> deals = new List<GemDeal>();
private List<Alert> alerts = new List<Alert>();
public Repository()
{
// add 5 users
users.Add(new User("1234567890123", "user1", "user1 description", false, "image1", false));
users.Add(new User("1234567890124", "user2", "user2 description", false, "image2", false));
users.Add(new User("1234567890125", "user3", "user3 description", false, "image3", false));
users.Add(new User("1234567890126", "user4", "user4 description", false, "image4", false));
users.Add(new User("1234567890127", "user5", "user5 description", false, "image5", false));
stocks.Add(new Stock("stock1", "STK1", "1234567890123", 120));
stocks.Add(new Stock("stock2", "STK2", "1234567890124", 130));
stocks.Add(new Stock("stock3", "STK3", "1234567890125", 140));
stocks.Add(new Stock("stock4", "STK4", "1234567890124", 150));
stocks.Add(new Stock("stock5", "STK5", "1234567890123", 160));
history.Add(new Stock("stock1", "STK1", "1234567890123", 100));
history.Add(new Stock("stock1", "STK1", "1234567890123", 120));
history.Add(new Stock("stock1", "STK1", "1234567890123", 130));
history.Add(new Stock("stock1", "STK1", "1234567890123", 160));
history.Add(new Stock("stock1", "STK1", "1234567890124", 100));
history.Add(new Stock("stock1", "STK1", "1234567890124", 120));
history.Add(new Stock("stock1", "STK1", "1234567890124", 130));
history.Add(new Stock("stock1", "STK1", "1234567890124", 160));
// THIS IS BRAINDEAD!!! JUST USE A TUPLE OF STOCK NAME AND QUANTITY !!! :CCCC
userStocks.Add(new Tuple<string, UserStock>("1234567890123", new UserStock("stock1", "STK1", "1234567890123", 10)));
userStocks.Add(new Tuple<string, UserStock>("1234567890124", new UserStock("stock1", "STK1", "1234567890123", 10)));
userStocks.Add(new Tuple<string, UserStock>("1234567890125", new UserStock("stock1", "STK1", "1234567890123", 10)));
userStocks.Add(new Tuple<string, UserStock>("1234567890126", new UserStock("stock1", "STK1", "1234567890123", 10)));
userStocks.Add(new Tuple<string, UserStock>("1234567890127", new UserStock("stock1", "STK1", "1234567890123", 10)));
// Transaction has no STOCK NAME??? km
transactions.Add(new Transaction("stock1", "STK1", "1234567890123", "buy", 10, 120, 1200, DateTime.Now, "1234567890123"));
transactions.Add(new Transaction("stock1", "STK1", "1234567890124", "buy", 10, 120, 1200, DateTime.Now, "1234567890124"));
transactions.Add(new Transaction("stock1", "STK1", "1234567890125", "buy", 10, 120, 1200, DateTime.Now, "1234567890125"));
transactions.Add(new Transaction("stock1", "STK1", "1234567890126", "buy", 10, 120, 1200, DateTime.Now, "1234567890126"));
transactions.Add(new Transaction("stock1", "STK1", "1234567890127", "buy", 10, 120, 1200, DateTime.Now, "1234567890127"));
favorites.Add(new Tuple<string, string>("1234567890123", "stock1"));
favorites.Add(new Tuple<string, string>("1234567890123", "stock2"));
favorites.Add(new Tuple<string, string>("1234567890123", "stock3"));
deals.Add(new GemDeal("deal1", 150, 130, false));
deals.Add(new GemDeal("deal2", 150, 130, false));
deals.Add(new GemDeal("deal3", 150, 130, false));
deals.Add(new GemDeal("deal4", 150, 130, false));
alerts.Add(new Alert { AlertId = 1, StockName = "stock1", Name = "Alert1", UpperBound = 150, LowerBound = 100, ToggleOnOff = true });
alerts.Add(new Alert { AlertId = 2, StockName = "stock2", Name = "Alert2", UpperBound = 200, LowerBound = 150, ToggleOnOff = false });
alerts.Add(new Alert { AlertId = 3, StockName = "stock3", Name = "Alert3", UpperBound = 250, LowerBound = 200, ToggleOnOff = true });
alerts.Add(new Alert { AlertId = 4, StockName = "stock4", Name = "Alert4", UpperBound = 300, LowerBound = 250, ToggleOnOff = false });
alerts.Add(new Alert { AlertId = 5, StockName = "stock5", Name = "Alert5", UpperBound = 350, LowerBound = 300, ToggleOnOff = true });
}
public static Repository Instance
{
get
{
if (_instance == null)
{
_instance = new Repository();
}
return _instance;
}
}
public List<Stock> getStockList()
{
return stocks;
}
public List<Stock> getStockHistory(string name)
{
return history.FindAll(stock => stock.Name == name);
}
public List<UserStock> getUserStocks(string cnp)
{
return userStocks.FindAll(stock => stock.Item1 == cnp).ConvertAll(stock => stock.Item2);
}
public void updateUserStocks(string cnp, List<UserStock> newStocks)
{
userStocks.RemoveAll(stock => stock.Item1 == cnp);
foreach (UserStock stock in newStocks)
{
userStocks.Add(new Tuple<string, UserStock>(cnp, stock));
}
}
public User getUserInformation(string cnp)
{
return users.Find(user => user.CNP == cnp);
}
public void updateUserInformation(string cnp, User user)
{
users.RemoveAll(u => u.CNP == cnp);
users.Add(user);
}
public void updateUserFavorites(string cnp, List<string> newFavorites)
{
favorites.RemoveAll(favorite => favorite.Item1 == cnp);
foreach (string favorite in newFavorites)
{
favorites.Add(new Tuple<string, string>(cnp, favorite));
}
}
public List<string> getUserFavorites(string cnp)
{
return favorites.FindAll(favorite => favorite.Item1 == cnp).ConvertAll(favorite => favorite.Item2);
}
public List<Transaction> getAllTransactions()
{
return transactions;
}
public void updateAllTransactions(List<Transaction> newList)
{
transactions = newList;
}
// +getPermanentGemDeals(): List<GemDeals>
public List<GemDeal> getPermanentGemDeals()
{
return deals;
}
// +fetchCurrentUser(): User // WHO ADDED THIS??
// TODO: ALERTS
public List<Alert> getAlerts()
{
return alerts;
}
public void updateAlerts(List<Alert> newAlerts)
{
alerts = newAlerts;
}
public void addAlert(Alert alert)
{
alerts.Add(alert);
}
public void removeAlert(int alertId)
{
alerts.RemoveAll(alert => alert.AlertId == alertId);
}
}
}