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.

PropertyImageController.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Transactions;
  2. using Microsoft.AspNetCore.Mvc;
  3. using UnivateProperties_API.Containers.Property;
  4. using UnivateProperties_API.Model.Properties;
  5. using UnivateProperties_API.Repository.Properties;
  6. namespace UnivateProperties_API.Controllers.Properties
  7. {
  8. [Route("api/[controller]")]
  9. [ApiController]
  10. public class PropertyImageController : ControllerBase
  11. {
  12. private readonly IPropertyImageRepository _Repo;
  13. public PropertyImageController(IPropertyImageRepository repo)
  14. {
  15. _Repo = repo;
  16. }
  17. [HttpGet]
  18. public IActionResult Get()
  19. {
  20. return new OkObjectResult(_Repo.GetAll());
  21. }
  22. [HttpGet("{id}")]
  23. public IActionResult Get(int id)
  24. {
  25. return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
  26. }
  27. [HttpGet("GetImagesByProperty/{PropertyId}")]
  28. public IActionResult GetImagesByProperty(int PropertyId) //Property string is more of a placeholder here.
  29. {
  30. return new OkObjectResult(_Repo.GetImages(PropertyId));
  31. }
  32. [HttpGet("GetProperySavedImages/{PropertyId}")]
  33. public IActionResult GetProperySavedImages(int PropertyId) //Property string is more of a placeholder here.
  34. {
  35. return new OkObjectResult(_Repo.Get(x => x.PropertyId == PropertyId));
  36. }
  37. [HttpPost]
  38. public IActionResult Post([FromBody] NewPropertyImages propertyImage)
  39. {
  40. using (var scope = new TransactionScope())
  41. {
  42. _Repo.Update(propertyImage);
  43. scope.Complete();
  44. return new OkResult();
  45. }
  46. }
  47. [HttpPut]
  48. public IActionResult Put([FromBody] PropertyImage propertyImage)
  49. {
  50. if (propertyImage != null)
  51. {
  52. using (var scope = new TransactionScope())
  53. {
  54. _Repo.Update(propertyImage);
  55. scope.Complete();
  56. return new OkResult();
  57. }
  58. }
  59. return new NoContentResult();
  60. }
  61. [HttpDelete("{id}")]
  62. public IActionResult Delete(int id)
  63. {
  64. _Repo.RemoveAtId(id);
  65. return new OkResult();
  66. }
  67. }
  68. }