Browse Source

Update C# code samples for correct namespace usages on Blazor

pull/23444/head
Enis Necipoglu 1 year ago
parent
commit
e4942b2ba7
No known key found for this signature in database GPG Key ID: 1EC55E13241E1680
  1. 116
      docs/en/tutorials/todo/layered/index.md

116
docs/en/tutorials/todo/layered/index.md

@ -171,13 +171,13 @@ This application has a single [entity](../../../framework/architecture/domain-dr
using System; using System;
using Volo.Abp.Domain.Entities; 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. `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 System.Threading.Tasks;
using Volo.Abp.Application.Services; 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<List<TodoItemDto>> GetListAsync(); Task DeleteAsync(Guid id);
Task<TodoItemDto> CreateAsync(string text);
Task DeleteAsync(Guid id);
}
} }
```` ````
### Data Transfer Object ### Data Transfer Object
@ -299,14 +299,14 @@ namespace TodoApp
````csharp ````csharp
using System; 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`. 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.Application.Services;
using Volo.Abp.Domain.Repositories; 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) public TodoAppService(IRepository<TodoItem, Guid> todoItemRepository)
{ {
_todoItemRepository = todoItemRepository; _todoItemRepository = todoItemRepository;
}
// TODO: Implement the methods here...
} }
// 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.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace TodoApp.Web.Pages namespace TodoApp.Web.Pages;
{
public class IndexModel : TodoAppPageModel public class IndexModel : TodoAppPageModel
{ {
public List<TodoItemDto> TodoItems { get; set; } public List<TodoItemDto> TodoItems { get; set; }
@ -430,7 +429,7 @@ namespace TodoApp.Web.Pages
TodoItems = await _todoAppService.GetListAsync(); 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. 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,41 @@ using Microsoft.AspNetCore.Components;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; 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}}
namespace TodoApp.Blazor.Pages;
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 List<TodoItemDto> TodoItems { get; set; } = new List<TodoItemDto>();
private string NewTodoText { get; set; } = string.Empty; private string NewTodoText { get; set; } = string.Empty;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
TodoItems = await TodoAppService.GetListAsync(); TodoItems = await TodoAppService.GetListAsync();
} }
private async Task Create() private async Task Create()
{ {
var result = await TodoAppService.CreateAsync(NewTodoText); var result = await TodoAppService.CreateAsync(NewTodoText);
TodoItems.Add(result); TodoItems.Add(result);
NewTodoText = null; NewTodoText = null;
} }
private async Task Delete(TodoItemDto todoItem) private async Task Delete(TodoItemDto todoItem)
{ {
await TodoAppService.DeleteAsync(todoItem.Id); await TodoAppService.DeleteAsync(todoItem.Id);
await Notify.Info("Deleted the todo item."); await Notify.Info("Deleted the todo item.");
TodoItems.Remove(todoItem); TodoItems.Remove(todoItem);
}
} }
} }
``` ```

Loading…
Cancel
Save