Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MenuOptionsController.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Microsoft.AspNetCore.Mvc;
  2. using ProRestaurant.Models.Restaurants;
  3. using ProRestaurant.Repository.Restaurants;
  4. using System.Transactions;
  5. namespace ProRestaurant.Controllers.Restaurants
  6. {
  7. [Route("api/[controller]")]
  8. [ApiController]
  9. public class MenuOptionsController : ControllerBase
  10. {
  11. public readonly IMenuOptionRepository repo;
  12. public MenuOptionsController(IMenuOptionRepository _repo)
  13. {
  14. repo = _repo;
  15. }
  16. [HttpGet("{id}")]
  17. public IActionResult Get(int id)
  18. {
  19. return new OkObjectResult(repo.GetMenuOption(id));
  20. }
  21. [HttpGet("GetRestaurantMenuOptions/{id}")]
  22. public IActionResult GetRestaurantMenuOptions(int id)
  23. {
  24. return new OkObjectResult(repo.GetRestaurantMenuOptions(id));
  25. }
  26. [HttpGet("GetOptionTypes")]
  27. public IActionResult GetOptionTypes()
  28. {
  29. return new OkObjectResult(repo.GetOptionTypes());
  30. }
  31. [HttpPost]
  32. public IActionResult Post([FromBody] MenuOption value)
  33. {
  34. using (var scope = new TransactionScope())
  35. {
  36. repo.Insert(value);
  37. scope.Complete();
  38. return CreatedAtAction(nameof(Get), new { id = value.Id }, value);
  39. }
  40. }
  41. [HttpPut]
  42. public IActionResult Put([FromBody] MenuOption value)
  43. {
  44. if (value != null)
  45. {
  46. using (var scope = new TransactionScope())
  47. {
  48. repo.Update(value);
  49. scope.Complete();
  50. return new OkResult();
  51. }
  52. }
  53. return new NoContentResult();
  54. }
  55. [HttpDelete("{id}")]
  56. public IActionResult Delete(int id)
  57. {
  58. repo.Delete(repo.GetMenuOption(id));
  59. return new OkResult();
  60. }
  61. [HttpDelete("DeleteMenuOptionItem/{id}")]
  62. public IActionResult DeleteMenuOptionItem(int id)
  63. {
  64. repo.DeleteItem(id);
  65. return new OkResult();
  66. }
  67. }
  68. }