Skip to content

Commit bec16ba

Browse files
V16
V16
1 parent 283dbdf commit bec16ba

File tree

9 files changed

+204
-64
lines changed

9 files changed

+204
-64
lines changed

ASP_Core_EF/ASP_Core_EF.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<TargetFramework>netcoreapp2.0</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<Content Include="Views\Enrollment\Details.cshtml.bak" />
9+
</ItemGroup>
10+
711
<ItemGroup>
812
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
913
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />

ASP_Core_EF/Controllers/CourseController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public IActionResult DeleteConfirm(int? Id)
5959

6060
}
6161

62+
[HttpGet]
63+
public IActionResult Details(int? Id)
64+
{
65+
66+
return View(_Course.GetCourse(Id));
67+
}
6268

6369

6470
}

ASP_Core_EF/Controllers/EnrollmentController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ public IActionResult DeleteConfirm(int? Id)
5656
_Enrollment.Remove(Id);
5757
return RedirectToAction("Index");
5858
}
59+
60+
5961
}
6062
}

ASP_Core_EF/Models/Course.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ public class Course
1717
[Required(ErrorMessage = "Credits is Required.")]
1818
public string Credits { get; set; }
1919

20+
public ICollection<Enrollment> Enrollments { get; set; }
21+
2022
}
2123
}

ASP_Core_EF/Models/Enrollment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.ComponentModel.DataAnnotations;
5+
using System.ComponentModel.DataAnnotations.Schema;
56
using System.Linq;
67
using System.Threading.Tasks;
78

@@ -35,5 +36,7 @@ public class Enrollment
3536

3637
public Student Students { get; set; }
3738
public Course Courses { get; set; }
39+
40+
3841
}
3942
}

ASP_Core_EF/Repository/CourseRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Threading.Tasks;
66
using ASP_Core_EF.Models;
7+
using Microsoft.EntityFrameworkCore;
78

