12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Transactions;
- using UnivateProperties_API.Containers.Property;
- using UnivateProperties_API.Model.Property;
- using UnivateProperties_API.Repository.Properties;
-
- namespace UnivateProperties_API.Controllers.Properties
- {
- [Route("Property/[controller]")]
- [ApiController]
- public class PropertyController : ControllerBase
- {
- private readonly IPropertyRepository _Repo;
-
- public PropertyController(IPropertyRepository repo)
- {
- _Repo = repo;
- }
-
- [HttpGet]
- public IActionResult Get()
- {
- return new OkObjectResult(_Repo.GetDisplay());
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
- }
-
- [HttpGet("search/{type}/{keyword}")]
- public IActionResult Get(string type, string Keyword)
- {
- return new OkObjectResult(_Repo.GetDisplay(Keyword));
- }
-
- [HttpGet("search/{type}/{propertytype}/{province}/{city}/{suburb}/{proptype}")]
- public IActionResult Get(string type, string propertyType, string province, string city, string suburb, string propType)
- {
- return new OkObjectResult(_Repo.GetDisplay(type, propertyType, province, city, suburb, propType));
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] Property property)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Insert(property);
- scope.Complete();
- return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
- }
- }
-
- [HttpPut]
- public IActionResult Put([FromBody] Property property)
- {
- if (property != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(property);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
- }
- }
|