API
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PaymentController.cs 1.5KB

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