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

TimeshareWeekController.cs 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. [HttpPut("publishOnly")]
  108. public IActionResult PublishOnly([FromBody] WeekDto item)
  109. {
  110. if (item != null)
  111. {
  112. using (var scope = new TransactionScope())
  113. {
  114. _Repo.PublishOnly(item);
  115. scope.Complete();
  116. return new OkResult();
  117. }
  118. }
  119. return new NoContentResult();
  120. }
  121. [HttpDelete("{id}")]
  122. public IActionResult Delete(int id)
  123. {
  124. _Repo.RemoveAtId(id);
  125. return new OkResult();
  126. }
  127. [HttpPost("verifyweek/{id}")]
  128. public IActionResult Post(int id)
  129. {
  130. using (var scope = new TransactionScope())
  131. {
  132. (_Repo as WeekRepository).VerifyWeek(id);
  133. scope.Complete();
  134. return new OkResult();
  135. }
  136. }
  137. [HttpPost("publishweek/{id}")]
  138. public IActionResult Publishweek(int id)
  139. {
  140. using (var scope = new TransactionScope())
  141. {
  142. (_Repo as WeekRepository).VerifyWeek(id);
  143. scope.Complete();
  144. return new OkResult();
  145. }
  146. }
  147. [HttpGet("getTenderWeeks")]
  148. public IActionResult GetTenderWeeks()
  149. {
  150. var item = (_Repo as WeekRepository).GetTenderWeeks();
  151. return new OkObjectResult(item);
  152. }
  153. }
  154. }