API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TimeshareWeekController.cs 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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("getBy")]
  34. public IActionResult GetBy(WeekFilterDto week)
  35. {
  36. var item = (_Repo as WeekRepository).GetBy(week);
  37. return new OkObjectResult(item);
  38. }
  39. [HttpPost]
  40. public IActionResult Post([FromBody] TimeshareWeek item)
  41. {
  42. using (var scope = new TransactionScope())
  43. {
  44. _Repo.Insert(item);
  45. scope.Complete();
  46. return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  47. }
  48. }
  49. [HttpPut("{id}")]
  50. public IActionResult Put([FromBody] TimeshareWeek item)
  51. {
  52. if (item != null)
  53. {
  54. using (var scope = new TransactionScope())
  55. {
  56. _Repo.Update(item);
  57. scope.Complete();
  58. return new OkResult();
  59. }
  60. }
  61. return new NoContentResult();
  62. }
  63. [HttpDelete("{id}")]
  64. public IActionResult Delete(int id)
  65. {
  66. _Repo.RemoveAtId(id);
  67. return new OkResult();
  68. }
  69. }
  70. }