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.

RestaurantUserController.cs 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 RestaurantUserController : ControllerBase
  10. {
  11. public readonly IRestaurantUserRepository repo;
  12. public RestaurantUserController(IRestaurantUserRepository _repo)
  13. {
  14. repo = _repo;
  15. }
  16. [HttpGet("GetRestaurantUsers/{id}")]
  17. public IActionResult GetRestaurantUsers(int id)
  18. {
  19. return new OkObjectResult(repo.GetUsers(id));
  20. }
  21. [HttpGet("{id}")]
  22. public IActionResult Get(int id)
  23. {
  24. return new OkObjectResult(repo.GetRestaurantUser(id));
  25. }
  26. [HttpPost]
  27. public IActionResult Post([FromBody] RestaurantUser value)
  28. {
  29. using (var scope = new TransactionScope())
  30. {
  31. repo.InsertUser(value);
  32. scope.Complete();
  33. return CreatedAtAction(nameof(Get), new { id = value.Id }, value);
  34. }
  35. }
  36. [HttpPut]
  37. public IActionResult Put([FromBody] RestaurantUser value)
  38. {
  39. if (value != null)
  40. {
  41. using (var scope = new TransactionScope())
  42. {
  43. repo.UpdateUser(value);
  44. scope.Complete();
  45. return new OkResult();
  46. }
  47. }
  48. return new NoContentResult();
  49. }
  50. [HttpDelete("{id}")]
  51. public IActionResult Delete(int id)
  52. {
  53. repo.RemoveUser(id);
  54. return new OkResult();
  55. }
  56. }
  57. }