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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 OwnerName)
  32. {
  33. var items = _Repo.GetAllBid();
  34. return new OkObjectResult(items);
  35. }
  36. [HttpPost]
  37. public IActionResult Post([FromBody] BidItem item)
  38. {
  39. using (var scope = new TransactionScope())
  40. {
  41. _Repo.Insert(item);
  42. scope.Complete();
  43. return CreatedAtAction(nameof(Get), new { id = item.Id }, item);
  44. }
  45. }
  46. [HttpPut]
  47. public IActionResult Put([FromBody] BidItem item)
  48. {
  49. if (item != null)
  50. {
  51. using (var scope = new TransactionScope())
  52. {
  53. _Repo.Update(item);
  54. scope.Complete();
  55. return new OkResult();
  56. }
  57. }
  58. return new NoContentResult();
  59. }
  60. [HttpPut("AcceptBid/{id}")]
  61. public IActionResult AcceptBid(int id)
  62. {
  63. return new OkObjectResult(_Repo.AcceptBid(id));
  64. }
  65. [HttpPut("DeclineBid")]
  66. public IActionResult DeclineBid([FromBody] BitItemDecline item)
  67. {
  68. return new OkObjectResult(_Repo.DecineBid(item));
  69. }
  70. [HttpDelete("{id}")]
  71. public IActionResult Delete(int id)
  72. {
  73. _Repo.RemoveAtId(id);
  74. return new OkResult();
  75. }
  76. }
  77. }