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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using Microsoft.AspNetCore.Mvc;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  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 IRepository<TimeshareWeek> _Repo;
  17. public TimeshareWeekController(IRepository<TimeshareWeek> 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("{id}")]
  28. public IActionResult Get(int id)
  29. {
  30. var item = _Repo.Get(x => x.Id == id);
  31. return new OkObjectResult(item);
  32. }
  33. [HttpGet("getAvailResort")]
  34. public IActionResult GetAvailResort()
  35. {
  36. if (_Repo is WeekRepository)
  37. {
  38. var item = (_Repo as WeekRepository).GetAvailResort();
  39. return new OkObjectResult(item);
  40. }
  41. else return new OkResult();
  42. }
  43. [HttpGet("getMyWeek/{id}")]
  44. public IActionResult GetMyWeek(int id)
  45. {
  46. if (_Repo is WeekRepository)
  47. {
  48. var item = (_Repo as WeekRepository).GetMyWeeks(id);
  49. return new OkObjectResult(item);
  50. }
  51. else return new OkResult();
  52. }
  53. [HttpGet("getBy")]
  54. public IActionResult GetBy(WeekFilterDto week)
  55. {
  56. var item = (_Repo as WeekRepository).GetBy(week);
  57. return new OkObjectResult(item);
  58. }
  59. [HttpPost]
  60. public IActionResult Post([FromBody] TimeshareWeek item)
  61. {
  62. using (var scope = new TransactionScope())
  63. {
  64. _Repo.Insert(item);
  65. scope.Complete();
  66. return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  67. }
  68. }
  69. [HttpPut("{id}")]
  70. public IActionResult Put([FromBody] TimeshareWeek item)
  71. {
  72. if (item != null)
  73. {
  74. using (var scope = new TransactionScope())
  75. {
  76. _Repo.Update(item);
  77. scope.Complete();
  78. return new OkResult();
  79. }
  80. }
  81. return new NoContentResult();
  82. }
  83. [HttpDelete("{id}")]
  84. public IActionResult Delete(int id)
  85. {
  86. _Repo.RemoveAtId(id);
  87. return new OkResult();
  88. }
  89. }
  90. }