using Microsoft.AspNetCore.Mvc; using Checkbook.API.Base; namespaceCheckbook.API.Reconcile { // test with http://localhost:xxx/api/v1/reconciles [Route("api/v1/[controller]")] [ApiController] publicclassReconcilesController : BaseController { privatereadonly IReconcileService _reconcileService;
var result = await _reconcileService.UpdateReconcile(reconcileVm); return Ok(result); }
[HttpDelete("{id}")] publicasync Task<IActionResult> Delete(long id) { var result = await _reconcileService.DeleteReconcile(id); return Ok(result); } } }
Here are a few interesting commands
1 2 3 4 5
// test with http://localhost:xxx/api/v1/reconciles [Route("api/v1/[controller]")] [ApiController] publicclassReconcilesController : BaseController {
The Route and ApiController statements are called Annotation’s. You add Annotations to classes, or methods as a way to add functionality to your code without adding the code itself.
Route defines the URL path to access methods in the class.
ApiController is used to tell the compiler that the class is an API controller. When you use the ApiController attribute, you are required to add the word Controller to the class name as a suffix.
Public ReconcilesController(…) is executed each time the class is instantiated. When the class is instantiated, a property called Dependency Injection will inject (IReconcileService reconcileService) a class which was created that implements the IReconcileService interface.
We store a reference of the class being passed in into the private variable _reconcileService.
This method returns records from the database. It does this by calling the GetAllReconcilesAsync() method in the class that implements the IReconcileService interface. it returns a List object loaded with ReconcileViewModel objects. This is wrapped in a IResult object..