using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using MisIngredientesVue.Core.Models; using MisIngredientesVue.Core.Services; using MisIngredientesVue.Core.Extensions; namespace MisIngredientesVue.Controllers { [Route("api/[controller]")] [ApiController] public class UserRolesController : Controller { private readonly IUserRolesService _userRolesService; public UserRolesController(IUserRolesService userRolesService) { _userRolesService = userRolesService; } [HttpGet] public async Task Get() { var roles = await _userRolesService.GetRoles(User.Identity.GetTenantId()); return Ok(roles); } [HttpPost] public async Task Create([FromBody] UserRole request) { var newRole = await _userRolesService.CreateRole(User.Identity.GetTenantId(), User.Identity.GetUserId(), request); return Ok(newRole); } [Route("{id}")] [HttpPut] public async Task Update(int id, [FromBody] UserRole request) { if (id != request.Id) return BadRequest(); await _userRolesService.UpdateRole(User.Identity.GetTenantId(), User.Identity.GetUserId(), request); return Ok(); } } }