Skip to content

Commit cd25d50

Browse files
committed
Session 5 - Database POSTs
1 parent c7e74a2 commit cd25d50

File tree

9 files changed

+80
-92
lines changed

9 files changed

+80
-92
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Controllers/RecordController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ public IActionResult Assessments()
3636
return View();
3737
}
3838

39+
public IActionResult AddClass()
40+
{
41+
return View();
42+
}
43+
[HttpPost]
44+
public IActionResult AddClass(Classes obj)
45+
{
46+
_db.Classes.Add(obj);
47+
_db.SaveChanges();
48+
return RedirectToAction("TimeTable");
49+
}
50+
3951
[HttpPost]
4052
public ActionResult TestForm(Models.TestResult sm)
4153
{

Migrations/20230918124802_InitialCreate.Designer.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

Migrations/20230918125811_AddingData.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

Migrations/20230918125811_AddingData.Designer.cs renamed to Migrations/20230925104438_InitialCreate.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Migrations/20230918124802_InitialCreate.cs renamed to Migrations/20230925104438_InitialCreate.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#nullable disable
55

6+
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
7+
68
namespace CMS.Migrations
79
{
810
/// <inheritdoc />
@@ -29,6 +31,15 @@ protected override void Up(MigrationBuilder migrationBuilder)
2931
table.PrimaryKey("PK_Classes", x => x.ID);
3032
})
3133
.Annotation("MySql:CharSet", "utf8mb4");
34+
35+
migrationBuilder.InsertData(
36+
table: "Classes",
37+
columns: new[] { "ID", "className", "period" },
38+
values: new object[,]
39+
{
40+
{ 1, "Physcis", 1 },
41+
{ 2, "Literature", 2 }
42+
});
3243
}
3344

3445
/// <inheritdoc />

Views/Record/AddClass.cshtml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@model Classes
2+
3+
<div class="min-h-screen text-center">
4+
<p class="dark:text-white font-bold tect-2xl md:text-5xl justify-center items-center pb-10">Add Classes</p>
5+
6+
<form method="post">
7+
<table class="min-w-full bg-transparent shadow-md rounded-lg text-center">
8+
<thead>
9+
<tr>
10+
<th class="py-2 px-4 bg-transparent text-white">Period</th>
11+
<th class="py-2 px-4 bg-transparent text-white">Name</th>
12+
</tr>
13+
</thead>
14+
<tbody>
15+
<tr class="border-t">
16+
<td class="py-2 px-4">
17+
<input asp-for="period" type="text" class="form-control w-full bg-transparent rounded px-2 py-1 text-white placeholder-white::placeholder text-center outline-none" placeholder="Enter period" />
18+
</td>
19+
<td class="py-2 px-4">
20+
<input asp-for="className" type="text" class="form-control w-full bg-transparent rounded px-2 py-1 text-white placeholder-white::placeholder text-center outline-none" placeholder="Enter name" />
21+
</td>
22+
</tr>
23+
</tbody>
24+
</table>
25+
26+
<div class="flex items-center justify-center mt-2 f">
27+
<div class="text-center mt-6 inline-flex">
28+
<button type="submit" class="text-white border border-white bg-transparent font-semibold hover:bg-gray-500 hover:text-gray-800 py-2 px-4 rounded items-center justify-center transition duration-100 ease-in-out">
29+
<i class="bi bi-plus-circle mr-2"> </i> Add to Timetable
30+
</button>
31+
</div>
32+
33+
<div class="w-10"> </div>
34+
35+
<div class="text-center mt-6 inline-flex">
36+
<a asp-controller="Record" asp-action="TimeTable" class="text-gray-400 border border-gray-400 bg-transparent font-semibold hover:bg-gray-500 hover:text-gray-800 py-2 px-4 rounded items-center justify-center transition duration-100 ease-in-out">
37+
<i class="bi bi-plus-circle mr-2"> </i> Back to Timetable
38+
</a>
39+
</div>
40+
</div>
41+
</form>
42+
</div>

Views/Record/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="p-8 bg-grey-100 min-h-screen">
2-
<p class="dark:text-white font-bold text-2xl md:text-6xl text-center pb-10"></p>
2+
<p class="dark:text-white font-bold text-2xl md:text-5xl text-center pb-10"></p>
33
</div>

Views/Record/TimeTable.cshtml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@model List<Classes>
22

3-
<div class="min-h-screen">
4-
<p class="dark:text-white font-bold tect-2xl md:text-6xl text-center pb-10">Time Table for Today</p>
3+
<div class="min-h-screen text-center">
4+
<p class="dark:text-white font-bold tect-2xl md:text-5xl justify-center items-center pb-10">Time Table for Today</p>
55

66
<table class="min-w-full bg-transparent shadow-md rounded-lg text-center">
77
<thead>
@@ -13,11 +13,17 @@
1313
<tbody>
1414
@foreach (var obj in Model)
1515
{
16-
<tr class="border-t">
17-
<td class="py-2 px-4">@obj.period</td>
18-
<td class="py-2 px-4">@obj.className</td>
19-
</tr>
16+
<tr class="border-t">
17+
<td class="py-2 px-4">@obj.period</td>
18+
<td class="py-2 px-4">@obj.className</td>
19+
</tr>
2020
}
2121
</tbody>
2222
</table>
23+
24+
<div class="text-center mt-6">
25+
<a asp-controller="Record" asp-action="AddClass" class="text-white border border-white bg-transparent font-semibold hover:bg-gray-500 hover:text-gray-800 py-2 px-4 rounded items-center justify-center transition duration-100 ease-in-out">
26+
<i class="bi bi-plus-circle mr-2"> </i> Add New Class
27+
</a>
28+
</div>
2329
</div>

0 commit comments

Comments
 (0)