| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | 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<Carousel> _Repo;
        public CarouselController(IRepository<Carousel> 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();
        }
    }
}
 |