Skip to content

Commit 4839a7b

Browse files
committed
Complete Credit Restriction
1 parent 5082b12 commit 4839a7b

File tree

6 files changed

+73
-45
lines changed

6 files changed

+73
-45
lines changed

StudentDemo/src/main/java/com/Student/StudentDemo/Controller/StudentController.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class StudentController {
2929
private String sutdentId;
3030
private String sutdentName;
3131
private int sutdentkeyId;
32+
private int totalCredit = 0;
3233

3334
@Autowired
3435
private StudentDao studentDao;
@@ -149,19 +150,36 @@ public String processaddSelectedStudentCourse(@RequestParam("studentKeyId") int
149150
@RequestParam("courseKeyId") int courseKeyId, Model model) {
150151
CourseDetails courseDetails = courseDao.findOne(courseKeyId);
151152
StudentDetails studentDetails = studentDao.findOne(studentKeyId);
153+
154+
getCredit();
155+
totalCredit += courseDetails.getCourseCredit();
156+
152157
for (CourseDetails c: sortedCouserList) {
153-
if(courseKeyId == c.getId())
158+
159+
if(totalCredit > 15)
160+
{
161+
model.addAttribute("courseList", courseDao.findAll());
162+
model.addAttribute("studentKeyId", sutdentkeyId);
163+
model.addAttribute("title", sutdentName + " : " + sutdentId);
164+
model.addAttribute("errors", "You have already taken 15 credit");
165+
totalCredit = 0;
166+
167+
return "Student/addCourseForStudent";
168+
}
169+
else if(courseKeyId == c.getId())
154170
{
155171
model.addAttribute("courseList", courseDao.findAll());
156172
model.addAttribute("studentKeyId", sutdentkeyId);
157173
model.addAttribute("title", sutdentName + " : " + sutdentId);
158174
model.addAttribute("errors", "Course is already selected!");
175+
totalCredit = 0;
159176

160177
return "Student/addCourseForStudent";
161178
}
162179
}
163180
studentDetails.addCourse(courseDetails);
164181
studentDao.save(studentDetails);
182+
totalCredit = 0;
165183

166184
return "redirect:/Student/viewCourseForStudent?studentKeyId="+studentKeyId+"";
167185
}
@@ -174,7 +192,17 @@ public String getSelectedStudentCourse(@RequestParam("studentKeyId") int student
174192
sutdentName = student.getName();
175193
model.addAttribute("List", sortedCouserList);
176194
model.addAttribute("title", sutdentName + " : " + sutdentId);
195+
model.addAttribute("totalCredit", "Total Credit : " + getCredit());
196+
totalCredit = 0;
177197

178198
return "Student/viewCourseForStudent";
179199
}
200+
201+
public int getCredit()
202+
{
203+
for (CourseDetails c: sortedCouserList) {
204+
totalCredit += c.getCourseCredit();
205+
}
206+
return totalCredit;
207+
}
180208
}

