API
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PropertyController.cs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #endregion
  46. [HttpGet("search")]
  47. public IActionResult Search([FromBody] PropertySearch search)
  48. {
  49. return new OkObjectResult(_Repo.GetDisplay(search));
  50. }
  51. //Will need to come out. Post search not working......:(
  52. [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}")]
  53. public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice)
  54. {
  55. var search = new PropertySearch()
  56. {
  57. UserName = userName,
  58. Keyword = keyword,
  59. SalesType = salesType,
  60. PropertyUsageType = propertyUsageType,
  61. PropertyType = propertyType,
  62. Province = province,
  63. City = city,
  64. Suburb = suburb,
  65. MinPrice = minPrice,
  66. MaxPrice = maxPrice
  67. };
  68. return new OkObjectResult(_Repo.GetDisplay(search));
  69. }
  70. [HttpPost]
  71. public IActionResult Post([FromBody] PropertyContainer property)
  72. {
  73. using (var scope = new TransactionScope())
  74. {
  75. _Repo.Insert(property);
  76. scope.Complete();
  77. return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
  78. }
  79. }
  80. [HttpPut]
  81. public IActionResult Put([FromBody] PropertyContainer property)
  82. {
  83. if (property != null)
  84. {
  85. using (var scope = new TransactionScope())
  86. {
  87. _Repo.Update(property);
  88. scope.Complete();
  89. return new OkResult();
  90. }
  91. }
  92. return new NoContentResult();
  93. }
  94. [HttpDelete("{id}")]
  95. public IActionResult Delete(int id)
  96. {
  97. _Repo.RemoveAtId(id);
  98. return new OkResult();
  99. }
  100. }
  101. }