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.

TimeshareWeekController.cs 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Linq;
  3. using System.Transactions;
  4. using UnivateProperties_API.Containers.Timeshare;
  5. using UnivateProperties_API.Model.Timeshare;
  6. using UnivateProperties_API.Repository;
  7. using UnivateProperties_API.Repository.Timeshare;
  8. namespace UnivateProperties_API.Controllers.Timeshare
  9. {
  10. [Route("api/[controller]")]
  11. [ApiController]
  12. public class TimeshareWeekController : ControllerBase
  13. {
  14. private readonly IWeekRepository _Repo;
  15. public TimeshareWeekController(IWeekRepository repo)
  16. {
  17. _Repo = repo;
  18. }
  19. [HttpGet]
  20. public IActionResult Get()
  21. {
  22. var items = (_Repo as WeekRepository).GetDtoListAll();
  23. return new OkObjectResult(items);
  24. }
  25. [HttpGet("GetTemplate")]
  26. public IActionResult GetTemplate()
  27. {
  28. return new OkObjectResult(new TimeshareWeekDto());
  29. }
  30. [HttpGet("{id}")]
  31. public IActionResult Get(int id)
  32. {
  33. var item = (_Repo as WeekRepository).GetMyDetailed(x => x.Id == id);
  34. return new OkObjectResult(item);
  35. }
  36. [HttpGet("getAvailResort")]
  37. public IActionResult GetAvailResort()
  38. {
  39. if (_Repo is WeekRepository)
  40. {
  41. var item = (_Repo as WeekRepository).GetAvailResort();
  42. return new OkObjectResult(item);
  43. }
  44. else return new OkResult();
  45. }
  46. [HttpGet("getMyWeek/{id}")]
  47. public IActionResult GetMyWeek(int id)
  48. {
  49. if (_Repo is WeekRepository)
  50. {
  51. var item = (_Repo as WeekRepository).GetMyWeeks(id);
  52. return new OkObjectResult(item);
  53. }
  54. else return new OkResult();
  55. }
  56. [HttpGet("getNeedApproval")]
  57. public IActionResult GetNeedApproval()
  58. {
  59. if (_Repo is WeekRepository)
  60. {
  61. var item = (_Repo as WeekRepository).GetNeedApproval();
  62. return new OkObjectResult(item);
  63. }
  64. else return new OkResult();
  65. }
  66. [HttpGet("getBy")]
  67. public IActionResult GetBy(WeekFilterDto week)
  68. {
  69. var item = (_Repo as WeekRepository).GetBy(week);
  70. return new OkObjectResult(item);
  71. }
  72. [HttpPost]
  73. public IActionResult Post([FromBody] TimeshareWeekDto item)
  74. {
  75. using (var scope = new TransactionScope())
  76. {
  77. var id = _Repo.SaveNewWeek(item);
  78. var savedItem = _Repo.Get(x => x.Id == id).FirstOrDefault();
  79. scope.Complete();
  80. return new OkObjectResult(savedItem);
  81. }
  82. }
  83. [HttpPut("{id}")]
  84. public IActionResult Put([FromBody] TimeshareWeek item)
  85. {
  86. if (item != null)
  87. {
  88. using (var scope = new TransactionScope())
  89. {
  90. _Repo.Update(item);
  91. scope.Complete();
  92. return new OkResult();
  93. }
  94. }
  95. return new NoContentResult();
  96. }
  97. [HttpDelete("{id}")]
  98. public IActionResult Delete(int id)
  99. {
  100. _Repo.RemoveAtId(id);
  101. return new OkResult();
  102. }
  103. [HttpPost("verifyweek/{id}")]
  104. public IActionResult Post(int id)
  105. {
  106. using (var scope = new TransactionScope())
  107. {
  108. (_Repo as WeekRepository).VerifyWeek(id);
  109. scope.Complete();
  110. return new OkResult();
  111. }
  112. }
  113. [HttpPost("publishweek/{id}")]
  114. public IActionResult Publishweek(int id)
  115. {
  116. using (var scope = new TransactionScope())
  117. {
  118. (_Repo as WeekRepository).VerifyWeek(id);
  119. scope.Complete();
  120. return new OkResult();
  121. }
  122. }
  123. [HttpGet("getTenderWeeks")]
  124. public IActionResult GetTenderWeeks()
  125. {
  126. var item = (_Repo as WeekRepository).GetTenderWeeks();
  127. return new OkObjectResult(item);
  128. }
  129. }
  130. }