Skip to content

Commit 9e06b96

Browse files
part 13
part 13
1 parent 1862a96 commit 9e06b96

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

ASP_Core_EF/Controllers/EnrollmentController.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ namespace ASP_Core_EF.Controllers
1111
public class EnrollmentController : Controller
1212
{
1313
private readonly IEnrollment _Enrollment;
14+
private readonly ICourse _Cousre;
15+
private readonly IStudent _Student;
1416

15-
public EnrollmentController(IEnrollment _IEnrollment)
17+
public EnrollmentController(IEnrollment _IEnrollment,ICourse _ICousre, IStudent _IStudent)
1618
{
1719
_Enrollment = _IEnrollment;
20+
_Cousre = _ICousre;
21+
_Student = _IStudent;
1822
}
1923
public IActionResult Index()
2024
{
@@ -24,6 +28,8 @@ public IActionResult Index()
2428
[HttpGet]
2529
public IActionResult Create()
2630
{
31+
ViewBag.Course = _Cousre.GetCourses;
32+
ViewBag.Student = _Student.GetStudents;
2733
return View();
2834
}
2935
[HttpPost]

ASP_Core_EF/Models/Enrollment.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ public class Enrollment
2323
public int CourseId { get; set; }
2424
[Required(ErrorMessage = "Start Date is Required")]
2525
[DisplayName("Start Date")]
26+
[DataType(DataType.Date)]
2627
public DateTime StartDate { get; set; }
2728
[Required(ErrorMessage = "End Date is Required")]
2829
[DisplayName("End Date")]
30+
[DataType(DataType.Date)]
2931
public DateTime EndDate { get; set; }
3032
[DisplayFormat(NullDisplayText = "No grade")]
3133
public Grade? Grade { get; set; }

ASP_Core_EF/Models/Student.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Student
1818
public int StudentId { get; set; }
1919
[DisplayName("First Name")]
2020
[Required(ErrorMessage = "First Name is Required.")]
21-
public string FisrtName { get; set; }
21+
public string FirstName { get; set; }
2222
[DisplayName("Last Name")]
2323
[Required(ErrorMessage = "Last Name is Required.")]
2424
public string LastName { get; set; }

ASP_Core_EF/Views/Enrollment/Create.cshtml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
1515
<div class="form-group">
1616
<label asp-for="StudentId" class="control-label"></label>
17-
<input asp-for="StudentId" class="form-control" />
17+
<select asp-for="StudentId"
18+
class="form-control"
19+
asp-items="@(new SelectList(ViewBag.Student,"StudentId","FirstName"))"></select>
1820
<span asp-validation-for="StudentId" class="text-danger"></span>
1921
</div>
2022
<div class="form-group">
2123
<label asp-for="CourseId" class="control-label"></label>
22-
<input asp-for="CourseId" class="form-control" />
24+
<select asp-for="CourseId"
25+
class="form-control"
26+
asp-items="@(new SelectList(ViewBag.Course,"CourseId","CourseName"))"></select>
2327
<span asp-validation-for="CourseId" class="text-danger"></span>
2428
</div>
2529
<div class="form-group">
@@ -34,7 +38,13 @@
3438
</div>
3539
<div class="form-group">
3640
<label asp-for="Grade" class="control-label"></label>
37-
<input asp-for="Grade" class="form-control" />
41+
<select asp-for="Grade" class="form-control">
42+
<option value="">No Grade</option>
43+
<option value="A">A</option>
44+
<option value="B">B</option>
45+
<option value="C">C</option>
46+
<option value="F">F</option>
47+
</select>
3848
<span asp-validation-for="Grade" class="text-danger"></span>
3949
</div>
4050
<div class="form-group">

ASP_Core_EF/Views/Student/Create.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<form asp-action="Create">
1414
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
1515
<div class="form-group">
16-
<label asp-for="FisrtName" class="control-label"></label>
17-
<input asp-for="FisrtName" class="form-control" />
18-
<span asp-validation-for="FisrtName" class="text-danger"></span>
16+
<label asp-for="FirstName" class="control-label"></label>
17+
<input asp-for="FirstName" class="form-control" />
18+
<span asp-validation-for="FirstName" class="text-danger"></span>
1919
</div>
2020
<div class="form-group">
2121
<label asp-for="LastName" class="control-label"></label>

ASP_Core_EF/Views/Student/Delete.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<hr />
1313
<dl class="dl-horizontal">
1414
<dt>
15-
@Html.DisplayNameFor(model => model.FisrtName)
15+
@Html.DisplayNameFor(model => model.FirstName)
1616
</dt>
1717
<dd>
18-
@Html.DisplayFor(model => model.FisrtName)
18+
@Html.DisplayFor(model => model.FirstName)
1919
</dd>
2020
<dt>
2121
@Html.DisplayNameFor(model => model.LastName)

ASP_Core_EF/Views/Student/Index.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<thead>
1414
<tr>
1515
<th>
16-
@Html.DisplayNameFor(model => model.FisrtName)
16+
@Html.DisplayNameFor(model => model.FirstName)
1717
</th>
1818
<th>
1919
@Html.DisplayNameFor(model => model.LastName)
@@ -37,7 +37,7 @@
3737
@foreach (var item in Model) {
3838
<tr>
3939
<td>
40-
@Html.DisplayFor(modelItem => item.FisrtName)
40+
@Html.DisplayFor(modelItem => item.FirstName)
4141
</td>
4242
<td>
4343
@Html.DisplayFor(modelItem => item.LastName)

0 commit comments

Comments
 (0)