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 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using Microsoft.AspNetCore.Mvc;
  2. using System;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Transactions;
  6. using UnivateProperties_API.Containers.Timeshare;
  7. using UnivateProperties_API.Model.Timeshare;
  8. using UnivateProperties_API.Repository;
  9. using UnivateProperties_API.Repository.Timeshare;
  10. namespace UnivateProperties_API.Controllers.Timeshare
  11. {
  12. [Route("api/[controller]")]
  13. [ApiController]
  14. public class TimeshareWeekController : ControllerBase
  15. {
  16. private readonly IWeekRepository _Repo;
  17. public TimeshareWeekController(IWeekRepository repo)
  18. {
  19. _Repo = repo;
  20. }
  21. [HttpGet]
  22. public IActionResult Get()
  23. {
  24. var items = (_Repo as WeekRepository).GetDtoListAll();
  25. return new OkObjectResult(items);
  26. }
  27. [HttpGet("GetTemplate")]
  28. public IActionResult GetTemplate()
  29. {
  30. return new OkObjectResult(new TimeshareWeekDto());
  31. }
  32. [HttpGet("{id}")]
  33. public IActionResult Get(int id)
  34. {
  35. var item = (_Repo as WeekRepository).GetMyDetailed(x => x.Id == id);
  36. return new OkObjectResult(item);
  37. }
  38. [HttpGet("getAvailResort")]
  39. public IActionResult GetAvailResort()
  40. {
  41. if (_Repo is WeekRepository)
  42. {
  43. var item = (_Repo as WeekRepository).GetAvailResort();
  44. return new OkObjectResult(item);
  45. }
  46. else return new OkResult();
  47. }
  48. [HttpGet("getByResortCode/{resortCode}")]
  49. public IActionResult GetAvailResort(string resortCode)
  50. {
  51. if (_Repo is WeekRepository)
  52. {
  53. var item = (_Repo as WeekRepository).GetAllByResortCode(resortCode);
  54. return new OkObjectResult(item);
  55. }
  56. else return new OkResult();
  57. }
  58. [HttpGet("getMyWeek/{id}")]
  59. public IActionResult GetMyWeek(int id)
  60. {
  61. if (_Repo is WeekRepository)
  62. {
  63. var item = (_Repo as WeekRepository).GetMyWeeks(id);
  64. return new OkObjectResult(item);
  65. }
  66. else return new OkResult();
  67. }
  68. [HttpGet("getNeedApproval")]
  69. public IActionResult GetNeedApproval()
  70. {
  71. if (_Repo is WeekRepository)
  72. {
  73. var item = (_Repo as WeekRepository).GetNeedApproval();
  74. return new OkObjectResult(item);
  75. }
  76. else return new OkResult();
  77. }
  78. [HttpGet("getBy")]
  79. public IActionResult GetBy(WeekFilterDto week)
  80. {
  81. var item = (_Repo as WeekRepository).GetBy(week);
  82. return new OkObjectResult(item);
  83. }
  84. [HttpGet("getLatest")]
  85. public IActionResult GetLatest()
  86. {
  87. var item = (_Repo as WeekRepository).GetLatest();
  88. return new OkObjectResult(item);
  89. }
  90. [HttpGet("indivWeekCount/{id}")]
  91. public IActionResult IndivWeekCount(int id)
  92. {
  93. var count = (_Repo as WeekRepository).IndivWeekCount(id);
  94. return new OkObjectResult(count);
  95. }
  96. [HttpPost]
  97. public IActionResult Post([FromBody] TimeshareWeekDto item)
  98. {
  99. try
  100. {
  101. using (var scope = new TransactionScope())
  102. {
  103. var id = _Repo.SaveNewWeek(item);
  104. var savedItem = _Repo.Get(x => x.Id == id).FirstOrDefault();
  105. scope.Complete();
  106. return new OkObjectResult(savedItem);
  107. }
  108. }
  109. catch(Exception ex)
  110. {
  111. return StatusCode((int)HttpStatusCode.InternalServerError, ex);
  112. }
  113. }
  114. [HttpPut]
  115. public IActionResult Put([FromBody] TimeshareWeek item)
  116. {
  117. if (item != null)
  118. {
  119. using (var scope = new TransactionScope())
  120. {
  121. _Repo.Update(item);
  122. scope.Complete();
  123. return new OkResult();
  124. }
  125. }
  126. return new NoContentResult();
  127. }
  128. [HttpPut("publishOnly")]
  129. public IActionResult PublishOnly([FromBody] WeekDto item)
  130. {
  131. if (item != null)
  132. {
  133. using (var scope = new TransactionScope())
  134. {
  135. _Repo.PublishOnly(item);
  136. scope.Complete();
  137. return new OkResult();
  138. }
  139. }
  140. return new NoContentResult();
  141. }
  142. [HttpDelete("{id}")]
  143. public IActionResult Delete(int id)
  144. {
  145. _Repo.RemoveAtId(id);
  146. return new OkResult();
  147. }
  148. [HttpPost("verifyweek/{id}")]
  149. public IActionResult Post(int id)
  150. {
  151. using (var scope = new TransactionScope())
  152. {
  153. (_Repo as WeekRepository).VerifyWeek(id);
  154. scope.Complete();
  155. return new OkResult();
  156. }
  157. }
  158. [HttpPost("PublishWeek/{id}")]
  159. public IActionResult PublishWeek(int id)
  160. {
  161. using (var scope = new TransactionScope())
  162. {
  163. (_Repo as WeekRepository).PublishWeek(id);
  164. scope.Complete();
  165. return new OkResult();
  166. }
  167. }
  168. [HttpPost("UnpublishWeek/{id}")]
  169. public IActionResult UnpublishWeek(int id)
  170. {
  171. using (var scope = new TransactionScope())
  172. {
  173. (_Repo as WeekRepository).UnpublishWeek(id);
  174. scope.Complete();
  175. return new OkResult();
  176. }
  177. }
  178. [HttpGet("getTenderWeeks")]
  179. public IActionResult GetTenderWeeks()
  180. {
  181. var item = (_Repo as WeekRepository).GetTenderWeeks();
  182. return new OkObjectResult(item);
  183. }
  184. }
  185. }