using Microsoft.AspNetCore.Mvc; using ProRestaurant.Models.Restaurants; using ProRestaurant.Repository.Restaurants; using System.Transactions; namespace ProRestaurant.Controllers.Restaurants { [Route("api/[controller]")] [ApiController] public class RestaurantCategoryController : Controller { private readonly IRestaurantCategoryRepository repo; public RestaurantCategoryController(IRestaurantCategoryRepository Repo) { repo = Repo; } [HttpGet] public IActionResult Get() { return new OkObjectResult(repo.Get()); } [HttpGet("GetSelectCategories")] public IActionResult GetSelectCategories() { return new OkObjectResult(repo.GetCategories()); } [HttpPost] public IActionResult Post([FromBody] RestaurantCategory category) { using (var scope = new TransactionScope()) { repo.Insert(category); scope.Complete(); return new OkObjectResult(category); } } [HttpPut] public IActionResult Put([FromBody] RestaurantCategory category) { if (category != null) { using (var scope = new TransactionScope()) { repo.Update(category); scope.Complete(); return new OkResult(); } } return new NoContentResult(); } [HttpDelete("{id}")] public IActionResult Delete(int id) { repo.Remove(id); return new OkResult(); } } }