API
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PropertyController.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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("{id}")]
  26. public IActionResult Get(int id)
  27. {
  28. return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id));
  29. }
  30. [HttpGet("latestProperties")]
  31. public IActionResult GetLatestProperties()
  32. {
  33. return new OkObjectResult(_Repo.GetLatestDisplay());
  34. }
  35. [HttpGet("{type}/{by}")]
  36. public IActionResult SearchBy(string type, int by)
  37. {
  38. return new OkObjectResult(_Repo.GetPropertyList(type, by));
  39. }
  40. #endregion
  41. [HttpGet("search")]
  42. public IActionResult Search([FromBody] PropertySearch search)
  43. {
  44. return new OkObjectResult(_Repo.GetDisplay(search));
  45. }
  46. //Will need to come out. Post search not working......:(
  47. [HttpGet("search/{userName}/{keyword}/{salesType}/{propertyUsageType}/{propertyType}/{province}/{city}/{suburb}/{minPrice}/{maxPrice}")]
  48. public IActionResult Search(string userName, string keyword, string salesType, string propertyUsageType, string propertyType, string province, string city, string suburb, decimal minPrice, decimal maxPrice)
  49. {
  50. var search = new PropertySearch()
  51. {
  52. UserName = userName,
  53. Keyword = keyword,
  54. SalesType = salesType,
  55. PropertyUsageType = propertyUsageType,
  56. PropertyType = propertyType,
  57. Province = province,
  58. City = city,
  59. Suburb = suburb,
  60. MinPrice = minPrice,
  61. MaxPrice = maxPrice
  62. };
  63. return new OkObjectResult(_Repo.GetDisplay(search));
  64. }
  65. [HttpPost]
  66. public IActionResult Post([FromBody] Property property)
  67. {
  68. using (var scope = new TransactionScope())
  69. {
  70. _Repo.Insert(property);
  71. scope.Complete();
  72. return CreatedAtAction(nameof(Get), new { id = property.Id }, property);
  73. }
  74. }
  75. [HttpPut]
  76. public IActionResult Put([FromBody] Property property)
  77. {
  78. if (property != null)
  79. {
  80. using (var scope = new TransactionScope())
  81. {
  82. _Repo.Update(property);
  83. scope.Complete();
  84. return new OkResult();
  85. }
  86. }
  87. return new NoContentResult();
  88. }
  89. [HttpDelete("{id}")]
  90. public IActionResult Delete(int id)
  91. {
  92. _Repo.RemoveAtId(id);
  93. return new OkResult();
  94. }
  95. }
  96. }