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.

IndividualController.cs 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System.Transactions;
  2. using Microsoft.AspNetCore.Mvc;
  3. using UnivateProperties_API.Containers.Timeshare.Detailed;
  4. using UnivateProperties_API.Model.Users;
  5. using UnivateProperties_API.Repository;
  6. using UnivateProperties_API.Repository.Users;
  7. namespace User_API.Controllers
  8. {
  9. [Route("api/[controller]")]
  10. [ApiController]
  11. public class IndividualController : ControllerBase
  12. {
  13. private readonly IRepository<Individual> _Repo;
  14. public IndividualController(IRepository<Individual> repo)
  15. {
  16. _Repo = repo;
  17. }
  18. //Gets data from the DB
  19. [HttpGet]
  20. public IActionResult Get()
  21. {
  22. return new OkObjectResult(_Repo.GetAll());
  23. }
  24. //Gets data from DB by Id
  25. [HttpGet("{id}")]
  26. public IActionResult Get(int id)
  27. {
  28. return new OkObjectResult(_Repo.Get(x => x.Id == id));
  29. }
  30. [HttpGet("getIndividual/{id}")]
  31. public IActionResult GetIndividual(int id)
  32. {
  33. return new OkObjectResult((_Repo as IndividualRepository).GetIndividual(id));
  34. }
  35. [HttpGet("getAllIndividuals")]
  36. public IActionResult GetAllIndividuals()
  37. {
  38. return new OkObjectResult((_Repo as IndividualRepository).GetAllIndividuals());
  39. }
  40. [HttpPut()]
  41. public IActionResult Put([FromBody]DetailedOwner owner)
  42. {
  43. if (owner != null)
  44. {
  45. using (var scope = new TransactionScope())
  46. {
  47. (_Repo as IndividualRepository).Update(owner);
  48. scope.Complete();
  49. return new OkResult();
  50. }
  51. }
  52. return new NoContentResult();
  53. }
  54. //Updates DB by removing said Id
  55. [HttpDelete("{id}")]
  56. public IActionResult Delete(int id)
  57. {
  58. _Repo.RemoveAtId(id);
  59. return new OkResult();
  60. }
  61. }
  62. }