12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Transactions;
- using Microsoft.AspNetCore.Mvc;
- using UnivateProperties_API.Containers.Property;
- using UnivateProperties_API.Model.Properties;
- using UnivateProperties_API.Repository.Properties;
-
- namespace UnivateProperties_API.Controllers.Properties
- {
- [Route("api/[controller]")]
- [ApiController]
- public class PropertyImageController : ControllerBase
- {
- private readonly IPropertyImageRepository _Repo;
-
- public PropertyImageController(IPropertyImageRepository repo)
- {
- _Repo = repo;
- }
-
- [HttpGet]
- public IActionResult Get()
- {
- return new OkObjectResult(_Repo.GetAll());
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
- }
-
- [HttpGet("GetImagesByProperty/{PropertyId}")]
- public IActionResult GetImagesByProperty(int PropertyId) //Property string is more of a placeholder here.
- {
- return new OkObjectResult(_Repo.GetImages(PropertyId));
- }
-
- [HttpGet("GetProperySavedImages/{PropertyId}")]
- public IActionResult GetProperySavedImages(int PropertyId) //Property string is more of a placeholder here.
- {
- return new OkObjectResult(_Repo.Get(x => x.PropertyId == PropertyId));
- }
-
- [HttpGet("SavePropImages")]
- public IActionResult SavePropImages()
- {
- _Repo.UpdateToPhysical();
- return new OkResult();
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] NewPropertyImages propertyImage)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(propertyImage);
- scope.Complete();
- return new OkResult();
- }
- }
-
- [HttpPut]
- public IActionResult Put([FromBody] PropertyImage propertyImage)
- {
- if (propertyImage != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(propertyImage);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
- }
- }
|