89
namespace ASP_Core_EF.Repository
910
{
@@ -24,7 +25,7 @@ public void Add(Course _Course)
2425

2526
public Course GetCourse(int? Id)
2627
{
27-
return db.Courses.Find(Id);
28+
return db.Courses.Include(e => e.Enrollments).ThenInclude(s =>s.Students).SingleOrDefault(a => a.CourseId == Id);
2829
}
2930

3031
public void Remove(int? Id)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
@model ASP_Core_EF.Models.Course
2+
3+
@{
4+
ViewData["Title"] = "Details";
5+
}
6+
7+
<h2>Details</h2>
8+
9+
<div>
10+
<h4>Course</h4>
11+
<hr />
12+
<dl class="dl-horizontal">
13+
<dt>
14+
@Html.DisplayNameFor(model => model.CourseName)
15+
</dt>
16+
<dd>
17+
@Html.DisplayFor(model => model.CourseName)
18+
</dd>
19+
<dt>
20+
@Html.DisplayNameFor(model => model.Credits)
21+
</dt>
22+
<dd>
23+
@Html.DisplayFor(model => model.Credits)
24+
</dd>
25+
<dt>
26+
@Html.DisplayNameFor(model => model.Enrollments)
27+
</dt>
28+
<dd>
29+
<table class="table">
30+
<thead>
31+
<tr>
32+
<th>
33+
Student
34+
</th>
35+
36+
<th>
37+
Start Date
38+
</th>
39+
<th>
40+
End Date
41+
</th>
42+
<th>
43+
Grade
44+
</th>
45+
46+
</tr>
47+
</thead>
48+
<tbody>
49+
@foreach (var item in Model.Enrollments)
50+
{
51+
<tr>
52+
<td>
53+
@Html.DisplayFor(modelItem => item.Students.FirstName)
54+
</td>
55+
56+
<td>
57+
@Html.DisplayFor(modelItem => item.StartDate)
58+
</td>
59+
<td>
60+
@Html.DisplayFor(modelItem => item.EndDate)
61+
</td>
62+
<td>
63+
@Html.DisplayFor(modelItem => item.Grade)
64+
</td>
65+
66+
</tr>
67+
}
68+
</tbody>
69+
</table>
70+
</dd>
71+
</dl>
72+
</div>
73+
<div>
74+
<a asp-action="Edit" asp-route-id="@Model.CourseId">Edit</a> |
75+
<a asp-action="Index">Back to List</a>
76+
</div>

ASP_Core_EF/Views/Enrollment/Create.cshtml

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
@model ASP_Core_EF.Models.Enrollment
2+
3+
@{
4+
ViewData["Title"] = "Details";
5+
}
6+
7+
<h2>Details</h2>
8+
9+
<div>
10+
<h4>Enrollment</h4>
11+
<hr />
12+
<dl class="dl-horizontal">
13+
<dt>
14+
@Html.DisplayNameFor(model => model.StartDate)
15+
</dt>
16+
<dd>
17+
@Html.DisplayFor(model => model.StartDate)
18+
</dd>
19+
<dt>
20+
@Html.DisplayNameFor(model => model.EndDate)
21+
</dt>
22+
<dd>
23+
@Html.DisplayFor(model => model.EndDate)
24+
</dd>
25+
<dt>
26+
@Html.DisplayNameFor(model => model.Grade)
27+
</dt>
28+
<dd>
29+
@Html.DisplayFor(model => model.Grade)
30+
</dd>
31+
<dt>
32+
@Html.DisplayNameFor(model => model.Courses)
33+
</dt>
34+
<dd>
35+
@Html.DisplayFor(model => model.Courses.CourseName)
36+
</dd>
37+
<dt>
38+
@Html.DisplayNameFor(model => model.Students)
39+
</dt>
40+
<dd>
41+
@Html.DisplayFor(model => model.Students.FirstName)
42+
</dd>
43+
<dt>
44+
@Html.DisplayNameFor(model => model.Students)
45+
</dt>
46+
<dd>
47+
<table class="table">
48+
<thead>
49+
<tr>
50+
<th>
51+
FirstName
52+
</th>
53+
<th>
54+
LastName
55+
</th>
56+
<th>
57+
DOB
58+
</th>
59+
<th>
60+
GenderId
61+
</th>
62+
<th>
63+
RegistrationDate
64+
</th>
65+
<th>
66+
Status
67+
</th>
68+
<th></th>
69+
</tr>
70+
</thead>
71+
<tbody>
72+
@foreach (var item in Model.StudentList)
73+
{
74+
<tr>
75+
<td>
76+
@Html.DisplayFor(modelItem => item.FirstName)
77+
</td>
78+
<td>
79+
@Html.DisplayFor(modelItem => item.LastName)
80+
</td>
81+
<td>
82+
@Html.DisplayFor(modelItem => item.DOB)
83+
</td>
84+
<td>
85+
@Html.DisplayFor(modelItem => item.Genders.GenderName)
86+
</td>
87+
<td>
88+
@Html.DisplayFor(modelItem => item.RegistrationDate)
89+
</td>
90+
<td>
91+
@Html.DisplayFor(modelItem => item.Status)
92+
</td>
93+
<td>
94+
<a asp-action="Edit" asp-route-id="@item.StudentId">Edit</a> |
95+
<a asp-action="Details" asp-route-id="@item.StudentId">Details</a> |
96+
<a asp-action="Delete" asp-route-id="@item.StudentId">Delete</a>
97+
</td>
98+
</tr>
99+
}
100+
</tbody>
101+
</table>
102+
103+
</dd>
104+
</dl>
105+
</div>
106+
<div>
107+
<a asp-action="Edit" asp-route-id="@Model.EnrollmentId">Edit</a> |
108+
<a asp-action="Index">Back to List</a>
109+
</div>

0 commit comments

Comments
 (0)