API
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TimeshareWeekController.cs 5.2KB

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