1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System.Transactions;
- using Microsoft.AspNetCore.Mvc;
- using UnivateProperties_API.Model.Properties;
- using UnivateProperties_API.Repository;
-
- namespace UnivateProperties_API.Controllers.Properties
- {
- [Route("api/[controller]")]
- [ApiController]
- public class PropertyUserFieldController : ControllerBase
- {
- private readonly IRepository<PropertyUserField> _Repo;
-
- public PropertyUserFieldController(IRepository<PropertyUserField> 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("PropertyFields/{id}")]
- public IActionResult GetPropertyFields(int id)
- {
- return new OkObjectResult(_Repo.Get(x => x.PropertyId == id));
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] PropertyUserField propertyUserField)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Insert(propertyUserField);
- scope.Complete();
- return CreatedAtAction(nameof(Get), new { id = propertyUserField.Id }, propertyUserField);
- }
- }
-
- [HttpPut]
- public IActionResult Put([FromBody] PropertyUserField propertyUserField)
- {
- if (propertyUserField != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(propertyUserField);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
- }
- }
|