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.

PropertyController.cs 5.1KB

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