API Reference
Files Referenced in this Document
IMyEntityNameAppService.csMyEntityNameAppService.csMyEntityNameDto.csMyEntityNameCreateDto.csMyEntityNameUpdateDto.csMyEntityNameGetListInput.csMyEntityNameExcelDto.cs
Table of Contents
- Introduction
- Service Interface Definition
- DTO Definitions
- Standard CRUD Operations
- Extended Operations
- Data Import and Export
- Conclusion
Introduction
This document provides a comprehensive reference for the API services in the CMS plugin, specifically focusing on the IMyEntityNameAppService and its implementation MyEntityNameAppService. These services expose standard CRUD (Create, Read, Update, Delete) operations as well as extended functionalities like batch deletion, sorting, and data import/export for MyEntityName entities. The API follows RESTful principles and is integrated with the ABP framework's application service pattern.
Service Interface Definition
The IMyEntityNameAppService interface defines the contract for managing MyEntityName resources. It inherits from ICrudAppService to provide standard CRUD capabilities and extends it with custom methods.
public interface IMyEntityNameAppService :
ICrudAppService<
MyEntityNameDto,
Guid,
MyEntityNameGetListInput,
MyEntityNameCreateDto,
MyEntityNameUpdateDto>,
IDataImportAppService<MyEntityNameExcelDto>
{
Task DeleteManyAsync(List<Guid> ids);
Task SortAsync(List<Guid> ids);
Task<List<MyEntityNameDto>> GetAllListAsync();
}
Section sources
IMyEntityNameAppService.cs
DTO Definitions
Data Transfer Objects (DTOs) are used to transfer data between the client and the server.
- MyEntityNameDto: Represents the full details of a
MyEntityNameentity, used in read operations. - MyEntityNameCreateDto: Contains necessary fields for creating a new entity (e.g.,
Name,Code). - MyEntityNameUpdateDto: Contains fields allowed to be updated.
- MyEntityNameGetListInput: Defines parameters for filtering, sorting, and paging when retrieving lists.
- MyEntityNameExcelDto: Specialized DTO for Excel import/export operations.
Section sources
MyEntityNameDto.csMyEntityNameCreateDto.cs
Standard CRUD Operations
The service implements standard CRUD operations provided by CrudAppService:
- GetAsync(Guid id): Retrieves a single entity by ID.
- GetListAsync(MyEntityNameGetListInput input): Retrieves a paged list of entities based on filter criteria.
- CreateAsync(MyEntityNameCreateDto input): Creates a new entity.
- UpdateAsync(Guid id, MyEntityNameUpdateDto input): Updates an existing entity.
- DeleteAsync(Guid id): Deletes an entity by ID.
These methods automatically handle mapping between entities and DTOs, validation, and database interactions.
Section sources
MyEntityNameAppService.cs
Extended Operations
Batch Deletion
The DeleteManyAsync method allows deleting multiple entities in a single request, improving performance for bulk operations.
public async Task DeleteManyAsync(List<Guid> ids)
{
await Repository.DeleteManyAsync(ids);
}
Sorting
The SortAsync method provides a mechanism to reorder entities. It typically accepts a list of IDs in the desired order and updates their sorting index in the database.
Get All List
The GetAllListAsync method retrieves all entities without paging, useful for dropdowns or small datasets.
Section sources
MyEntityNameAppService.cs
Data Import and Export
The service implements IDataImportAppService<MyEntityNameExcelDto> to support Excel data operations.
- GetImportTemplateAsync: Generates an Excel template for users to fill in data.
- ImportAsync: Parses an uploaded Excel file and creates entities in bulk.
- ExportAsync: Exports current data to an Excel file.
This functionality leverages the ExcelManager to handle file parsing and generation.
Section sources
MyEntityNameAppService.cs
Conclusion
The MyEntityNameAppService provides a robust and complete set of APIs for managing MyEntityName resources. By combining standard CRUD operations with batch processing, sorting, and Excel integration, it meets the requirements of enterprise-grade applications. The clear separation of DTOs and interfaces ensures maintainability and extensibility.