using Microsoft.AspNetCore.Mvc; using System.Transactions; using UnivateProperties_API.Model.Region; using UnivateProperties_API.Repository; namespace UnivateProperties_API.Controllers.Region { [Route("Region/[controller]")] [ApiController] public class ProvinceController : ControllerBase { private readonly IRepository _Repo; public ProvinceController(IRepository repo) { _Repo = repo; } [HttpGet] public IActionResult Get() { return new OkObjectResult(_Repo.GetAll()); } [HttpGet("{id}")] public IActionResult Get(int id) { return new OkObjectResult(_Repo.Get(x => x.Id == id)); } [HttpPost] public IActionResult Post([FromBody] Province province) { using (var scope = new TransactionScope()) { _Repo.Insert(province); scope.Complete(); return CreatedAtAction(nameof(Get), new { id = province.Id }, province); } } [HttpPut] public IActionResult Put([FromBody] Province province) { if (province != null) { using (var scope = new TransactionScope()) { _Repo.Update(province); scope.Complete(); return new OkResult(); } } return new NoContentResult(); } [HttpDelete("{id}")] public IActionResult Delete(int id) { _Repo.RemoveAtId(id); return new OkResult(); } } }