API
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

PropertyController.cs 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Transactions;
  5. using UnivateProperties_API.Containers.Property;
  6. using UnivateProperties_API.Model.Properties;
  7. using UnivateProperties_API.Repository.Properties;
  8. namespace UnivateProperties_API.Controllers.Properties
  9. {
  10. [Route("api/[controller]")]
  11. [ApiController]
  12. public class PropertyController : ControllerBase
  13. {
  14. private readonly IPropertyRepository _Repo;
  15. public PropertyController(IPropertyRepository repo)
  16. {
  17. _Repo = repo;
  18. }
  19. #region Get Methods
  20. [HttpGet]
  21. public IActionResult Get()
  22. {
  23. return new OkObjectResult(_Repo.GetDisplay());
  24. }
  25. [HttpGet("getDetailed/{id}")]
  26. public IActionResult GetDetailed(int id)
  27. {
  28. return new OkObjectResult(_Repo.GetDetailed(id, true));
  29. }
  30. [HttpGet("getProperty/{id}")]
  31. public IActionResult GetProperty(int id)
  32. {
  33. return new OkObjectResult(_Repo.GetDetailed(id, false));
  34. }
  35. [HttpGet("latestProperties")]
  36. public IActionResult GetLatestProperties()
  37. {
  38. return new OkObjectResult(_Repo.GetLatestDisplay());
  39. }
  40. [HttpGet("{type}/{by}")]
  41. public IActionResult SearchBy(string type, int by)
  42. {
  43. return new OkObjectResult(_Repo.GetPropertyList(type, by));
  44. }
  45. [HttpGet("MayEditProperty/{id}")]
  46. public IActionResult MayEditProperty(int id)
  47. {
  48. return new OkObjectResult(_Repo.MayEdit(id));
  49. }
  50. #endregion
  51. [HttpGet("search")]
  52. public IActionResult Search([FromBody] PropertySearch search)
  53. {
  54. return new OkObjectResult(_Repo.GetDisplay(search));
  55. }
  56. //Will need to come out. Post search not working......:(
  57. [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}")]
  58. public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice)
  59. {
  60. var search = new PropertySearch()
  61. {
  62. UserName = userName,
  63. Keyword = keyword,
  64. SalesType = salesType,
  65. PropertyUsageType = propertyUsageType,
  66. PropertyType = propertyType,
  67. Province = province,
  68. City = city,
  69. Suburb = suburb,
  70. MinPrice = minPrice,
  71. MaxPrice = maxPrice
  72. };
  73. return new OkObjectResult(_Repo.GetDisplay(search));
  74. }
  75. [HttpPost]
  76. public IActionResult Post([FromBody] PropertyContainer property)
  77. {
  78. using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
  79. {
  80. _Repo.Insert(property);
  81. scope.Complete();
  82. return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
  83. }
  84. }
  85. [HttpPut]
  86. public IActionResult Put([FromBody] PropertyContainer property)
  87. {
  88. if (property != null)
  89. {
  90. using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
  91. {
  92. _Repo.Update(property);
  93. scope.Complete();
  94. return new OkResult();
  95. }
  96. }
  97. return new NoContentResult();
  98. }
  99. [HttpDelete("{id}")]
  100. public IActionResult Delete(int id)
  101. {
  102. _Repo.RemoveAtId(id);
  103. return new OkResult();
  104. }
  105. }
  106. }