using Microsoft.AspNetCore.Mvc; using System.Transactions; using UnivateProperties_API.Containers.ProcessFlow; using UnivateProperties_API.Model.ProcessFlow; using UnivateProperties_API.Repository; using UnivateProperties_API.Repository.ProccessFlow; namespace UnivateProperties_API.Controllers.ProcessFlow { [Route("api/[controller]")] [ApiController] public class BidController : ControllerBase { private readonly IBidRepository _Repo; public BidController(IBidRepository repo) { _Repo = repo; } [HttpGet] public IActionResult Get() { var items = _Repo.GetAll(); return new OkObjectResult(items); } [HttpGet("{id}")] public IActionResult Get(int id) { var item = _Repo.GetDetailed(x => x.Id == id); return new OkObjectResult(item); } [HttpGet("GetBids/{name}")] public IActionResult GetOwnerBids(string name) { var items = _Repo.GetAllBidBy(name); return new OkObjectResult(items); } [HttpGet("GetBidDetails/{id}")] public IActionResult GetBidDetail(int id) { var item = _Repo.GetDispaly(id); return new OkObjectResult(item); } [HttpGet("GetNewBidTemplate")] public IActionResult GetNewBidTemplate() { return new OkObjectResult(_Repo.NewBidTemplate()); } [HttpPost] public IActionResult Post([FromBody] BidItemNew item) { using (var scope = new TransactionScope(TransactionScopeOption.Suppress)) { _Repo.InsertNew(item); scope.Complete(); return CreatedAtAction(nameof(Get), new { id = item.Id }, item); } } [HttpPut] public IActionResult Put([FromBody] BidItem item) { if (item != null) { using (var scope = new TransactionScope()) { _Repo.Update(item); scope.Complete(); return new OkResult(); } } return new NoContentResult(); } [HttpPut("AcceptBid/{id}")] public IActionResult AcceptBid(int id) { return new OkObjectResult(_Repo.AcceptBid(id)); } [HttpPut("DeclineBid")] public IActionResult DeclineBid([FromBody] BitItemDecline item) { return new OkObjectResult(_Repo.DecineBid(item)); } [HttpDelete("{id}")] public IActionResult Delete(int id) { _Repo.RemoveAtId(id); return new OkResult(); } } }