12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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<Payment> _Repo;
- private readonly IPaygateRepository _paygateRepo;
-
- public PaymentController(IRepository<Payment> _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();
- }
- }
- }
|