-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cpp
More file actions
151 lines (132 loc) · 3.76 KB
/
User.cpp
File metadata and controls
151 lines (132 loc) · 3.76 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
//
// Created by Luca Teodorescu on 20.03.2026.
//
#include "User.h"
#include "Account.h"
#include <iostream>
User::User(const string &FirstName, const string &LastName, const string &CNP, const string &BirthDate) {
this->FirstName = FirstName;
this->LastName = LastName;
this->CNP = CNP;
this->BirthDate = BirthDate;
Account *new_account = new Account(this);
string IBAN = new_account->GetIBAN();
if (!AllAccounts.contains(IBAN)) {
AllAccounts[IBAN] = new_account;
}
else {
delete new_account;
cout << "Eroare critică: IBAN duplicat generat!" << '\n';
}
}
User::User(const string &FirstName, const string &LastName, const string &CNP, const string &BirthDate, const string ¤cy) {
this->FirstName = FirstName;
this->LastName = LastName;
this->CNP = CNP;
this->BirthDate = BirthDate;
Account *new_account = new Account(this, currency);
string IBAN = new_account->GetIBAN();
if (AllAccounts.find(IBAN) == AllAccounts.end()) {
AllAccounts[IBAN] = new_account;
}
}
string User::GetBirthDate() {
return this->BirthDate;
}
string User::GetFirstName() {
return this->FirstName;
}
string User::GetLastName() {
return this->LastName;
}
string User::GetCNP() {
return this->CNP;
}
void User::AddAccount(const string ¤cy) {
Account *new_account = new Account(this, currency);
string IBAN = new_account->GetIBAN();
if (AllAccounts.find(IBAN) == AllAccounts.end()) {
AllAccounts[IBAN] = new_account;
}
}
void User::DeleteAccount() {
for (const auto &it : AllAccounts) {
Account *account = it.second;
account->DeleteWallet();
}
AllAccounts.clear();
}
void User::DeleteAccount(const string &IBAN) {
auto it = AllAccounts.find(IBAN);
if (it != AllAccounts.end()) {
delete it->second;
AllAccounts.erase(it);
cout << "Contul cu IBAN-ul " << IBAN << " a fost sters cu succes din sistem.\n";
}
else {
cout << "Eroare: Acest IBAN nu apartine utilizatorului curent!\n";
}
}
void User::AddWallet(const string &IBAN) {
if (AllAccounts.find(IBAN) == AllAccounts.end()) {
Account *new_account = new Account(this);
new_account->addWallet();
}
else {
Account *new_account = AllAccounts[IBAN];
new_account->addWallet();
}
}
void User::DeleteWallet(const string &IBAN, const string &WalletID) {
if (AllAccounts.find(IBAN) != AllAccounts.end()) {
Account *account = AllAccounts[IBAN];
account->DeleteWallet(WalletID);
}
else {
cout << "IBAN invalid" << '\n';
}
}
Account *User::GetAccount(const string &IBAN) {
if (AllAccounts.find(IBAN) != AllAccounts.end()) {
Account *account = AllAccounts[IBAN];
return account;
}
}
void User::SendFriendInvitation(const string &CNP) {
if (SentFriendInvitations.find(CNP) == SentFriendInvitations.end()) {
SentFriendInvitations[CNP] = true;
}
else {
cout << "Invitation already exists" << endl;
}
}
bool User::AcceptFriendInvitation(const string &CNP) {
if (AcceptedFriendInvitations.find(CNP) == AcceptedFriendInvitations.end()) {
AcceptedFriendInvitations[CNP] = true;
return true;
}
else {
cout << "Invitation already accepted" << '\n';
return false;
}
}
void User::AddFriend(const string &CNP) {
Friends[CNP] = true;
}
void User::EraseFriend(const string &CNP) {
if (Friends.find(CNP) != Friends.end()) {
Friends.erase(CNP);
}
}
bool User::CheckFriend(const string &CNP) {
if (Friends.find(CNP) != Friends.end()) {
return true;
}
return false;
}
User::~User() {
for (auto &it : AllAccounts) {
delete it.second;
}
AllAccounts.clear();
}