You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RestaurantCategoryController.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 RestaurantCategoryController : Controller
  10. {
  11. private readonly IRestaurantCategoryRepository repo;
  12. public RestaurantCategoryController(IRestaurantCategoryRepository Repo)
  13. {
  14. repo = Repo;
  15. }
  16. [HttpGet]
  17. public IActionResult Get()
  18. {
  19. return new OkObjectResult(repo.Get());
  20. }
  21. [HttpPost]
  22. public IActionResult Post([FromBody] RestaurantCategory category)
  23. {
  24. using (var scope = new TransactionScope())
  25. {
  26. repo.Insert(category);
  27. scope.Complete();
  28. return new OkObjectResult(category);
  29. }
  30. }
  31. [HttpPut]
  32. public IActionResult Put([FromBody] RestaurantCategory category)
  33. {
  34. if (category != null)
  35. {
  36. using (var scope = new TransactionScope())
  37. {
  38. repo.Update(category);
  39. scope.Complete();
  40. return new OkResult();
  41. }
  42. }
  43. return new NoContentResult();
  44. }
  45. [HttpDelete("{id}")]
  46. public IActionResult Delete(int id)
  47. {
  48. repo.Remove(id);
  49. return new OkResult();
  50. }
  51. }
  52. }