-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTodoList.razor
65 lines (58 loc) · 1.64 KB
/
TodoList.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@page "/api/todo"
@using TodoApp.Models
@inject TodoApp.Service.ITodoService TodoService
@inject NavigationManager navigationManager
<PageTitle>TodoApp</PageTitle>
<h3>TODO List</h3>
@if (todoItems == null)
{
<p>Loading...</p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Title</th>
<th>Completed</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var item in todoItems)
{
<tr>
<td>@item.Id</td>
<td>@item.Title</td>
<td>@(item.IsCompleted ? "Yes" : "No")</td>
<td>
<button class="btn btn-primary" @onclick="() => EditTodoItem(item)">Edit</button>
<button class="btn btn-danger" @onclick="() => DeleteTodoItem(item.Id)">Delete</button>
</td>
</tr>
}
</tbody>
</table>
}
<button class="button" @onclick="AddTodoItem">Add New Item</button>
@code {
private List<Models.TodoItem> todoItems = null!;
protected override async Task OnInitializedAsync()
{
todoItems = await TodoService.GetTodoItems();
}
private void AddTodoItem()
{
navigationManager.NavigateTo("/api/todo/add");
}
private void EditTodoItem(Models.TodoItem item)
{
navigationManager.NavigateTo($"/api/todo/{item.Id}");
}
private async Task DeleteTodoItem(int id)
{
await TodoService.DeleteTodoItem(id);
todoItems = await TodoService.GetTodoItems();
}
}