1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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 MenuOptionsController : ControllerBase
- {
- public readonly IMenuOptionRepository repo;
-
- public MenuOptionsController(IMenuOptionRepository _repo)
- {
- repo = _repo;
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- return new OkObjectResult(repo.GetMenuOption(id));
- }
-
- [HttpGet("GetRestaurantMenuOptions/{id}")]
- public IActionResult GetRestaurantMenuOptions(int id)
- {
- return new OkObjectResult(repo.GetRestaurantMenuOptions(id));
- }
-
- [HttpGet("GetOptionTypes")]
- public IActionResult GetOptionTypes()
- {
- return new OkObjectResult(repo.GetOptionTypes());
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] MenuOption value)
- {
- using (var scope = new TransactionScope())
- {
- repo.Insert(value);
- scope.Complete();
- return CreatedAtAction(nameof(Get), new { id = value.Id }, value);
- }
- }
-
- [HttpPut]
- public IActionResult Put([FromBody] MenuOption value)
- {
- if (value != null)
- {
- using (var scope = new TransactionScope())
- {
- repo.Update(value);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- repo.Delete(repo.GetMenuOption(id));
- return new OkResult();
- }
-
- [HttpDelete("DeleteMenuOptionItem/{id}")]
- public IActionResult DeleteMenuOptionItem(int id)
- {
- repo.DeleteItem(id);
- return new OkResult();
- }
- }
- }
|