Skip to content

Base API Controller Classes

Dennis C. Mitchell edited this page Sep 12, 2019 · 3 revisions

EDennis.AspNetCore.Base provides a WriteableController base class and a ReadonlyController base class. The WriteableController class is designed to be used with a WriteableRepo (non-temporal version) where the underlying entity has a simple integer ID. The ReadonlyController class is designed to be used with a ReadonlyRepo (non-temporal version), which utilizes a relational database. This page summarizes the endpoints available for each base controller.

WriteableController

WriteableController provides base CRUD endpoints, as well as Swagger-friendly endpoints for querying via OData expressions, Dynamic Linq expressions, and DevExtreme.AspNet.Data.DataSourceLoader.

Type Parameters

WriteableController has two type parameters:

Type Parameter Constraints
TEntity TEntity is a class with a default constructor and implements both IHasSysUser and IHasIntegerId
TContext TContext extends Microsoft.EntityFrameworkCore.DbContext

Constructor

The WriteableController constructor accepts one argument:

  • WriteableRepo<TEntity, TContext> -- any valid WriteableRepo subclass
public WriteableRepo(WriteableRepo<TEntity, TContext> repo)

Endpoints

WriteableController exposes several endpoints.

Endpoint Action Parameters Description
/odata select, orderBy, filter, expand, skip (int?), top (int?) Query by OData
/devextreme select, sort, filter, skip (int?), take (int?), totalSummary, group, groupSummary Query by DevExtreme
/linq select, orderBy, where, skip (int?), take (int?) Query by OData
/linq/async (same as /linq) Asynchronous version of /linq
/get/{id} id (int) Query by integer primary key
/get/async/{id} (same as /get/{id}) Asynchronous version of /get/{id}
/post (none) Post a new object -- requires JSON body
/post/async (none) Asynchronous version of /post
/put/{id} id (int) Modify by integer primary key -- requires JSON body
/put/async/{id} (same as /put/{id}) Asynchronous version of /put/{id}
/delete/{id} id (int) Delete by integer primary key
/delete/async/{id} (same as /delete/{id}) Asynchronous version of /delete/{id}

ReadonlyController

ReadonlyController provides Swagger-friendly endpoints for querying via OData expressions, Dynamic Linq expressions, and DevExtreme.AspNet.Data.DataSourceLoader, as well as Postman-friendly endpoints for calling parameterized stored procedures.

Type Parameters

ReadonlyController has two type parameters:

Type Parameter Constraints
TEntity TEntity is a class with a default constructor
TContext TContext extends Microsoft.EntityFrameworkCore.DbContext

Constructor

The ReadonlyController constructor accepts one argument:

  • ReadonlyRepo<TEntity, TContext> -- any valid ReadonlyRepo subclass
public ReadonlyRepo(ReadonlyRepo<TEntity, TContext> repo)

Endpoints

ReadonlyController exposes several endpoints.

Endpoint Action Parameters Description
/odata select, orderBy, filter, expand, skip (int?), top (int?) Query by OData
/devextreme select, sort, filter, skip (int?), take (int?), totalSummary, group, groupSummary Query by DevExtreme
/linq select, orderBy, where, skip (int?), take (int?) Query by OData
/linq/async (same as /linq) Asynchronous version of /linq
/sp spName and any number of other parameters Query by stored procedure and return a List
/sp/async (same as /sp/async) Asynchronous version of /sp/async
/json spName and any number of other parameters Query by stored procedure and return a JSON string*
/json/async (same as /json/async) Asynchronous version of /json/async

*The stored procedure must be configured to return JSON as a single varchar column called "Json"

Clone this wiki locally