API
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

UnitConfigurationController.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Transactions;
  3. using UnivateProperties_API.Model.Timeshare;
  4. using UnivateProperties_API.Repository;
  5. using UnivateProperties_API.Repository.Timeshare;
  6. namespace UnivateProperties_API.Controllers.Timeshare
  7. {
  8. [Route("api/[controller]")]
  9. [ApiController]
  10. public class UnitConfigurationController : ControllerBase
  11. {
  12. private readonly IRepository<UnitConfiguration> _Repo;
  13. public UnitConfigurationController(IRepository<UnitConfiguration> repo)
  14. {
  15. _Repo = repo;
  16. }
  17. [HttpGet]
  18. public IActionResult Get()
  19. {
  20. var items = (_Repo as UnitConfigurationRepository).GetMyDetailed();
  21. return new OkObjectResult(items);
  22. }
  23. [HttpGet("{id}")]
  24. public IActionResult Get(int id)
  25. {
  26. var item = _Repo.Get(x => x.Id == id);
  27. return new OkObjectResult(item);
  28. }
  29. [HttpPost]
  30. public IActionResult Post([FromBody] UnitConfiguration item)
  31. {
  32. using (var scope = new TransactionScope())
  33. {
  34. _Repo.Insert(item);
  35. scope.Complete();
  36. return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  37. }
  38. }
  39. [HttpPut("{id}")]
  40. public IActionResult Put([FromBody] UnitConfiguration item)
  41. {
  42. if (item != null)
  43. {
  44. using (var scope = new TransactionScope())
  45. {
  46. _Repo.Update(item);
  47. scope.Complete();
  48. return new OkResult();
  49. }
  50. }
  51. return new NoContentResult();
  52. }
  53. [HttpDelete("{id}")]
  54. public IActionResult Delete(int id)
  55. {
  56. _Repo.RemoveAtId(id);
  57. return new OkResult();
  58. }
  59. }
  60. }