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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.GetDetailed(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. [HttpGet("GetNewBidTemplate")]
  43. public IActionResult GetNewBidTemplate()
  44. {
  45. return new OkObjectResult(_Repo.NewBidTemplate());
  46. }
  47. [HttpPost]
  48. public IActionResult Post([FromBody] BidItemNew item)
  49. {
  50. using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
  51. {
  52. _Repo.InsertNew(item);
  53. scope.Complete();
  54. return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  55. }
  56. }
  57. [HttpPut]
  58. public IActionResult Put([FromBody] BidItem item)
  59. {
  60. if (item != null)
  61. {
  62. using (var scope = new TransactionScope())
  63. {
  64. _Repo.Update(item);
  65. scope.Complete();
  66. return new OkResult();
  67. }
  68. }
  69. return new NoContentResult();
  70. }
  71. [HttpPut("AcceptBid/{id}")]
  72. public IActionResult AcceptBid(int id)
  73. {
  74. return new OkObjectResult(_Repo.AcceptBid(id));
  75. }
  76. [HttpPut("DeclineBid")]
  77. public IActionResult DeclineBid([FromBody] BitItemDecline item)
  78. {
  79. return new OkObjectResult(_Repo.DecineBid(item));
  80. }
  81. [HttpDelete("{id}")]
  82. public IActionResult Delete(int id)
  83. {
  84. _Repo.RemoveAtId(id);
  85. return new OkResult();
  86. }
  87. }
  88. }