This repository has been archived by the owner on Jul 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
353 lines (320 loc) · 12.5 KB
/
Program.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
using System;
using System.Collections.Generic;
using Synergia.NET;
using Synergia.NET.Models;
namespace SynergiaCLI
{
class Program
{
#region Variables
private static SynergiaClient client = new SynergiaClient();
private static Account account;
private static LuckyNumber lucky;
private static List<Subject> subjects;
private static List<Teacher> teachers;
private static List<Lesson> lessons;
private static List<Event> events;
private static List<Attendance> attendances;
private static List<Grade> grades;
private static List<Average> averages;
private static List<TextGrade> textGrades;
private static List<Announcement> announcements;
#endregion
static void Main(string[] args)
{
// Display header and get user credentials
displayHeader();
Console.Write("Username: ");
var username = Console.ReadLine();
Console.Write("Password: ");
var password = Console.ReadLine();
// Create a new instance and login to Synergia
client.Login(username, password);
// Display main screen
displayHeader();
displayMenu();
}
private static void displayHeader()
{
// Clear console screen and write header text (+ add an empty line at the bottom)
Console.Clear();
Console.WriteLine("Synergia.NET API test project\n");
}
private static void displayMenu()
{
//Display menu options
Console.WriteLine("1. Account");
Console.WriteLine("2. Lucky number");
Console.WriteLine("3. Subjects");
Console.WriteLine("4. Teachers");
Console.WriteLine("5. Lessons");
Console.WriteLine("6. Events");
Console.WriteLine("7. Attendances");
Console.WriteLine("8. Grades");
Console.WriteLine("9. Averages");
Console.WriteLine("10. Text grades");
Console.WriteLine("11. Announcements");
// Get input and display proper data
var input = Console.ReadLine();
switch (input)
{
case "1":
displayHeader();
displayAccount();
displayFooter();
break;
case "2":
displayHeader();
displayLuckyNumber();
displayFooter();
break;
case "3":
displayHeader();
displaySubjects();
displayFooter();
break;
case "4":
displayHeader();
displayTeachers();
displayFooter();
break;
case "5":
displayHeader();
displayLessons();
displayFooter();
break;
case "6":
displayHeader();
displayEvents();
displayFooter();
break;
case "7":
displayHeader();
displayAttendances();
displayFooter();
break;
case "8":
displayHeader();
displayGrades();
displayFooter();
break;
case "9":
displayHeader();
displayAverages();
displayFooter();
break;
case "10":
displayHeader();
displayTextGrades();
displayFooter();
break;
case "11":
displayHeader();
displayAnnouncements();
displayFooter();
break;
default:
displayHeader();
displayMenu();
break;
}
}
private static void displayFooter()
{
// Write bottom menu options
Console.WriteLine("\n1. Back");
Console.WriteLine("2. Exit");
// Get input and do proper actions
char input = Console.ReadKey(false).KeyChar;
switch(input)
{
// User chose '1' so we display the main menu combo
case '1':
displayHeader();
displayMenu();
break;
// User chose '2' our program exits
case '2':
Environment.Exit(0);
break;
}
}
private static void displayAccount()
{
Console.WriteLine("Account:");
if (account == null)
{
account = client.GetAccount();
}
Console.WriteLine("Name: " + account.FirstName + " " + account.LastName);
Console.WriteLine("Login: " + account.Login);
Console.WriteLine("Premium status: " + account.IsPremium);
}
private static void displayLuckyNumber()
{
if (lucky == null)
{
lucky = client.GetLuckyNumber();
}
Console.WriteLine("Lucky number: " + lucky.Number);
Console.WriteLine("Lucky number day: " + lucky.LuckyNumberDay.ToString());
}
private static void displaySubjects()
{
Console.WriteLine("Subjects:");
if (subjects == null)
{
subjects = client.GetSubjects();
}
Dictionary<string, Subject> subjectDictionary = client.GetSubjectsIDDictionary();
for (int i = 0; i < subjects.Count; i++)
{
string name = subjects[i].Name;
string id = subjects[i].ID.ToString();
Console.WriteLine("{0} (id: {1})", subjectDictionary[id].Name, id);
}
}
private static void displayTeachers()
{
Console.WriteLine("Teachers:");
if (teachers == null)
{
teachers = client.GetTeachers();
}
Dictionary<string, Teacher> teacherDictionary = client.GetTeachersIDDictionary();
for (int i = 0; i < teachers.Count; i++)
{
string name = teachers[i].FullName;
string id = teachers[i].ID.ToString();
Console.WriteLine("{0} (id: {1})", teacherDictionary[id].FullName, id);
}
}
private static void displayLessons()
{
Console.WriteLine("Lessons:");
if (lessons == null)
{
lessons = client.GetLessons();
}
Dictionary<string, Teacher> teachersDictionary = client.GetTeachersIDDictionary();
Dictionary<string, Subject> subjectDictionary = client.GetSubjectsIDDictionary();
for(int i = 0; i < lessons.Count; i++)
{
string teacherName = teachersDictionary[lessons[i].TeacherID.ToString()].FullName;
string subjectName = subjectDictionary[lessons[i].SubjectID].Name;
string subjectId = lessons[i].SubjectID;
Console.WriteLine("{0} (id: {1}) - {2}", subjectName, subjectId, teacherName);
}
}
private static void displayEvents()
{
Console.WriteLine("Events:");
if (events == null)
{
events = client.GetEvents();
}
Dictionary<string, Teacher> teachersDictionary = client.GetTeachersIDDictionary();
Dictionary<string, EventCategory> eventCategoriesDictionary = client.GetEventCategoriesIDDictionary();
for(int i = 0; i < events.Count; i++)
{
string date = events[i].Date.ToString();
string id = events[i].ID.ToString();
string category = eventCategoriesDictionary[events[i].EventCategoryID].Name;
Console.WriteLine("{0} - {1}(id: {2})", category, date, id);
}
}
private static void displayAttendances()
{
Console.WriteLine("Attendances:");
if (attendances == null)
{
attendances = client.GetAttendances();
}
Dictionary<string, AttendanceCategory> attendanceCategoriesDictionary = client.GetAttendanceCategoriesIDDictionary();
for(int i = 0; i < attendances.Count; i++)
{
string category = attendanceCategoriesDictionary[attendances[i].TypeID].Name;
string date = attendances[i].Date.ToString();
string id = attendances[i].ID;
Console.WriteLine("{0} - {1} (id: {2})", category, date, id);
}
}
private static void displayGrades()
{
Console.WriteLine("Grades:");
if (grades == null)
{
grades = client.GetGrades();
}
Dictionary<string, GradeCategory> gradeCategoriesDictionary = client.GetGradeCategoriesIDDictionary();
Dictionary<string, GradeComment> gradeCommentsDictionary = client.GetGradeCommentsIDDictionary();
for(int i = 0; i < grades.Count; i++)
{
string grade = grades[i].Value.ToString();
string category = gradeCategoriesDictionary[grades[i].CategoryID].Name;
string comment = gradeCommentsDictionary[grades[i].GradeCommentID].Text;
string date = grades[i].Date.ToString();
string id = grades[i].ID;
Console.WriteLine($"Grade: {grade} (id: {id})");
Console.WriteLine($"Category: {category}");
Console.WriteLine($"Comment: {comment}");
Console.WriteLine($"Date: {date}" + Environment.NewLine);
}
}
private static void displayAverages()
{
Console.WriteLine("Averages:");
if (averages == null)
{
averages = client.GetSubjectAverages();
}
Dictionary<string, Subject> sd = client.GetSubjectsIDDictionary();
for (int i = 0; i < averages.Count; i++)
{
string name = sd[averages[i].SubjectID].Name;
string id = averages[i].SubjectID;
string firstSemester = averages[i].FirstSemester;
string secondSemeter = averages[i].SecondSemester;
string final = averages[i].FullYear;
Console.WriteLine($"Subject: {name} (id: {id})");
Console.WriteLine($"Fist semester: {firstSemester}");
Console.WriteLine($"Second semester: {secondSemeter}");
Console.WriteLine($"Final: {final}" + Environment.NewLine);
}
}
private static void displayTextGrades()
{
Console.WriteLine("Text grades:");
if (textGrades == null)
{
textGrades = client.GetTextGrades();
}
Dictionary<string, Subject> subjectDictionary = client.GetSubjectsIDDictionary();
for (int i = 0; i < textGrades.Count; i++)
{
string grade = textGrades[i].Grade;
string id = textGrades[i].ID;
string subject = subjectDictionary[textGrades[i].SubjectID].Name;
Console.WriteLine($"Grade: {grade} (id: {id})");
Console.WriteLine($"Subject: {subject}" + Environment.NewLine);
}
}
private static void displayAnnouncements()
{
Console.WriteLine("Announcements:");
if (announcements == null)
{
announcements = client.GetAnnouncements();
}
for (int i = 0; i < announcements.Count; i++)
{
string id = announcements[i].ID;
string subject = announcements[i].Subject;
string content = announcements[i].Content;
Console.WriteLine("ID: {0}", id);
Console.WriteLine("Subject: {0}", subject);
Console.WriteLine("Content: {0}", content + Environment.NewLine);
}
}
}
}