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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. [HttpGet("SavePropImages")]
  38. public IActionResult SavePropImages()
  39. {
  40. _Repo.UpdateToPhysical();
  41. return new OkResult();
  42. }
  43. [HttpPost]
  44. public IActionResult Post([FromBody] NewPropertyImages propertyImage)
  45. {
  46. using (var scope = new TransactionScope())
  47. {
  48. _Repo.Update(propertyImage);
  49. scope.Complete();
  50. return new OkResult();
  51. }
  52. }
  53. [HttpPut]
  54. public IActionResult Put([FromBody] PropertyImage propertyImage)
  55. {
  56. if (propertyImage != null)
  57. {
  58. using (var scope = new TransactionScope())
  59. {
  60. _Repo.Update(propertyImage);
  61. scope.Complete();
  62. return new OkResult();
  63. }
  64. }
  65. return new NoContentResult();
  66. }
  67. [HttpDelete("{id}")]
  68. public IActionResult Delete(int id)
  69. {
  70. _Repo.RemoveAtId(id);
  71. return new OkResult();
  72. }
  73. }
  74. }