1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using Microsoft.AspNetCore.Mvc;
- using System.Transactions;
- using UnivateProperties_API.Model.Users;
- using UnivateProperties_API.Repository;
-
- namespace UnivateProperties_API.Controllers.Users
- {
- [Route("api/[controller]")]
- [ApiController]
- public class UserRoleController : ControllerBase
- {
- private readonly IRepository<UserRole> _Repo;
-
- public UserRoleController(IRepository<UserRole> rp)
- {
- _Repo = rp;
- }
-
- [HttpGet]
- public IActionResult Get()
- {
- var roles = _Repo.GetAll();
- return new OkObjectResult(roles);
- }
-
- [HttpGet("{id}")]
- public IActionResult Get(int id)
- {
- return new OkObjectResult(_Repo.Get(x => x.Id == id));
- }
-
- [HttpPost]
- public IActionResult Post([FromBody] UserRole userRole)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Insert(userRole);
- scope.Complete();
- return CreatedAtAction(nameof(Get), new { id = userRole.Id }, userRole);
- }
- }
-
- [HttpPut]
- public IActionResult Put([FromBody] UserRole userRole)
- {
- if (userRole != null)
- {
- using (var scope = new TransactionScope())
- {
- _Repo.Update(userRole);
- scope.Complete();
- return new OkResult();
- }
- }
- return new NoContentResult();
- }
-
- [HttpDelete("{id}")]
- public IActionResult Delete(int id)
- {
- _Repo.RemoveAtId(id);
- return new OkResult();
- }
- }
- }
|