using Microsoft.AspNetCore.Mvc; using System.Transactions; using UnivateProperties_API.Model.Financial; using UnivateProperties_API.Repository; using UnivateProperties_API.Repository.Financial; namespace UnivateProperties_API.Controllers.Financial { [Route("api/[controller]")] [ApiController] public class PaymentController : ControllerBase { private readonly IRepository _Repo; private readonly IPaygateRepository _paygateRepo; public PaymentController(IRepository _repo, IPaygateRepository paygateRepo) { _Repo = _repo; _paygateRepo = paygateRepo; } [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()) { var paymentResult = _paygateRepo.GoToPaymentGateway(payment); //_Repo.Insert(payment); scope.Complete(); return new OkObjectResult(paymentResult); } } [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(); } } }