Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RestaurantRolesController.cs 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 RestaurantRolesController : ControllerBase
  10. {
  11. private readonly IRestaurantRoleRepository repo;
  12. public RestaurantRolesController(IRestaurantRoleRepository _repo)
  13. {
  14. repo = _repo;
  15. }
  16. [HttpGet("{id}")]
  17. public IActionResult Get(int id)
  18. {
  19. return new OkObjectResult(repo.GetRole(id));
  20. }
  21. [HttpGet("GetRoles/{id}")]
  22. public IActionResult GetRoles(int id)
  23. {
  24. return new OkObjectResult(repo.GetRoles(id));
  25. }
  26. [HttpGet("GetPremission/{id}")]
  27. public IActionResult GetPremission(int id)
  28. {
  29. return new OkObjectResult(repo.GetPremission(id));
  30. }
  31. [HttpPost]
  32. public IActionResult Post([FromBody] RestaurantRole role)
  33. {
  34. using (var scope = new TransactionScope())
  35. {
  36. repo.Insert(role);
  37. scope.Complete();
  38. return CreatedAtAction(nameof(Get), new { id = role.Id }, role);
  39. }
  40. }
  41. [HttpPut]
  42. public IActionResult Put([FromBody] RestaurantRole role)
  43. {
  44. if (role != null)
  45. {
  46. using (var scope = new TransactionScope())
  47. {
  48. repo.Update(role);
  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.GetRole(id));
  59. return new OkResult();
  60. }
  61. }
  62. }