@ -171,13 +171,13 @@ This application has a single [entity](../../../framework/architecture/domain-dr
using System;
using Volo.Abp.Domain.Entities;
namespace TodoApp
namespace TodoApp;
public class TodoItem : BasicAggregateRoot< Guid >
{
public class TodoItem : BasicAggregateRoot< Guid >
{
public string Text { get; set; } = string.Empty;
}
public string Text { get; set; } = string.Empty;
}
````
`BasicAggregateRoot` is the simplest base class to create root entities, and `Guid` is the primary key (`Id`) of the entity here.
@ -281,15 +281,15 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace TodoApp
namespace TodoApp;
public interface ITodoAppService : IApplicationService
{
public interface ITodoAppService : IApplicationService
{
Task< List < TodoItemDto > > GetListAsync();
Task< TodoItemDto > CreateAsync(string text);
Task DeleteAsync(Guid id);
}
Task< List < TodoItemDto > > GetListAsync();
Task< TodoItemDto > CreateAsync(string text);
Task DeleteAsync(Guid id);
}
````
### Data Transfer Object
@ -299,14 +299,14 @@ namespace TodoApp
````csharp
using System;
namespace TodoApp
namespace TodoApp;
public class TodoItemDto
{
public class TodoItemDto
{
public Guid Id { get; set; }
public string Text { get; set; } = string.Empty;
}
public Guid Id { get; set; }
public string Text { get; set; } = string.Empty;
}
````
This is a very simple DTO class that matches our `TodoItem` entity. We are ready to implement the `ITodoAppService` .
@ -323,19 +323,18 @@ using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace TodoApp
namespace TodoApp;
public class TodoAppService : ApplicationService, ITodoAppService
{
public class TodoAppService : ApplicationService, ITodoAppService
{
private readonly IRepository< TodoItem , Guid > _todoItemRepository;
private readonly IRepository< TodoItem , Guid > _todoItemRepository;
public TodoAppService(IRepository< TodoItem , Guid > todoItemRepository)
{
_todoItemRepository = todoItemRepository;
}
// TODO: Implement the methods here...
public TodoAppService(IRepository< TodoItem , Guid > todoItemRepository)
{
_todoItemRepository = todoItemRepository;
}
// TODO: Implement the methods here...
}
````
@ -412,8 +411,8 @@ Open the `Index.cshtml.cs` file in the `Pages` folder of the *TodoApp.Web* proje
using System.Collections.Generic;
using System.Threading.Tasks;
namespace TodoApp.Web.Pages
{
namespace TodoApp.Web.Pages;
public class IndexModel : TodoAppPageModel
{
public List< TodoItemDto > TodoItems { get; set; }
@ -430,7 +429,7 @@ namespace TodoApp.Web.Pages
TodoItems = await _todoAppService.GetListAsync();
}
}
}
````
This class uses the `ITodoAppService` to get the list of todo items and assign the `TodoItems` property. We will use it to render the todo items on the razor page.
@ -578,34 +577,39 @@ using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace TodoApp.Blazor.Pages
{{if UI=="Blazor" || UI=="BlazorWebApp"}}
namespace TodoApp.Blazor.Client.Pages;
{{else if UI=="BlazorServer"}}
namespace TodoApp.Blazor.Pages;
{{else if UI=="MAUIBlazor"}}
namespace TodoApp.MauiBlazor.Pages;
{{end}}
public partial class Index
{
public partial class Index
{
[Inject]
private ITodoAppService TodoAppService { get; set; }
[Inject]
private ITodoAppService TodoAppService { get; set; }
private List< TodoItemDto > TodoItems { get; set; } = new List< TodoItemDto > ();
private string NewTodoText { get; set; } = string.Empty;
private List< TodoItemDto > TodoItems { get; set; } = new List< TodoItemDto > ();
private string NewTodoText { get; set; } = string.Empty;
protected override async Task OnInitializedAsync()
{
TodoItems = await TodoAppService.GetListAsync();
}
private async Task Create()
{
var result = await TodoAppService.CreateAsync(NewTodoText);
TodoItems.Add(result);
NewTodoText = null;
}
protected override async Task OnInitializedAsync()
{
TodoItems = await TodoAppService.GetListAsync();
}
private async Task Create()
{
var result = await TodoAppService.CreateAsync(NewTodoText);
TodoItems.Add(result);
NewTodoText = null;
}
private async Task Delete(TodoItemDto todoItem)
{
await TodoAppService.DeleteAsync(todoItem.Id);
await Notify.Info("Deleted the todo item.");
TodoItems.Remove(todoItem);
}
private async Task Delete(TodoItemDto todoItem)
{
await TodoAppService.DeleteAsync(todoItem.Id);
await Notify.Info("Deleted the todo item.");
TodoItems.Remove(todoItem);
}
}
```