using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Transactions; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using UnivateProperties_API.Model.Misc; using UnivateProperties_API.Repository; namespace UnivateProperties_API.Controllers.Misc { [Route("api/[controller]")] [ApiController] public class CarouselController : ControllerBase { private readonly IRepository _Repo; public CarouselController(IRepository repo) { _Repo = repo; } [HttpGet] public IActionResult Get() { return new OkObjectResult(_Repo.GetAll()); } [HttpGet("{id}")] public IActionResult Get(int id) { return new OkObjectResult(_Repo.GetDetailed(x => x.Id == id)); } [HttpPost] public IActionResult Post([FromBody] Carousel carousel) { using (var scope = new TransactionScope()) { _Repo.Insert(carousel); scope.Complete(); return CreatedAtAction(nameof(Get), new { id = carousel.Id }, carousel); } } [HttpPut] public IActionResult Put([FromBody] Carousel carousel) { if (carousel != null) { using (var scope = new TransactionScope()) { _Repo.Update(carousel); scope.Complete(); return new OkResult(); } } return new NoContentResult(); } [HttpDelete("{id}")] public IActionResult Delete(int id) { _Repo.RemoveAtId(id); return new OkResult(); } } }