API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PaymentController.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Transactions;
  3. using UnivateProperties_API.Model.Financial;
  4. using UnivateProperties_API.Repository;
  5. using UnivateProperties_API.Repository.Financial;
  6. namespace UnivateProperties_API.Controllers.Financial
  7. {
  8. [Route("api/[controller]")]
  9. [ApiController]
  10. public class PaymentController : ControllerBase
  11. {
  12. private readonly IRepository<Payment> _Repo;
  13. private readonly IPaygateRepository _paygateRepo;
  14. public PaymentController(IRepository<Payment> _repo, IPaygateRepository paygateRepo)
  15. {
  16. _Repo = _repo;
  17. _paygateRepo = paygateRepo;
  18. }
  19. [HttpGet]
  20. public IActionResult Get()
  21. {
  22. return new OkObjectResult(_Repo.GetAll());
  23. }
  24. [HttpGet("{id}")]
  25. public IActionResult Get(string id)
  26. {
  27. return new OkObjectResult(_Repo.Get(x => x.PayRequestId == id));
  28. }
  29. [HttpPost]
  30. public IActionResult Post([FromBody] Payment payment)
  31. {
  32. using (var scope = new TransactionScope())
  33. {
  34. var paymentResult = _paygateRepo.GoToPaymentGateway(payment);
  35. //_Repo.Insert(payment);
  36. scope.Complete();
  37. return new OkObjectResult(paymentResult);
  38. }
  39. }
  40. [HttpPut("{id}")]
  41. public IActionResult Put([FromBody] Payment payment)
  42. {
  43. if (payment != null)
  44. {
  45. using (var scope = new TransactionScope())
  46. {
  47. _Repo.Update(payment);
  48. scope.Complete();
  49. return new OkResult();
  50. }
  51. }
  52. return new NoContentResult();
  53. }
  54. }
  55. }