API
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TimeshareWeekController.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Transactions;
  3. using UnivateProperties_API.Containers.Timeshare;
  4. using UnivateProperties_API.Model.Timeshare;
  5. using UnivateProperties_API.Repository;
  6. using UnivateProperties_API.Repository.Timeshare;
  7. namespace UnivateProperties_API.Controllers.Timeshare
  8. {
  9. [Route("api/[controller]")]
  10. [ApiController]
  11. public class TimeshareWeekController : ControllerBase
  12. {
  13. private readonly IRepository<TimeshareWeek> _Repo;
  14. public TimeshareWeekController(IRepository<TimeshareWeek> repo)
  15. {
  16. _Repo = repo;
  17. }
  18. [HttpGet]
  19. public IActionResult Get()
  20. {
  21. var items = (_Repo as WeekRepository).GetDtoListAll();
  22. return new OkObjectResult(items);
  23. }
  24. [HttpGet("{id}")]
  25. public IActionResult Get(int id)
  26. {
  27. var item = (_Repo as WeekRepository).GetMyDetailed(x => x.Id == id);
  28. return new OkObjectResult(item);
  29. }
  30. [HttpGet("getAvailResort")]
  31. public IActionResult GetAvailResort()
  32. {
  33. if (_Repo is WeekRepository)
  34. {
  35. var item = (_Repo as WeekRepository).GetAvailResort();
  36. return new OkObjectResult(item);
  37. }
  38. else return new OkResult();
  39. }
  40. [HttpGet("getMyWeek/{id}")]
  41. public IActionResult GetMyWeek(int id)
  42. {
  43. if (_Repo is WeekRepository)
  44. {
  45. var item = (_Repo as WeekRepository).GetMyWeeks(id);
  46. return new OkObjectResult(item);
  47. }
  48. else return new OkResult();
  49. }
  50. [HttpGet("getBy")]
  51. public IActionResult GetBy(WeekFilterDto week)
  52. {
  53. var item = (_Repo as WeekRepository).GetBy(week);
  54. return new OkObjectResult(item);
  55. }
  56. [HttpPost]
  57. public IActionResult Post([FromBody] TimeshareWeek item)
  58. {
  59. using (var scope = new TransactionScope())
  60. {
  61. _Repo.Insert(item);
  62. scope.Complete();
  63. return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  64. }
  65. }
  66. [HttpPut("{id}")]
  67. public IActionResult Put([FromBody] TimeshareWeek item)
  68. {
  69. if (item != null)
  70. {
  71. using (var scope = new TransactionScope())
  72. {
  73. _Repo.Update(item);
  74. scope.Complete();
  75. return new OkResult();
  76. }
  77. }
  78. return new NoContentResult();
  79. }
  80. [HttpDelete("{id}")]
  81. public IActionResult Delete(int id)
  82. {
  83. _Repo.RemoveAtId(id);
  84. return new OkResult();
  85. }
  86. }
  87. }