-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin.cs
More file actions
160 lines (146 loc) · 4.7 KB
/
Admin.cs
File metadata and controls
160 lines (146 loc) · 4.7 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassInheritance2
{
internal class Admin : User
{
public List<Teacher> Teachers { get; set; }
public List<Student> Students { get; set; }
public Admin(string univer, string fio) : base(univer, fio)
{
Teachers = new List<Teacher>();
Students = new List<Student>();
}
public void AddTeacher(Teacher teacher)
{
if (!Teachers.Contains(teacher))
{
Teachers.Add(teacher);
Console.WriteLine($"Teacher {teacher.Fio} added to database");
}
else
Console.WriteLine($"The teacher {teacher.Fio} is already in the database");
}
public void DeleteTeacher(string fio)
{
bool flag = false;
foreach (Teacher t in Teachers)
{
if (t.Fio == fio)
{
Teachers.Remove(t);
flag = true;
Console.WriteLine($"Teacher {fio} removed from the database");
break;
}
}
if (!flag)
Console.WriteLine("Teacher is not found.");
}
public void AddTeacherSubject(string fio, string subject)
{
bool flag = false;
foreach (Teacher t in Teachers)
{
if (t.Fio == fio)
{
t.AddSubject(subject);
flag = true;
Console.WriteLine($"An item \'{subject}\' has been added to teacher {fio}");
break;
}
}
if (!flag)
Console.WriteLine("Teacher is not found.");
}
public void DeleteTeacherSubject(string fio, string subject)
{
bool flag = false;
foreach (Teacher t in Teachers)
{
if (t.Fio == fio)
{
t.DeleteSubject(subject);
flag = true;
Console.WriteLine($"Teacher {fio} subject \'{subject}\' has been removed");
break;
}
}
if (!flag)
Console.WriteLine("Teacher is not found.");
}
public void AddStudent(Student student)
{
if (!Students.Contains(student))
{
Students.Add(student);
Console.WriteLine($"Student {student.Fio} added to database");
}
else
Console.WriteLine($"The student {student.Fio} is already in the database");
}
public void DeleteStudent(string fio)
{
bool flag = false;
foreach (Student stud in Students)
{
if (stud.Fio == fio)
{
Students.Remove(stud);
flag = true;
Console.WriteLine($"Student{fio} removed from the database");
break;
}
}
if (!flag)
Console.WriteLine("Student is not found.");
}
public void AddStudentSubject(string fio, string subject, int grade)
{
bool flag = false;
foreach (Student stud in Students)
{
if (stud.Fio == fio)
{
stud.AddSubject(subject, grade);
Console.WriteLine($"An item \'{subject}\' has been added to student {fio}");
flag = true;
break;
}
}
if (!flag)
Console.WriteLine("Student is not found.");
}
public void DeleteStudentSubject(string fio, string subject)
{
bool flag = false;
foreach (Student stud in Students)
{
if (stud.Fio == fio)
{
stud.DeleteSubject(subject);
Console.WriteLine($"Teacher {fio} subject \'{subject}\' has been removed");
flag = true;
break;
}
}
if (!flag)
Console.WriteLine("Student is not found.");
}
public override void PrintInfo()
{
base.PrintInfo();
foreach (var t in Teachers)
{
Console.WriteLine($"TeacherName: {t.Fio}");
}
foreach (var stud in Students)
{
Console.WriteLine($"StudentName: {stud.Fio}");
}
}
}
}