.NET Plugin Events
Create Entity Controller
Get Started
Lifecycle & Coding Details
Developing a Plugin
Guides & Tutorials
Blueprint Plugin Events
Node.js Plugin Events
- Create Server
- Create Server Docker Compose
- Create Server Docker Compose Dev
- Create Server Dot Env
- Create Server Auth
- Create Package Json
- Create Entity Service
- Create Entity Service Base
- Create Entity Controller
- Create Entity Controller Base
- Create Entity Resolver
- Create Entity Resolver Base
- Create Message Broker Service
- Create Message Broker Service Base
- Create Message Broker NestJS Module
- Create Message Broker Client Options Factory
- Create Message Broker Topics Enum
- Create Prisma Schema
.NET Plugin Events
- Create Server
- Create Server Appsettings
- Create Server Auth
- Create Program File
- Create Server Csproj
- Create Server Docker Compose
- Create Server Git Ignore
- Create Entity Model
- Create Resource Db Context File
- Create Message Broker
- Create Message Broker Client Options Factory
- Create Message Broker Service
- Create Entity Controller
- Create Entity Controller Base
- Create DTOs
- Create Entity Extensions
- Create Entity Interface
- Create Entity Service
- Create Entity Service Base
- Create Seed Development Data File
- Load Static Files
.NET Plugin Events
Create Entity Controller
Creates a controller for a specific entity in the .NET application.
afterCreateEntityController(
context: dotnetTypes.DsgContext,
eventParams: dotnet.CreateEntityControllerParams,
files: FileMap<Class>
): Promise<FileMap<Class>> {
const { entity, resourceName, apisDir } = eventParams;
const controllerPath = `${apisDir}/${entity.name}/${pascalCase(entity.name)}Controller.cs`;
const controllerFile = files.get(controllerPath);
if (controllerFile) {
// Add a custom action to the controller
controllerFile.code.addMethod(
CsharpSupport.method({
name: "ExportToCsv",
access: "public",
isAsync: true,
returnType: CsharpSupport.Types.task(CsharpSupport.Types.reference("IActionResult")),
decorators: [
CsharpSupport.decorator({
name: "HttpGet",
arguments: ["export-csv"],
}),
],
body: `
var allItems = await _service.List();
var csv = ConvertToCsv(allItems);
return File(Encoding.UTF8.GetBytes(csv), "text/csv", "${entity.name}Export.csv");
`,
})
);
// Add necessary imports
controllerFile.code.addImport("System.Text");
controllerFile.code.addImport("Microsoft.AspNetCore.Mvc");
}
return files;
}
Event Name
CreateEntityController
Event Parameters
The entity object for which the controller is being created.
The name of the resource (typically the entity name).
The directory where the API controllers are being generated.
An object containing the CRUD actions available for the entity.
afterCreateEntityController(
context: dotnetTypes.DsgContext,
eventParams: dotnet.CreateEntityControllerParams,
files: FileMap<Class>
): Promise<FileMap<Class>> {
const { entity, resourceName, apisDir } = eventParams;
const controllerPath = `${apisDir}/${entity.name}/${pascalCase(entity.name)}Controller.cs`;
const controllerFile = files.get(controllerPath);
if (controllerFile) {
// Add a custom action to the controller
controllerFile.code.addMethod(
CsharpSupport.method({
name: "ExportToCsv",
access: "public",
isAsync: true,
returnType: CsharpSupport.Types.task(CsharpSupport.Types.reference("IActionResult")),
decorators: [
CsharpSupport.decorator({
name: "HttpGet",
arguments: ["export-csv"],
}),
],
body: `
var allItems = await _service.List();
var csv = ConvertToCsv(allItems);
return File(Encoding.UTF8.GetBytes(csv), "text/csv", "${entity.name}Export.csv");
`,
})
);
// Add necessary imports
controllerFile.code.addImport("System.Text");
controllerFile.code.addImport("Microsoft.AspNetCore.Mvc");
}
return files;
}
Was this page helpful?
afterCreateEntityController(
context: dotnetTypes.DsgContext,
eventParams: dotnet.CreateEntityControllerParams,
files: FileMap<Class>
): Promise<FileMap<Class>> {
const { entity, resourceName, apisDir } = eventParams;
const controllerPath = `${apisDir}/${entity.name}/${pascalCase(entity.name)}Controller.cs`;
const controllerFile = files.get(controllerPath);
if (controllerFile) {
// Add a custom action to the controller
controllerFile.code.addMethod(
CsharpSupport.method({
name: "ExportToCsv",
access: "public",
isAsync: true,
returnType: CsharpSupport.Types.task(CsharpSupport.Types.reference("IActionResult")),
decorators: [
CsharpSupport.decorator({
name: "HttpGet",
arguments: ["export-csv"],
}),
],
body: `
var allItems = await _service.List();
var csv = ConvertToCsv(allItems);
return File(Encoding.UTF8.GetBytes(csv), "text/csv", "${entity.name}Export.csv");
`,
})
);
// Add necessary imports
controllerFile.code.addImport("System.Text");
controllerFile.code.addImport("Microsoft.AspNetCore.Mvc");
}
return files;
}