API
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TimeshareWeekController.cs 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. [HttpPost]
  91. public IActionResult Post([FromBody] TimeshareWeekDto item)
  92. {
  93. try
  94. {
  95. using (var scope = new TransactionScope())
  96. {
  97. var id = _Repo.SaveNewWeek(item);
  98. var savedItem = _Repo.Get(x => x.Id == id).FirstOrDefault();
  99. scope.Complete();
  100. return new OkObjectResult(savedItem);
  101. }
  102. }
  103. catch(Exception ex)
  104. {
  105. return StatusCode((int)HttpStatusCode.InternalServerError, ex);
  106. }
  107. }
  108. [HttpPut]
  109. public IActionResult Put([FromBody] TimeshareWeek item)
  110. {
  111. if (item != null)
  112. {
  113. using (var scope = new TransactionScope())
  114. {
  115. _Repo.Update(item);
  116. scope.Complete();
  117. return new OkResult();
  118. }
  119. }
  120. return new NoContentResult();
  121. }
  122. [HttpPut("publishOnly")]
  123. public IActionResult PublishOnly([FromBody] WeekDto item)
  124. {
  125. if (item != null)
  126. {
  127. using (var scope = new TransactionScope())
  128. {
  129. _Repo.PublishOnly(item);
  130. scope.Complete();
  131. return new OkResult();
  132. }
  133. }
  134. return new NoContentResult();
  135. }
  136. [HttpDelete("{id}")]
  137. public IActionResult Delete(int id)
  138. {
  139. _Repo.RemoveAtId(id);
  140. return new OkResult();
  141. }
  142. [HttpPost("verifyweek/{id}")]
  143. public IActionResult Post(int id)
  144. {
  145. using (var scope = new TransactionScope())
  146. {
  147. (_Repo as WeekRepository).VerifyWeek(id);
  148. scope.Complete();
  149. return new OkResult();
  150. }
  151. }
  152. [HttpPost("PublishWeek/{id}")]
  153. public IActionResult PublishWeek(int id)
  154. {
  155. using (var scope = new TransactionScope())
  156. {
  157. (_Repo as WeekRepository).PublishWeek(id);
  158. scope.Complete();
  159. return new OkResult();
  160. }
  161. }
  162. [HttpPost("UnpublishWeek/{id}")]
  163. public IActionResult UnpublishWeek(int id)
  164. {
  165. using (var scope = new TransactionScope())
  166. {
  167. (_Repo as WeekRepository).UnpublishWeek(id);
  168. scope.Complete();
  169. return new OkResult();
  170. }
  171. }
  172. [HttpGet("getTenderWeeks")]
  173. public IActionResult GetTenderWeeks()
  174. {
  175. var item = (_Repo as WeekRepository).GetTenderWeeks();
  176. return new OkObjectResult(item);
  177. }
  178. }
  179. }