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.

BidController.cs 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using Microsoft.AspNetCore.Mvc;
  2. using System.Transactions;
  3. using UnivateProperties_API.Containers.ProcessFlow;
  4. using UnivateProperties_API.Model.ProcessFlow;
  5. using UnivateProperties_API.Repository;
  6. using UnivateProperties_API.Repository.ProccessFlow;
  7. namespace UnivateProperties_API.Controllers.ProcessFlow
  8. {
  9. [Route("api/[controller]")]
  10. [ApiController]
  11. public class BidController : ControllerBase
  12. {
  13. private readonly IBidRepository _Repo;
  14. public BidController(IBidRepository repo)
  15. {
  16. _Repo = repo;
  17. }
  18. [HttpGet]
  19. public IActionResult Get()
  20. {
  21. var items = _Repo.GetAll();
  22. return new OkObjectResult(items);
  23. }
  24. [HttpGet("{id}")]
  25. public IActionResult Get(int id)
  26. {
  27. var item = _Repo.Get(x => x.Id == id);
  28. return new OkObjectResult(item);
  29. }
  30. [HttpGet("GetBids/{name}")]
  31. public IActionResult GetOwnerBids(string name)
  32. {
  33. var items = _Repo.GetAllBidBy(name);
  34. return new OkObjectResult(items);
  35. }
  36. [HttpGet("GetBidDetails/{id}")]
  37. public IActionResult GetBidDetail(int id)
  38. {
  39. var item = _Repo.GetDispaly(id);
  40. return new OkObjectResult(item);
  41. }
  42. [HttpPost]
  43. public IActionResult Post([FromBody] BidItemNew item)
  44. {
  45. using (var scope = new TransactionScope())
  46. {
  47. _Repo.InsertNew(item);
  48. scope.Complete();
  49. //return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  50. var bid = _Repo.Get(x => x.Id == item.Id);
  51. return new OkObjectResult(bid);
  52. }
  53. }
  54. [HttpPut]
  55. public IActionResult Put([FromBody] BidItem item)
  56. {
  57. if (item != null)
  58. {
  59. using (var scope = new TransactionScope())
  60. {
  61. _Repo.Update(item);
  62. scope.Complete();
  63. return new OkResult();
  64. }
  65. }
  66. return new NoContentResult();
  67. }
  68. [HttpPut("AcceptBid/{id}")]
  69. public IActionResult AcceptBid(int id)
  70. {
  71. return new OkObjectResult(_Repo.AcceptBid(id));
  72. }
  73. [HttpPut("DeclineBid")]
  74. public IActionResult DeclineBid([FromBody] BitItemDecline item)
  75. {
  76. return new OkObjectResult(_Repo.DecineBid(item));
  77. }
  78. [HttpDelete("{id}")]
  79. public IActionResult Delete(int id)
  80. {
  81. _Repo.RemoveAtId(id);
  82. return new OkResult();
  83. }
  84. }
  85. }