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

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