-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
198 lines (167 loc) · 4.76 KB
/
Program.cs
File metadata and controls
198 lines (167 loc) · 4.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
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
//1.Group yarat
/*2.Grouplari goster
3.Group sil
4.Student yarat
5.Studentleri goster
6.Student sil*/
using Microsoft.EntityFrameworkCore;
using ormStudent;
using AppDBContext context = new AppDBContext();
START:
Console.WriteLine(" ");
Console.WriteLine("1.Group yarat");
Console.WriteLine("2.Grouplari goster");
Console.WriteLine("3.Group sil");
Console.WriteLine("4.Student yarat");
Console.WriteLine("5.Studentleri goster");
Console.WriteLine("6.Student sil");
Console.WriteLine(" ");
string choice = Console.ReadLine();
Console.Clear();
switch (choice)
{
case "1":
Console.Write("Yeni yaradacaginiz Groupun adi:");
string gName = Console.ReadLine();
Group groups = new()
{
Name = gName
};
context.Groups.Add(groups);
var result=context.SaveChanges();
if (result > 0)
{
Console.WriteLine("Group ugurla yaradildi");
}
goto START;
break;
case "2":
ShowAllGroup(context);
goto START;
break;
case "3":
IdGroupDelete:
ShowAllGroup(context);
Console.Write("Silmek istediyiniz ID-ni secin:");
string deleteIdGroup = Console.ReadLine();
bool isDeletedGroup = int.TryParse(deleteIdGroup, out int idGroup);
if (!isDeletedGroup)
{
Console.WriteLine("Duzgun deyer daxil et!");
goto IdGroupDelete;
}
Group deletedGroup = context.Groups.FirstOrDefault(s => s.Id == idGroup);
if (deletedGroup == null)
{
Console.WriteLine("Silmek istediyiniz Group movcud deyil");
break;
}
context.Groups.Remove(deletedGroup);
var deleteGroup = context.SaveChanges();
if (deleteGroup > 0)
{
Console.WriteLine("Group ugurla silindi");
}
goto START;
break;
case "4":
sNameInput:
Console.Write("Yeni yaradacaginiz Studentin adi:");
string sName = Console.ReadLine();
if (sName == null || sName.Length < 3)
{
Console.WriteLine("Duzgun deyer daxil et!");
goto sNameInput;
}
Console.Write("Yeni yaradacaginiz Studentin yasi:");
int age = Convert.ToInt32(Console.ReadLine());
gradeInput:
Console.Write("Yeni yaradacaginiz Studentin qiymeti:");
string grade = Console.ReadLine();
var isParsed = decimal.TryParse(grade, out decimal DCgrade);
if (!isParsed)
{
Console.WriteLine("Duzgun deyer daxil et!");
goto gradeInput;
}
groupIdInput:
var gr = context.Groups.ToList();
foreach (var item in gr)
{
Console.WriteLine(item);
}
Console.Write("Istediyiniz GroupsID-ni daxil edin:");
string groupIdInput = Console.ReadLine();
var isParsedGroupId = int.TryParse(groupIdInput, out int DCgroupId);
if (!isParsedGroupId)
{
Console.WriteLine("Duzgun deyer daxil et!");
goto groupIdInput;
}
bool isExistGroup = context.Groups.Any(g => g.Id == DCgroupId);
if (!isExistGroup)
{
Console.WriteLine("Duzgun deyer daxil et!");
goto groupIdInput;
}
Student students = new()
{
Name = sName,
Age = age,
Grade = DCgrade,
GroupsId = DCgroupId
};
context.Students.Add(students);
var yekun = context.SaveChanges();
if (yekun > 0)
{
Console.WriteLine("Student ugurla elave edildi");
}
goto START;
break;
case "5":
ShowAll(context);
goto START;
break;
case "6":
IDinput:
ShowAll(context);
Console.Write("Silmek istediyiniz ID-ni secin:");
string deleteIdInput = Console.ReadLine();
bool isDeleted = int.TryParse(deleteIdInput, out int id);
if (!isDeleted)
{
Console.WriteLine("Duzgun deyer daxil et!");
goto IDinput;
}
Student deletedStudent = context.Students.FirstOrDefault(s => s.Id == id);
if (deletedStudent == null)
{
Console.WriteLine("Silmek istediyiniz Student movcud deyil");
break;
}
context.Students.Remove(deletedStudent);
var deleteYekun = context.SaveChanges();
if (deleteYekun > 0)
{
Console.WriteLine("Student ugurla silindi");
}
goto START;
break;
}
static void ShowAll(AppDBContext context)
{
var forStudents = context.Students.Include(x => x.Groups).ToList();
foreach (var item in forStudents)
{
Console.WriteLine(item);
}
}
static void ShowAllGroup(AppDBContext context)
{
var forGroup = context.Groups.ToList();
foreach (var item in forGroup)
{
Console.WriteLine(item);
}
}