-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac3b3c6
commit 7bbb350
Showing
16 changed files
with
574 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
@page "/exam" | ||
@rendermode InteractiveServer | ||
@using CloudProject.Services | ||
|
||
<h3>Exam Management</h3> | ||
|
||
|
||
@if (_isLoading) | ||
{ | ||
<div>Loading...</div> | ||
} | ||
else | ||
{ | ||
|
||
<div> | ||
<h4>Add/Edit Exam</h4> | ||
<input @bind="_currentExam.CourseName" placeholder="Name"/> | ||
<input type="date" @bind="_currentExam.ExamDate"/> | ||
<button @onclick="@SaveExam">Save</button> | ||
</div> | ||
|
||
<div> | ||
<h4>Exams</h4> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Date</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var exam in _exams) | ||
{ | ||
<tr> | ||
<td>@exam.CourseName</td> | ||
<td>@exam.ExamDate.ToString()</td> | ||
<td> | ||
<button @onclick="() => EditExam(exam)">Edit</button> | ||
<button @onclick="() => DeleteExam(exam.ExamId)">Delete</button> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
} | ||
|
||
@code { | ||
[Inject] | ||
private IExamService ExamService { get; set; } = null!; | ||
private bool _isLoading = true; | ||
private IEnumerable<Models.Exam> _exams = new List<Models.Exam>(); | ||
private Models.Exam _currentExam = new Models.Exam(); | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
_exams = await ExamService.GetAllExamsAsync(); | ||
_isLoading = false; | ||
} | ||
|
||
private async Task SaveExam() | ||
{ | ||
if (_currentExam.ExamId == 0) | ||
await ExamService.CreateExamAsync(_currentExam); | ||
else | ||
await ExamService.UpdateExamAsync(_currentExam); | ||
|
||
_currentExam = new Models.Exam(); | ||
_exams = await ExamService.GetAllExamsAsync(); | ||
} | ||
|
||
private void EditExam(Models.Exam exam) | ||
{ | ||
_currentExam = new Models.Exam | ||
{ | ||
ExamId = exam.ExamId, | ||
CourseName = exam.CourseName, | ||
ExamDate = exam.ExamDate | ||
}; | ||
} | ||
|
||
private async Task DeleteExam(int id) | ||
{ | ||
await ExamService.DeleteExamAsync(id); | ||
_exams = await ExamService.GetAllExamsAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using CloudProject.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace CloudProject.Data; | ||
|
||
public class ApplicationDbContext : DbContext | ||
{ | ||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) | ||
: base(options) | ||
{ | ||
} | ||
|
||
public DbSet<Exam> Exams { get; set; } | ||
} |
66 changes: 66 additions & 0 deletions
66
CloudProject/Migrations/20240915130130_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Metadata; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace CloudProject.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class InitialCreate : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.AlterDatabase() | ||
.Annotation("MySql:CharSet", "utf8mb4"); | ||
|
||
migrationBuilder.CreateTable( | ||
name: "Exams", | ||
columns: table => new | ||
{ | ||
ExamId = table.Column<int>(type: "int", nullable: false) | ||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), | ||
CourseName = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false) | ||
.Annotation("MySql:CharSet", "utf8mb4"), | ||
ExamDate = table.Column<DateTime>(type: "datetime(6)", nullable: false), | ||
Location = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false) | ||
.Annotation("MySql:CharSet", "utf8mb4"), | ||
DurationMinutes = table.Column<int>(type: "int", nullable: false), | ||
Instructor = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false) | ||
.Annotation("MySql:CharSet", "utf8mb4") | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Exams", x => x.ExamId); | ||
}) | ||
.Annotation("MySql:CharSet", "utf8mb4"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Exams"); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
CloudProject/Migrations/20240915134947_ToltiParametriRequired.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.