12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using Microsoft.AspNetCore.Mvc;
- using ProRestaurant.Models.Restaurants;
- using ProRestaurant.Repository.Restaurants;
- using System.Transactions;
-
- namespace ProRestaurant.Controllers.Restaurants
- {
- [Route("api/[controller]")]
- [ApiController]
- public class RestaurantRolesController : ControllerBase
- {
- private readonly IRestaurantRoleRepository repo;
-
- public RestaurantRolesController(IRestaurantRoleRepository _repo)
- {
- repo = _repo;
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- return new OkObjectResult(repo.GetRole(id));
- }
-
- [HttpGet("GetRoles/{id}")]
- public IActionResult GetRoles(int id)
- {
- return new OkObjectResult(repo.GetRoles(id));
- }
-
- [HttpGet("GetPremission/{id}")]
- public IActionResult GetPremission(int id)
- {
- return new OkObjectResult(repo.GetPremission(id));
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] RestaurantRole role)
- {
- using (var scope = new TransactionScope())
- {
- repo.Insert(role);
- scope.Complete();
- return CreatedAtAction(nameof(Get), new { id = role.Id }, role);
- }
- }
-
- [HttpPut]
- public IActionResult Put([FromBody] RestaurantRole role)
- {
- if (role != null)
- {
- using (var scope = new TransactionScope())
- {
- repo.Update(role);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- repo.Delete(repo.GetRole(id));
- return new OkResult();
- }
- }
- }
|