using Microsoft.AspNetCore.Mvc; using System.Transactions; using UnivateProperties_API.Model.Financial; using UnivateProperties_API.Repository; namespace UnivateProperties_API.Controllers.Financial { [Route("api/[controller]")] [ApiController] public class PaymentController : ControllerBase { private readonly IRepository _Repo; public PaymentController(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] Payment payment) { using (var scope = new TransactionScope()) { _Repo.Insert(payment); scope.Complete(); return CreatedAtAction(nameof(Get), new { id = payment.Id }, payment); } } [HttpPut("{id}")] public IActionResult Put([FromBody] Payment payment) { if (payment != null) { using (var scope = new TransactionScope()) { _Repo.Update(payment); scope.Complete(); return new OkResult(); } } return new NoContentResult(); } } }