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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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("latestProperties/{type}")]
  42. public IActionResult GetLatestProperties(string type)
  43. {
  44. return new OkObjectResult(_Repo.GetLatestDisplay(type));
  45. }
  46. [HttpGet("GetPropertyList/{by}")]
  47. public IActionResult SearchBy(int by)
  48. {
  49. return new OkObjectResult(_Repo.GetPropertyList(by));
  50. }
  51. [HttpGet("GetLivePropertyList")]
  52. public IActionResult GetLivePropertyList()
  53. {
  54. return new OkObjectResult(_Repo.GetPropertyList());
  55. }
  56. [HttpGet("MayEditProperty/{id}")]
  57. public IActionResult MayEditProperty(int id)
  58. {
  59. return new OkObjectResult(_Repo.MayEdit(id));
  60. }
  61. [HttpGet("GetAdminProperties/{userId}")]
  62. public IActionResult GetAdminProperties(int userId)
  63. {
  64. return new OkObjectResult(_Repo.GetAdminProperties(userId));
  65. }
  66. [HttpGet("GetPropertyStatuses")]
  67. public IActionResult GetPropertyStatuses()
  68. {
  69. return new OkObjectResult(_Repo.GetStatuses());
  70. }
  71. #endregion
  72. [HttpGet("search")]
  73. public IActionResult Search([FromBody] PropertySearch search)
  74. {
  75. return new OkObjectResult(_Repo.GetDisplay(search));
  76. }
  77. //Will need to come out. Post search not working......:(
  78. [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}/{availableFrom}/{propertyId}")]
  79. 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)
  80. {
  81. var search = new PropertySearch()
  82. {
  83. UserName = userName,
  84. Keyword = keyword,
  85. SalesType = salesType,
  86. PropertyUsageType = propertyUsageType,
  87. PropertyType = propertyType,
  88. Province = province,
  89. City = city,
  90. Suburb = suburb,
  91. MinPrice = minPrice,
  92. MaxPrice = maxPrice,
  93. PropertyId = propertyId
  94. };
  95. if (availableFrom == "undefined")
  96. search.AvailableFrom = DateTime.MinValue;
  97. else
  98. search.AvailableFrom = DateTime.Parse(availableFrom);
  99. return new OkObjectResult(_Repo.GetDisplay(search));
  100. }
  101. [HttpPost]
  102. public IActionResult Post([FromBody] PropertyContainer property)
  103. {
  104. using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
  105. {
  106. _Repo.Insert(property);
  107. scope.Complete();
  108. return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
  109. }
  110. }
  111. [HttpPut]
  112. public IActionResult Put([FromBody] PropertyContainer property)
  113. {
  114. if (property != null)
  115. {
  116. using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
  117. {
  118. _Repo.Update(property);
  119. scope.Complete();
  120. return new OkResult();
  121. }
  122. }
  123. return new NoContentResult();
  124. }
  125. [HttpPut("PublishProperty")]
  126. public IActionResult PublishProperty([FromBody] PropertyAdminContainer property)
  127. {
  128. _Repo.PublishProperty(property.Id);
  129. return new NoContentResult();
  130. }
  131. [HttpPut("UnpublishProperty")]
  132. public IActionResult UnpublishProperty(PropertyAdminContainer property)
  133. {
  134. _Repo.UnpublishProperty(property.Id);
  135. return new NoContentResult();
  136. }
  137. [HttpDelete("{id}")]
  138. public IActionResult Delete(int id)
  139. {
  140. _Repo.RemoveAtId(id);
  141. return new OkResult();
  142. }
  143. }
  144. }