| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | 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();
        }
    }
}
 |