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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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("getByResortCode/{resortCode}")]
  47. public IActionResult GetAvailResort(string resortCode)
  48. {
  49. if (_Repo is WeekRepository)
  50. {
  51. var item = (_Repo as WeekRepository).GetAllByResortCode(resortCode);
  52. return new OkObjectResult(item);
  53. }
  54. else return new OkResult();
  55. }
  56. [HttpGet("getMyWeek/{id}")]
  57. public IActionResult GetMyWeek(int id)
  58. {
  59. if (_Repo is WeekRepository)
  60. {
  61. var item = (_Repo as WeekRepository).GetMyWeeks(id);
  62. return new OkObjectResult(item);
  63. }
  64. else return new OkResult();
  65. }
  66. [HttpGet("getNeedApproval")]
  67. public IActionResult GetNeedApproval()
  68. {
  69. if (_Repo is WeekRepository)
  70. {
  71. var item = (_Repo as WeekRepository).GetNeedApproval();
  72. return new OkObjectResult(item);
  73. }
  74. else return new OkResult();
  75. }
  76. [HttpGet("getBy")]
  77. public IActionResult GetBy(WeekFilterDto week)
  78. {
  79. var item = (_Repo as WeekRepository).GetBy(week);
  80. return new OkObjectResult(item);
  81. }
  82. [HttpPost]
  83. public IActionResult Post([FromBody] TimeshareWeekDto item)
  84. {
  85. using (var scope = new TransactionScope())
  86. {
  87. var id = _Repo.SaveNewWeek(item);
  88. var savedItem = _Repo.Get(x => x.Id == id).FirstOrDefault();
  89. scope.Complete();
  90. return new OkObjectResult(savedItem);
  91. }
  92. }
  93. [HttpPut]
  94. public IActionResult Put([FromBody] TimeshareWeek item)
  95. {
  96. if (item != null)
  97. {
  98. using (var scope = new TransactionScope())
  99. {
  100. _Repo.Update(item);
  101. scope.Complete();
  102. return new OkResult();
  103. }
  104. }
  105. return new NoContentResult();
  106. }
  107. [HttpDelete("{id}")]
  108. public IActionResult Delete(int id)
  109. {
  110. _Repo.RemoveAtId(id);
  111. return new OkResult();
  112. }
  113. [HttpPost("verifyweek/{id}")]
  114. public IActionResult Post(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. [HttpPost("publishweek/{id}")]
  124. public IActionResult Publishweek(int id)
  125. {
  126. using (var scope = new TransactionScope())
  127. {
  128. (_Repo as WeekRepository).VerifyWeek(id);
  129. scope.Complete();
  130. return new OkResult();
  131. }
  132. }
  133. [HttpGet("getTenderWeeks")]
  134. public IActionResult GetTenderWeeks()
  135. {
  136. var item = (_Repo as WeekRepository).GetTenderWeeks();
  137. return new OkObjectResult(item);
  138. }
  139. }
  140. }