using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Mvc; using System.Threading; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace AsbCloudWebApi.Controllers { [ApiController] public abstract class CrudController : ControllerBase where T : IId where TService : ICrudService { protected readonly TService service; public CrudController(TService service) { this.service = service; } // GET api//5 [HttpGet("{id}")] public virtual IActionResult Get(int id, CancellationToken token = default) { var result = service.GetAsync(id, token).ConfigureAwait(false); return Ok(result); } // POST api/ [HttpPost] public virtual IActionResult Insert([FromBody] T value, CancellationToken token = default) { var result = service.InsertAsync(value, token).ConfigureAwait(false); return Ok(result); } // PUT api//5 [HttpPut("{id}")] public virtual IActionResult Put(int id, [FromBody] T value, CancellationToken token = default) { var result = service.UpdateAsync(value, token).ConfigureAwait(false); return Ok(result); } // DELETE api//5 [HttpDelete("{id}")] public virtual IActionResult Delete(int id, CancellationToken token = default) { var result = service.DeleteAsync(id, token).ConfigureAwait(false); return Ok(result); } } }