-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewStudentDataRecord.cs
More file actions
80 lines (74 loc) · 3.21 KB
/
ViewStudentDataRecord.cs
File metadata and controls
80 lines (74 loc) · 3.21 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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ITPAssignment1
{
internal class ViewStudentDataRecord
{
private Dictionary<string, StudentRecordData> studentRecords;
private string dataDirectory = "UserData";
public ViewStudentDataRecord(Dictionary<string, StudentRecordData> studentRecords)
{
this.studentRecords = studentRecords;
}
public void ViewStudentData()
{
Console.WriteLine("");
Console.Write("Please Enter The Student's ID Number: ");
string studentID = Console.ReadLine();
if (studentRecords.ContainsKey(studentID))
{
string jsonPath = Path.Combine(dataDirectory, $"{studentID}.json");
string textPath = Path.Combine(dataDirectory, $"{studentID}.txt");
if (File.Exists(jsonPath))
{
string json = File.ReadAllText(jsonPath);
StudentRecordData studentData = JsonConvert.DeserializeObject<StudentRecordData>(json);
Console.WriteLine("");
Console.WriteLine("Reading Student Data From JSON Database"); // Read JSON Data
Console.WriteLine("");
Console.WriteLine($"Student ID: {studentData.StudentID}");
Console.WriteLine($"Student Name: {studentData.StudentName}");
Console.WriteLine($"Marks: {string.Join(", ", studentData.Marks)}");
Console.WriteLine($"Notes: {string.Join(", ", studentData.Notes)}");
Console.WriteLine("");
if (studentData.NewMarks.Any()) // Check If Marks Have Been Updated Or Not
{
Console.WriteLine($"Updated Marks: {string.Join(", ", studentData.NewMarks)}");
Console.WriteLine($"Updated Notes: {studentData.NewNotes}");
Console.WriteLine("");
}
}
else if (File.Exists(textPath))
{
using (StreamReader reader = new StreamReader(textPath))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine("");
Console.WriteLine(line);
Console.WriteLine("");
}
}
}
else
{
Console.WriteLine("");
Console.WriteLine("Student Data Record Not Found, Please Try Again With A Valid ID"); // Error Handling
Console.WriteLine("");
}
}
else
{
Console.WriteLine("");
Console.WriteLine("Student Data Record Not Found, Please Try Again With A Valid ID"); // Error Handling
Console.WriteLine("");
}
}
}
}