StudentDemo/src/main/resources/static/css/style.css

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ body{
3434
.navbar ul li a{
3535
display: inline-block;
3636
text-decoration: none;
37-
color: #2880d7;;
37+
color: #2880d7;
3838
padding: 0 20px 0 0;
3939
margin: 0 5px;
4040
position: relative;
@@ -83,6 +83,12 @@ body{
8383
margin-top: 20px;
8484
}
8585

86+
.viewCourseForStudentFull{
87+
margin-top: 20px;
88+
overflow: hidden;
89+
background-color: #ecf0f1;
90+
padding: 20px;
91+
}
8692
.addCourseForStudent{
8793
display: block;
8894
overflow: hidden;
@@ -107,34 +113,21 @@ body{
107113
padding: 30px;
108114
background-color: #ecf0f1;
109115
}
110-
.depertmentList ul{
111-
list-style: none;
116+
.depertmentList ol{
112117
margin: 0;
113118
padding: 0;
114-
margin: 10px 0;
119+
margin: 20px 20px;
115120
}
116-
.depertmentList ul li{
121+
.depertmentList ol li{
117122

118123
}
119-
.depertmentList ul li a{
120-
background-color: #02CCFF;
121-
padding: 10px;
122-
display: inline-block;
123-
margin: 10px 0;
124-
min-width: 200px;
125-
text-align: center;
126-
font-size: 24px;
127-
font-weight: 400;
124+
.depertmentList ol li a{
128125
letter-spacing: 1px;
129-
color: #ffffff;
126+
color: #2880d7;
130127
text-decoration: none;
131-
border-bottom: 6px solid transparent;
132-
border-radius: 4px;
133-
transition: 1s;
134128
}
135-
.depertmentList ul li a:hover{
136-
border-bottom: 6px solid #2450e7;
137-
transition: 1s;
129+
.depertmentList ol li a:hover{
130+
color: #07bfd5;
138131
}
139132

140133

StudentDemo/src/main/resources/templates/Course/Course.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h1 th:text="${title}"></h1>
2121
</tr>
2222
</table>
2323
<a class="btn btn-success" href="/Course/addCourse">Add Course</a>
24-
<a class="btn btn-danger" href="/Student/removeStudent">Remove Student</a>
24+
<a class="btn btn-danger" href="">Remove Course</a>
2525
</div>
2626
</div>
2727
</body>

StudentDemo/src/main/resources/templates/Depertment/Depertment.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ <h1 th:text="${title}"></h1>
88
<nav th:replace="fragments :: navigation"></nav>
99
</div>
1010
<div class="depertmentList">
11-
<ul class="deptList">
11+
<ol class="deptList">
1212
<li th:each="deptList : ${deptList}"><a th:href="@{/Student/asDepertment(deptId=${deptList.Id})}" th:text="${deptList.DeptName}"></a></li>
13-
</ul>
13+
</ol>
1414
<a class="btn btn-success" href="/Depertment/addDepertment">Add Department</a>
1515
</div>
1616
</div>

StudentDemo/src/main/resources/templates/Student/removeStudent.html

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,29 @@ <h1 th:text="${title}"></h1>
88
<nav th:replace="fragments :: navigation"></nav>
99
</div>
1010

11-
<form action="" method="post">
12-
<table class="table">
13-
<tr>
14-
<th>Check</th>
15-
<th>ID</th>
16-
<th>Name</th>
17-
<th>Email</th>
18-
<th>Department</th>
19-
</tr>
20-
<tr th:each="list : ${studentList}">
21-
<td><input type="checkbox" name="studentCheckedId" th:value="${list.Id}"/></td>
22-
<td th:text="${list.studentId}"></td>
23-
<td th:text="${list.Name}"></td>
24-
<td th:text="${list.Email}"></td>
25-
<td th:text="${list.depertmentDetails.DeptName}"></td>
26-
</tr>
27-
</table>
28-
<input class="btn btn-danger" type="submit" value="Remove Student"/>
29-
</form>
11+
<div class="studentTable">
12+
<form action="" method="post">
13+
<table class="table">
14+
<tr>
15+
<th>Check</th>
16+
<th>ID</th>
17+
<th>Name</th>
18+
<th>Email</th>
19+
<th>Department</th>
20+
</tr>
21+
<tr th:each="list : ${studentList}">
22+
<td><input type="checkbox" name="studentCheckedId" th:value="${list.Id}"/></td>
23+
<td th:text="${list.studentId}"></td>
24+
<td th:text="${list.Name}"></td>
25+
<td th:text="${list.Email}"></td>
26+
<td th:text="${list.depertmentDetails.DeptName}"></td>
27+
</tr>
28+
</table>
29+
<input class="btn btn-danger" type="submit" value="Remove Student"/>
30+
</form>
31+
</div>
32+
33+
3034
</div>
3135
</body>
3236
</html>

StudentDemo/src/main/resources/templates/Student/viewCourseForStudent.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ <h1 th:text="${title}"></h1>
88
<nav th:replace="fragments :: navigation"></nav>
99
</div>
1010

11-
<div class="addCourseForStudentFull">
11+
<div class="viewCourseForStudentFull">
12+
<div class="CreditBox">
13+
<h4 th:text="${totalCredit}"></h4>
14+
</div>
1215
<div class="courseTableForSingleStudent">
1316
<table class="table table-striped">
1417
<tr>

0 commit comments

Comments
 (0)