API
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

CarouselController.cs 1.7KB

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