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.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. [HttpGet("GetSelectCategories")]
  22. public IActionResult GetSelectCategories()
  23. {
  24. return new OkObjectResult(repo.GetCategories());
  25. }
  26. [HttpPost]
  27. public IActionResult Post([FromBody] RestaurantCategory category)
  28. {
  29. using (var scope = new TransactionScope())
  30. {
  31. repo.Insert(category);
  32. scope.Complete();
  33. return new OkObjectResult(category);
  34. }
  35. }
  36. [HttpPut]
  37. public IActionResult Put([FromBody] RestaurantCategory category)
  38. {
  39. if (category != null)
  40. {
  41. using (var scope = new TransactionScope())
  42. {
  43. repo.Update(category);
  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.Remove(id);
  54. return new OkResult();
  55. }
  56. }
  57. }